@cornerstonejs/core 0.41.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cornerstonejs/core",
3
- "version": "0.41.0",
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": "91c274e60d136f3470eace8c04bf2216df0a06ed"
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
- (xSpacing === image.rowPixelSpacing ||
1545
+ (isSameXSpacing ||
1542
1546
  (image.rowPixelSpacing === null && xSpacing === 1.0)) &&
1543
- (ySpacing === image.columnPixelSpacing ||
1547
+ (isSameYSpacing ||
1544
1548
  (image.columnPixelSpacing === null && ySpacing === 1.0)) &&
1545
1549
  xVoxels === image.columns &&
1546
1550
  yVoxels === image.rows &&
package/src/init.ts CHANGED
@@ -49,18 +49,10 @@ function _getGLContext(): RenderingContext {
49
49
  function _hasActiveWebGLContext() {
50
50
  const gl = _getGLContext();
51
51
 
52
- // Report the result.
53
- if (gl && (gl as WebGL2RenderingContext).getExtension) {
54
- const ext = (gl as WebGL2RenderingContext).getExtension(
55
- 'EXT_texture_norm16'
56
- );
57
-
58
- if (ext) {
59
- return true;
60
- }
61
- }
62
-
63
- return false;
52
+ // Check if the context is either WebGLRenderingContext or WebGL2RenderingContext
53
+ return (
54
+ gl instanceof WebGLRenderingContext || gl instanceof WebGL2RenderingContext
55
+ );
64
56
  }
65
57
 
66
58
  function hasSharedArrayBuffer() {
@@ -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
- * returns equal if the two arrays are identical within the
3
- * given tolerance.
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 array of values
6
- * @param v2 - The second array of values.
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: number[] | Float32Array,
13
- v2: number[] | Float32Array,
46
+ export default function isEqual<ValueType>(
47
+ v1: ValueType,
48
+ v2: ValueType,
14
49
  tolerance = 1e-5
15
50
  ): boolean {
16
- if (v1.length !== v2.length) {
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
- for (let i = 0; i < v1.length; i++) {
21
- if (Math.abs(v1[i] - v2[i]) > tolerance) {
22
- return false;
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
- return true;
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
  }