Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/geometry/boundingBox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Point } from "./point";
import { Polygon } from "./polygon";

/** A simple bounding box defined by 4 coordinates: xMin, yMin, xMax, yMax */
export class BBox {
Expand All @@ -16,4 +17,8 @@ export class BBox {
}

/** A bounding box defined by 4 points. */
export type BoundingBox = [Point, Point, Point, Point];
export class BoundingBox extends Polygon {
constructor(topLeft: Point, topRight: Point, bottomRight: Point, bottomLeft: Point) {
super(topLeft, topRight, bottomRight, bottomLeft);
}
}
4 changes: 2 additions & 2 deletions src/geometry/boundingBoxUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export function getBoundingBox(polygon: Polygon): BoundingBox {
* Given a BBox, generate the associated bounding box.
*/
export function getBoundingBoxFromBBox(bbox: BBox): BoundingBox {
return [
return new BoundingBox(
[bbox.xMin, bbox.yMin],
[bbox.xMax, bbox.yMin],
[bbox.xMax, bbox.yMax],
[bbox.xMin, bbox.yMax],
];
);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/geometry/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Point } from "./point";

/** A polygon, composed of several Points. */
export class Polygon extends Array<Point> {}
export class Polygon extends Array<Point> {

constructor(...args: Point[]) {
super(...args);
}
}
6 changes: 3 additions & 3 deletions src/parsing/custom/listField.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseFieldConstructor } from "../standard";
import { Polygon, getBoundingBox } from "../../geometry";
import { Polygon, getBoundingBox, BoundingBox } from "../../geometry";
import { StringDict } from "../common";

export class ListFieldValue {
Expand All @@ -14,12 +14,12 @@ export class ListFieldValue {
* Contains exactly 4 relative vertices coordinates (points) of a right
* rectangle containing the word in the document.
*/
bbox: Polygon = [];
bbox?: BoundingBox;
/**
* Contains the relative vertices coordinates (points) of a polygon containing
* the word in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();
/** The document page on which the information was found. */
pageId?: number;

Expand Down
2 changes: 1 addition & 1 deletion src/parsing/standard/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Field extends BaseField {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();
/** The confidence score of the prediction. */
confidence: number;

Expand Down
2 changes: 1 addition & 1 deletion src/product/billOfLading/billOfLadingV1Carrier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class BillOfLadingV1Carrier {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.name = prediction["name"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/billOfLading/billOfLadingV1CarrierItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BillOfLadingV1CarrierItem {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.description = prediction["description"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/billOfLading/billOfLadingV1Consignee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BillOfLadingV1Consignee {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/billOfLading/billOfLadingV1NotifyParty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BillOfLadingV1NotifyParty {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/billOfLading/billOfLadingV1Shipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BillOfLadingV1Shipper {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class FinancialDocumentV1LineItem {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.description = prediction["description"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BankAccountDetailsV2Bban {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.bbanBankCode = prediction["bban_bank_code"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/energyBill/energyBillV1EnergyConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class EnergyBillV1EnergyConsumer {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/energyBill/energyBillV1EnergySupplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class EnergyBillV1EnergySupplier {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/energyBill/energyBillV1EnergyUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class EnergyBillV1EnergyUsage {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/energyBill/energyBillV1MeterDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class EnergyBillV1MeterDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.meterNumber = prediction["meter_number"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/energyBill/energyBillV1Subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class EnergyBillV1Subscription {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.description = prediction["description"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class EnergyBillV1TaxesAndContribution {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.description = prediction["description"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2BankAccountDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PayslipV2BankAccountDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.bankName = prediction["bank_name"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV2Employee {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2Employer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV2Employer {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2Employment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV2Employment {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.category = prediction["category"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2PayDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PayslipV2PayDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2PayPeriod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PayslipV2PayPeriod {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.endDate = prediction["end_date"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2Pto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class PayslipV2Pto {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV2SalaryDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class PayslipV2SalaryDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3BankAccountDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PayslipV3BankAccountDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.bankName = prediction["bank_name"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV3Employee {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3Employer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV3Employer {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.address = prediction["address"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3Employment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class PayslipV3Employment {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.category = prediction["category"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3PaidTimeOff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PayslipV3PaidTimeOff {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3PayDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class PayslipV3PayDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3PayPeriod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PayslipV3PayPeriod {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.endDate = prediction["end_date"];
Expand Down
2 changes: 1 addition & 1 deletion src/product/fr/payslip/payslipV3SalaryDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PayslipV3SalaryDetail {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/product/invoice/invoiceV4LineItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class InvoiceV4LineItem {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.description = prediction["description"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class InvoiceSplitterV1InvoicePageGroup {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
this.pageIndexes = prediction["page_indexes"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class NutritionFactsLabelV1AddedSugar {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class NutritionFactsLabelV1Calorie {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class NutritionFactsLabelV1Cholesterol {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class NutritionFactsLabelV1DietaryFiber {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class NutritionFactsLabelV1Nutrient {
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
polygon: Polygon = [];
polygon: Polygon = new Polygon();

constructor({ prediction = {} }: StringDict) {
if (
Expand Down
Loading
Loading