Skip to content

Commit 35ea0bc

Browse files
fix polygon drawing func
1 parent 3282da7 commit 35ea0bc

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

tests/testing-utils/drawing_utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export async function draw_point(page, position) {
5454
}
5555

5656
/**
57-
* Draw a polyline and return its spatial payload.
57+
* Draw a polygon and return its spatial payload.
5858
*
5959
* @param {Page} page
6060
* @param {[number, number][]} points
@@ -75,12 +75,15 @@ export async function draw_polygon(page, points) {
7575
await page.waitForTimeout(200);
7676

7777
// Convert coordinates to image space
78+
// Polygon spatial payload is an array of layers, where each layer has points with first/last duplicated
7879
return await page.evaluate((pts) => {
7980
const image_points = pts.map((pt) =>
8081
window.ulabel.get_image_aware_mouse_x_y(
8182
{ pageX: pt[0], pageY: pt[1] },
8283
),
8384
);
85+
// Duplicate the first point at the end to close the polygon (ulabel format)
86+
image_points.push([...image_points[0]]);
8487
return [image_points];
8588
}, points);
8689
}

0 commit comments

Comments
 (0)