File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments