Skip to content

Commit 67b34dc

Browse files
committed
fix(lengthTool): fix coordinate conversion drift
1 parent fe95a96 commit 67b34dc

3 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/core/src/utilities/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import getSpacingInNormalDirection from './getSpacingInNormalDirection';
1717
import getTargetVolumeAndSpacingInNormalDir from './getTargetVolumeAndSpacingInNormalDir';
1818
import getVolumeActorCorners from './getVolumeActorCorners';
1919
import indexWithinDimensions from './indexWithinDimensions';
20+
import indexAlmostWithinDimensions from './indexAlmostWithinDimensions';
2021
import getVolumeViewportsContainingSameVolumes from './getVolumeViewportsContainingSameVolumes';
2122
import getViewportsWithVolumeId from './getViewportsWithVolumeId';
2223
import transformWorldToIndex, {
@@ -140,6 +141,7 @@ export {
140141
getTargetVolumeAndSpacingInNormalDir,
141142
getVolumeActorCorners,
142143
indexWithinDimensions,
144+
indexAlmostWithinDimensions,
143145
getVolumeViewportsContainingSameVolumes,
144146
getViewportsWithVolumeId,
145147
transformWorldToIndex,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { EPSILON } from '../constants';
2+
import type { Point3 } from '../types';
3+
4+
/**
5+
* Returns true if the specified index is within the given dimensions.
6+
*
7+
* @param index - The index to check.
8+
* @param dimensions - The dimensions to check against.
9+
*
10+
* @returns True if the index is in-bounds.
11+
*/
12+
13+
export default function indexAlmostWithinDimensions(
14+
index: Point3,
15+
dimensions: Point3
16+
): boolean {
17+
if (
18+
index[0] < -EPSILON ||
19+
index[0] >= dimensions[0] + EPSILON ||
20+
index[1] < -EPSILON ||
21+
index[1] >= dimensions[1] + EPSILON ||
22+
index[2] < -EPSILON ||
23+
index[2] >= dimensions[2] + EPSILON
24+
) {
25+
return false;
26+
}
27+
28+
return true;
29+
}

packages/tools/src/tools/base/BaseTool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ abstract class BaseTool {
424424
public static isInsideVolume(dimensions, indexPoints) {
425425
const { length: count } = indexPoints;
426426
for (let i = 0; i < count; i++) {
427-
if (!csUtils.indexWithinDimensions(indexPoints[i], dimensions)) {
427+
if (!csUtils.indexAlmostWithinDimensions(indexPoints[i], dimensions)) {
428428
return false;
429429
}
430430
}

0 commit comments

Comments
 (0)