Skip to content

Commit c3c5e0c

Browse files
helmut-hoffer-von-ankershoffenHelmut (Oertel) Hoffer von Ankershoffen
andauthored
fix(critical): isCoordinateInsideBoundingBox (#158)
* fix(critical): isCoordinateInsideBoundingBox now supports negative coordinates, and is simpler * style: using js standard style --------- Co-authored-by: Helmut (Oertel) Hoffer von Ankershoffen <[email protected]>
1 parent 2cf1e62 commit c3c5e0c

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

src/bulkAnnotations/utils.js

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ export const getViewportBoundingBox = ({ view, pyramid, affine }) => {
3434
}
3535
}
3636

37-
const swapIfGreater = (array1, array2, index) => {
38-
if (array1[index] > array2[index]) {
39-
const temp = array1[index]
40-
array1[index] = array2[index]
41-
array2[index] = temp
42-
}
43-
}
44-
4537
/**
4638
* Check if coordinate is inside bounding box
4739
*
@@ -55,29 +47,15 @@ export const isCoordinateInsideBoundingBox = (
5547
topLeft,
5648
bottomRight
5749
) => {
58-
const result = !(
59-
Math.abs(topLeft[0]) > Math.abs(coordinate[0]) ||
60-
Math.abs(coordinate[0]) > Math.abs(bottomRight[0]) ||
61-
Math.abs(topLeft[1]) > Math.abs(coordinate[1]) ||
62-
Math.abs(coordinate[1]) > Math.abs(bottomRight[1])
63-
) || !(
64-
Math.abs(bottomRight[0]) > Math.abs(coordinate[0]) ||
65-
Math.abs(coordinate[0]) > Math.abs(topLeft[0]) ||
66-
Math.abs(bottomRight[1]) > Math.abs(coordinate[1]) ||
67-
Math.abs(coordinate[1]) > Math.abs(topLeft[1])
68-
)
69-
if (result === true) {
70-
return result
71-
} else {
72-
swapIfGreater(topLeft, bottomRight, 0)
73-
swapIfGreater(topLeft, bottomRight, 1)
74-
return !(
75-
Math.abs(topLeft[0]) > Math.abs(coordinate[0]) ||
76-
Math.abs(coordinate[0]) > Math.abs(bottomRight[0]) ||
77-
Math.abs(topLeft[1]) > Math.abs(coordinate[1]) ||
78-
Math.abs(coordinate[1]) > Math.abs(bottomRight[1])
79-
)
80-
}
50+
const minX = Math.min(topLeft[0], bottomRight[0])
51+
const maxX = Math.max(topLeft[0], bottomRight[0])
52+
const minY = Math.min(topLeft[1], bottomRight[1])
53+
const maxY = Math.max(topLeft[1], bottomRight[1])
54+
55+
return coordinate[0] >= minX &&
56+
coordinate[0] <= maxX &&
57+
coordinate[1] >= minY &&
58+
coordinate[1] <= maxY
8159
}
8260

8361
/**

0 commit comments

Comments
 (0)