Skip to content

Commit

Permalink
Fixed vertical polylines difficult to select (#7860)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored May 7, 2024
1 parent 7f1ae38 commit dc74a20
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240507_153530_boris_fixed_vertical_polylines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Vertical polyline of two points is difficult to select
(<https://github.com/cvat-ai/cvat/pull/7860>)
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion cvat-core/src/annotations-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit dc74a20

Please sign in to comment.