Skip to content

Commit 52c14b7

Browse files
committed
🐛 fix for printing crop results
1 parent 58dfeaf commit 52c14b7

6 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/geometry/polygon.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class Polygon extends Array<Point> {
4747
}
4848

4949
toString(): string {
50-
return this.map((point) => `(${point})`).join(", ");
50+
const points = this.map((point) => `(${point})`).join(", ");
51+
return `(${points})`;
5152
}
5253
}

src/v2/parsing/inference/field/fieldLocation.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,20 @@ import { Polygon } from "@/geometry/index.js";
22
import { StringDict } from "@/parsing/stringDict.js";
33

44
/**
5-
* Location of a field.
5+
* A field's location on the document.
66
*/
77
export class FieldLocation {
8-
/** Free polygon made up of points (can be null when not provided). */
9-
readonly polygon: Polygon | null;
10-
11-
/** Page ID. */
12-
readonly page: number | undefined;
8+
/** Position information as a list of points in clockwise order. */
9+
readonly polygon: Polygon;
10+
/** 0-based page index of where the polygon is located. */
11+
readonly page;
1312

1413
constructor(serverResponse: StringDict) {
15-
this.polygon = "polygon" in serverResponse ? new Polygon(...serverResponse["polygon"]) : null;
16-
this.page = "page" in serverResponse ? serverResponse["page"] : undefined;
14+
this.polygon = new Polygon(...serverResponse["polygon"]);
15+
this.page = serverResponse["page"];
1716
}
1817

1918
toString(): string {
20-
return this.polygon?.toString() ?? "";
19+
return `${this.polygon} on page ${this.page}`;
2120
}
2221
}

src/v2/product/crop/cropItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ export class CropItem {
1111
}
1212

1313
toString(): string {
14-
return `${this.objectType}: ${this.location}`;
14+
return `* :Location: ${this.location}\n :Object Type: ${this.objectType}`;
1515
}
1616
}

src/v2/product/crop/cropResult.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class CropResult {
1212
}
1313

1414
toString(): string {
15-
const crops = this.crops.map(item => item.toString()).join("\n * ");
16-
return `Crop\n====\n * ${crops}`;
15+
const crops = this.crops.map(item => item.toString()).join("\n");
16+
return `Crops\n=====\n${crops}`;
1717
}
1818
}

tests/v2/product/crop.spec.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ describe("MindeeV2 - Crop Response", async () => {
4747
assert.strictEqual(polygon[2][1], 0.947);
4848
assert.strictEqual(polygon[3][0], 0.15);
4949
assert.strictEqual(polygon[3][1], 0.947);
50+
51+
const rstString = await fs.readFile(
52+
path.join(V2_PRODUCT_PATH, "crop", "crop_single.rst"), "utf8"
53+
);
54+
assert.strictEqual(response.inference.toString(), rstString);
5055
});
5156

5257
it("should load multiple results", async () => {
@@ -101,19 +106,10 @@ describe("MindeeV2 - Crop Response", async () => {
101106
assert.strictEqual(secondPolygon[2][1], 0.97);
102107
assert.strictEqual(secondPolygon[3][0], 0.547);
103108
assert.strictEqual(secondPolygon[3][1], 0.97);
104-
});
105109

106-
describe("RST Display", async () => {
107-
it("to be properly exposed", async () => {
108-
const response = await loadV2Response(
109-
crop.CropResponse,
110-
path.join(V2_PRODUCT_PATH, "crop", "crop_single.json")
111-
);
112-
const rstString = await fs.readFile(
113-
path.join(V2_PRODUCT_PATH, "crop", "crop_single.rst"), "utf8"
114-
);
115-
assert.notStrictEqual(response.inference, null);
116-
assert.strictEqual(response.inference.toString(), rstString);
117-
});
110+
const rstString = await fs.readFile(
111+
path.join(V2_PRODUCT_PATH, "crop", "crop_multiple.rst"), "utf8"
112+
);
113+
assert.strictEqual(response.inference.toString(), rstString);
118114
});
119115
});

0 commit comments

Comments
 (0)