Skip to content

Commit

Permalink
fix(critical): isCoordinateInsideBoundingBox now supports negative co…
Browse files Browse the repository at this point in the history
…ordinates, and is simpler
  • Loading branch information
Helmut (Oertel) Hoffer von Ankershoffen authored and helmut-hoffer-von-ankershoffen committed Nov 10, 2024
1 parent 628555a commit 80e5a03
Showing 1 changed file with 9 additions and 23 deletions.
32 changes: 9 additions & 23 deletions src/bulkAnnotations/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,15 @@ export const isCoordinateInsideBoundingBox = (
topLeft,
bottomRight
) => {
const result = !(
Math.abs(topLeft[0]) > Math.abs(coordinate[0]) ||
Math.abs(coordinate[0]) > Math.abs(bottomRight[0]) ||
Math.abs(topLeft[1]) > Math.abs(coordinate[1]) ||
Math.abs(coordinate[1]) > Math.abs(bottomRight[1])
) || !(
Math.abs(bottomRight[0]) > Math.abs(coordinate[0]) ||
Math.abs(coordinate[0]) > Math.abs(topLeft[0]) ||
Math.abs(bottomRight[1]) > Math.abs(coordinate[1]) ||
Math.abs(coordinate[1]) > Math.abs(topLeft[1])
)
if (result === true) {
return result
} else {
swapIfGreater(topLeft, bottomRight, 0)
swapIfGreater(topLeft, bottomRight, 1)
return !(
Math.abs(topLeft[0]) > Math.abs(coordinate[0]) ||
Math.abs(coordinate[0]) > Math.abs(bottomRight[0]) ||
Math.abs(topLeft[1]) > Math.abs(coordinate[1]) ||
Math.abs(coordinate[1]) > Math.abs(bottomRight[1])
)
}
let minX = Math.min(topLeft[0], bottomRight[0]);
let maxX = Math.max(topLeft[0], bottomRight[0]);
let minY = Math.min(topLeft[1], bottomRight[1]);
let maxY = Math.max(topLeft[1], bottomRight[1]);

return coordinate[0] >= minX &&
coordinate[0] <= maxX &&
coordinate[1] >= minY &&
coordinate[1] <= maxY;
}

/**
Expand Down

0 comments on commit 80e5a03

Please sign in to comment.