From dc74a20d9fbaf0a885d2197b047ba9f14a66812c Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Tue, 7 May 2024 16:21:39 +0300 Subject: [PATCH] Fixed vertical polylines difficult to select (#7860) --- .../20240507_153530_boris_fixed_vertical_polylines.md | 4 ++++ cvat-core/package.json | 2 +- cvat-core/src/annotations-objects.ts | 11 ++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 changelog.d/20240507_153530_boris_fixed_vertical_polylines.md diff --git a/changelog.d/20240507_153530_boris_fixed_vertical_polylines.md b/changelog.d/20240507_153530_boris_fixed_vertical_polylines.md new file mode 100644 index 000000000000..5a18f8c93a25 --- /dev/null +++ b/changelog.d/20240507_153530_boris_fixed_vertical_polylines.md @@ -0,0 +1,4 @@ +### Fixed + +- Vertical polyline of two points is difficult to select + () diff --git a/cvat-core/package.json b/cvat-core/package.json index 98adef48e9ca..cb88e3440ce1 100644 --- a/cvat-core/package.json +++ b/cvat-core/package.json @@ -1,6 +1,6 @@ { "name": "cvat-core", - "version": "15.0.4", + "version": "15.0.5", "type": "module", "description": "Part of Computer Vision Tool which presents an interface for client-side integration", "main": "src/api.ts", diff --git a/cvat-core/src/annotations-objects.ts b/cvat-core/src/annotations-objects.ts index ddaba729c6f4..03331d101ede 100644 --- a/cvat-core/src/annotations-objects.ts +++ b/cvat-core/src/annotations-objects.ts @@ -1671,7 +1671,16 @@ export class PolylineShape extends PolyShape { const y2 = points[i + 3]; // Find the shortest distance from point to an edge - if ((x - x1) * (x2 - x) >= 0 && (y - y1) * (y2 - y) >= 0) { + // using perpendicular or by the distance to the nearest point + + // Get coordinate vectors + const AB = [x2 - x1, y2 - y1]; + const BM = [x - x2, y - y2]; + const AM = [x - x1, y - y1]; + + // scalar products have different signs for two pairs of vectors + // it means that perpendicular projection lies on the edge + if (Math.sign(AB[0] * BM[0] + AB[1] * BM[1]) !== Math.sign(AB[0] * AM[0] + AB[1] * AM[1])) { // Find the length of a perpendicular // https://en.wikipedia.org/wiki/Distance_from_a_point_to_a_line distances.push(