@cornerstonejs/core 0.41.1 → 0.41.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/RenderingEngine/StackViewport.js +4 -2
- package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/cjs/utilities/isEqual.d.ts +1 -1
- package/dist/cjs/utilities/isEqual.js +30 -4
- package/dist/cjs/utilities/isEqual.js.map +1 -1
- package/dist/esm/RenderingEngine/StackViewport.js +4 -2
- package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/esm/utilities/isEqual.d.ts +1 -1
- package/dist/esm/utilities/isEqual.js +30 -4
- package/dist/esm/utilities/isEqual.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/src/RenderingEngine/StackViewport.ts +6 -2
- package/src/utilities/isEqual.ts +60 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "0.41.
|
|
3
|
+
"version": "0.41.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/umd/index.js",
|
|
6
6
|
"types": "dist/esm/index.d.ts",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"type": "individual",
|
|
52
52
|
"url": "https://ohif.org/donate"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "e682bc7d33796f1ff962e42f3bed54d276dc6ad4"
|
|
55
55
|
}
|
|
@@ -1536,11 +1536,15 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1536
1536
|
const columnCosines = direction.slice(3, 6);
|
|
1537
1537
|
const dataType = imageData.getPointData().getScalars().getDataType();
|
|
1538
1538
|
|
|
1539
|
+
// using epsilon comparison for float numbers comparison.
|
|
1540
|
+
const isSameXSpacing = isEqual(xSpacing, image.rowPixelSpacing);
|
|
1541
|
+
const isSameYSpacing = isEqual(ySpacing, image.columnPixelSpacing);
|
|
1542
|
+
|
|
1539
1543
|
// using spacing, size, and direction only for now
|
|
1540
1544
|
return (
|
|
1541
|
-
(
|
|
1545
|
+
(isSameXSpacing ||
|
|
1542
1546
|
(image.rowPixelSpacing === null && xSpacing === 1.0)) &&
|
|
1543
|
-
(
|
|
1547
|
+
(isSameYSpacing ||
|
|
1544
1548
|
(image.columnPixelSpacing === null && ySpacing === 1.0)) &&
|
|
1545
1549
|
xVoxels === image.columns &&
|
|
1546
1550
|
yVoxels === image.rows &&
|
package/src/utilities/isEqual.ts
CHANGED
|
@@ -1,27 +1,74 @@
|
|
|
1
|
+
function areNumbersEqualWithTolerance(
|
|
2
|
+
num1: number,
|
|
3
|
+
num2: number,
|
|
4
|
+
tolerance: number
|
|
5
|
+
): boolean {
|
|
6
|
+
return Math.abs(num1 - num2) <= tolerance;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function areArraysEqual(
|
|
10
|
+
arr1: ArrayLike<number>,
|
|
11
|
+
arr2: ArrayLike<number>,
|
|
12
|
+
tolerance = 1e-5
|
|
13
|
+
): boolean {
|
|
14
|
+
if (arr1.length !== arr2.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
19
|
+
if (!areNumbersEqualWithTolerance(arr1[i], arr2[i], tolerance)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isNumberType(value: any): value is number {
|
|
28
|
+
return typeof value === 'number';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isNumberArrayLike(value: any): value is ArrayLike<number> {
|
|
32
|
+
return 'length' in value && typeof value[0] === 'number';
|
|
33
|
+
}
|
|
34
|
+
|
|
1
35
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
36
|
+
* Returns whether two values are equal or not, based on epsilon comparison.
|
|
37
|
+
* For array comparison, it does NOT strictly compare them but only compare its values.
|
|
38
|
+
* It can compare array of numbers and also typed array. Otherwise it will just return false.
|
|
4
39
|
*
|
|
5
|
-
* @param v1 - The first
|
|
6
|
-
* @param v2 - The second
|
|
40
|
+
* @param v1 - The first value to compare
|
|
41
|
+
* @param v2 - The second value to compare
|
|
7
42
|
* @param tolerance - The acceptable tolerance, the default is 0.00001
|
|
8
43
|
*
|
|
9
44
|
* @returns True if the two values are within the tolerance levels.
|
|
10
45
|
*/
|
|
11
|
-
export default function isEqual(
|
|
12
|
-
v1:
|
|
13
|
-
v2:
|
|
46
|
+
export default function isEqual<ValueType>(
|
|
47
|
+
v1: ValueType,
|
|
48
|
+
v2: ValueType,
|
|
14
49
|
tolerance = 1e-5
|
|
15
50
|
): boolean {
|
|
16
|
-
|
|
51
|
+
// values must be the same type or not null
|
|
52
|
+
if (typeof v1 !== typeof v2 || v1 === null || v2 === null) {
|
|
17
53
|
return false;
|
|
18
54
|
}
|
|
19
55
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
56
|
+
// typeof object must have same constructor
|
|
57
|
+
if (
|
|
58
|
+
typeof v1 === 'object' &&
|
|
59
|
+
typeof v2 === 'object' &&
|
|
60
|
+
v1.constructor !== v2.constructor
|
|
61
|
+
) {
|
|
62
|
+
return false;
|
|
24
63
|
}
|
|
25
64
|
|
|
26
|
-
|
|
65
|
+
if (isNumberType(v1) && isNumberType(v2)) {
|
|
66
|
+
return areNumbersEqualWithTolerance(v1, v2, tolerance);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (isNumberArrayLike(v1) && isNumberArrayLike(v2)) {
|
|
70
|
+
return areArraysEqual(v1, v2, tolerance);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return false;
|
|
27
74
|
}
|