Skip to content

Commit

Permalink
fix(Stack): swap image row and column pixel spacing + relaxing isequa…
Browse files Browse the repository at this point in the history
…l compar… (cornerstonejs#566)

Co-authored-by: Rodolfo <[email protected]>
  • Loading branch information
RoyWiggins and Rodolfo committed Apr 28, 2023
1 parent 0ebf130 commit 2f06906
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/RenderingEngine/StackViewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1315,9 +1315,9 @@ class StackViewport extends Viewport implements IStackViewport {
// using spacing, size, and direction only for now
return (
(isSameXSpacing ||
(image.rowPixelSpacing === null && xSpacing === 1.0)) &&
(image.columnPixelSpacing === null && xSpacing === 1.0)) &&
(isSameYSpacing ||
(image.columnPixelSpacing === null && ySpacing === 1.0)) &&
(image.rowPixelSpacing === null && ySpacing === 1.0)) &&
xVoxels === image.columns &&
yVoxels === image.rows &&
isEqual(imagePlaneModule.rowCosines, <Point3>rowCosines) &&
Expand Down
9 changes: 0 additions & 9 deletions packages/core/src/utilities/isEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ export default function isEqual<ValueType>(
return false;
}

// typeof object must have same constructor
if (
typeof v1 === 'object' &&
typeof v2 === 'object' &&
v1.constructor !== v2.constructor
) {
return false;
}

if (isNumberType(v1) && isNumberType(v2)) {
return areNumbersEqualWithTolerance(v1, v2, tolerance);
}
Expand Down
23 changes: 21 additions & 2 deletions packages/core/test/utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,36 @@ describe('Cornerstone-render Utilities:', function () {
expect(isEqual(Infinity, Infinity, 0.0001)).toBe(false);
expect(isEqual(NaN, NaN, 0.0001)).toBe(false);

const typedArray0 = new Float32Array([1.0, 2.1]);
const typedArray1 = new Float32Array([1.0, 1.2]);
const typedArray2 = new Float32Array([1.0, 1.2]);
const typedArray3 = new Float64Array([1.0, 1.2]);
const typedArray4 = new Float64Array([1.01, 1.202]);
const typedArray5 = new Int16Array([1, 2]);
const typedArray6 = new Int16Array([1, 2]);
const typedArray7 = new Int16Array([1, 3]);

expect(isEqual(typedArray1, typedArray2, 0.0001)).toBe(true);
expect(isEqual(typedArray3, typedArray4, 0.1)).toBe(true);
expect(isEqual(typedArray5, typedArray6, 0.0001)).toBe(true);
expect(isEqual(typedArray1, typedArray3, 0.1)).toBe(false);
expect(isEqual(typedArray3, typedArray4, 0.0001)).toBe(false);
expect(isEqual(typedArray3, typedArray4, 0.0001)).toEqual(
isEqual(typedArray4, typedArray3, 0.0001)
);
expect(isEqual(typedArray5, typedArray6, 0.1)).toBe(true);
expect(isEqual(typedArray5, typedArray6, 0.001)).toBe(true);
expect(isEqual(typedArray5, typedArray7, 0.1)).toBe(false);
expect(isEqual(typedArray1, typedArray3, 0.1)).toBe(true);
expect(isEqual(typedArray1, typedArray3, 0.0001)).toBe(true);
expect(isEqual(typedArray1, typedArray5, 0.0001)).toBe(false);
expect(isEqual(typedArray1, typedArray5, 0.01)).toBe(false);
expect(isEqual(typedArray0, typedArray5, 0.01)).toBe(false);
expect(isEqual(typedArray0, typedArray5, 0.1)).toBe(true);
expect(isEqual(typedArray0, typedArray5, 0.1)).toEqual(
isEqual(typedArray5, typedArray0, 0.1)
);
expect(isEqual(typedArray0, typedArray5, 0.1)).toEqual(
isEqual(typedArray5, typedArray5, 0.1)
);
});

it('Should correctly calculate line and plane intersection', () => {
Expand Down

0 comments on commit 2f06906

Please sign in to comment.