flo-mat 3.0.13 → 3.0.15

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.
Files changed (138) hide show
  1. package/__tests__/cp-node/check-clone-eql-calc.spec.ts +58 -0
  2. package/__tests__/cp-node/compare-cp-nodes-by-value.ts +35 -0
  3. package/__tests__/cp-node/compare-loops-by-value.ts +40 -0
  4. package/__tests__/cp-node/compare-poss-by-value.ts +25 -0
  5. package/__tests__/cp-node/fs/clone.spec.ts +19 -3
  6. package/__tests__/cp-node/fs/find-first.spec.ts +13 -3
  7. package/__tests__/cp-node/fs/get-all-between.spec.ts +20 -3
  8. package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +2 -2
  9. package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +16 -3
  10. package/__tests__/cp-node/fs/get-all-vertices.spec.ts +14 -3
  11. package/__tests__/cp-node/fs/get-children.spec.ts +18 -3
  12. package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +14 -3
  13. package/__tests__/cp-node/fs/get-prong-count.spec.ts +16 -3
  14. package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +11 -3
  15. package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +20 -3
  16. package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +16 -3
  17. package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +20 -3
  18. package/__tests__/cp-node/fs/is-one-prong.spec.ts +16 -3
  19. package/__tests__/cp-node/fs/is-sharp.spec.ts +10 -3
  20. package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +13 -3
  21. package/__tests__/cp-node/fs/is-special.spec.ts +12 -3
  22. package/__tests__/cp-node/fs/is-terminating.spec.ts +15 -3
  23. package/__tests__/cp-node/fs/is-trivial.spec.ts +13 -3
  24. package/__tests__/cp-node/fs/is-two-prong.spec.ts +11 -3
  25. package/__tests__/cp-node/fs/is-vertex-special.spec.ts +13 -3
  26. package/__tests__/cp-node/fs/is-vertex.spec.ts +14 -3
  27. package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +13 -3
  28. package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +10 -3
  29. package/__tests__/cp-node/fs/traverse-cp.spec.ts +9 -3
  30. package/__tests__/cp-node/fs/traverse-edges.spec.ts +13 -3
  31. package/__tests__/cp-node/fs/traverse-vertices.spec.ts +12 -3
  32. package/__tests__/cp-node/random-walk.ts +33 -0
  33. package/__tests__/cp-node/stringification/from-stringifyable.spec.ts +3 -0
  34. package/__tests__/cp-node/stringification/loop-from-stringifyable.spec.ts +4 -0
  35. package/__tests__/cp-node/stringification/loop-to-stringifyable.spec.ts +19 -0
  36. package/__tests__/cp-node/stringification/to-stringifyable.spec.ts +34 -0
  37. package/__tests__/get-mats1.ts +125 -0
  38. package/__tests__/jsog/check-jsog-eql-calc.spec.ts +47 -67
  39. package/__tests__/jsog/decode-jsog.ts +88 -85
  40. package/__tests__/jsog/mat-dummy-1.ts +19 -0
  41. package/__tests__/jsog/mat-dummys.ts +6197 -6195
  42. package/__tests__/jsog/to-jsog-breath-first.ts +110 -107
  43. package/__tests__/jsog/to-jsog-depth-first.ts +58 -55
  44. package/browser/index.js +7002 -6298
  45. package/browser/index.min.js +1 -1
  46. package/jest.config.cjs +1 -0
  47. package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +1 -1
  48. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +3 -3
  49. package/node/closest-boundary-point/get-close-boundary-points-certified.js +1 -1
  50. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  51. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +2 -2
  52. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +7 -7
  53. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  54. package/node/cp-node/cp-node.d.ts +2 -2
  55. package/node/cp-node/fs/clone.d.ts +1 -1
  56. package/node/cp-node/fs/clone.js +17 -13
  57. package/node/cp-node/fs/clone.js.map +1 -1
  58. package/node/cp-node/fs/enhance-cp-node.d.ts +2 -2
  59. package/node/cp-node/fs/find-first.d.ts +9 -2
  60. package/node/cp-node/fs/find-first.js +12 -9
  61. package/node/cp-node/fs/find-first.js.map +1 -1
  62. package/node/cp-node/fs/get-all-on-loop.js +5 -6
  63. package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
  64. package/node/cp-node/fs/get-edge-direction.d.ts +1 -1
  65. package/node/cp-node/fs/get-edge-direction.js.map +1 -1
  66. package/node/cp-node/fs/is-on-same-circle.d.ts +1 -0
  67. package/node/cp-node/fs/is-on-same-circle.js +1 -0
  68. package/node/cp-node/fs/is-on-same-circle.js.map +1 -1
  69. package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +1 -1
  70. package/node/debug/functions/draw-elem/draw-dull-corner.js +1 -1
  71. package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
  72. package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +1 -1
  73. package/node/debug/functions/draw-elem/draw-sharp-corner.js +2 -1
  74. package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
  75. package/node/find-mat/find-mats.js +7 -2
  76. package/node/find-mat/find-mats.js.map +1 -1
  77. package/node/find-mat/get-meta.d.ts +4 -4
  78. package/node/find-mat/get-meta.js +1 -1
  79. package/node/find-mat/get-meta.js.map +1 -1
  80. package/node/geometry/circle.d.ts +4 -3
  81. package/node/geometry/circle.js +0 -7
  82. package/node/geometry/circle.js.map +1 -1
  83. package/node/index.d.ts +2 -2
  84. package/node/index.js +1 -0
  85. package/node/index.js.map +1 -1
  86. package/node/mat/curve-piece.d.ts +3 -3
  87. package/node/mat/get-boundary-piece-beziers.d.ts +2 -2
  88. package/node/mat/mat-meta.d.ts +4 -4
  89. package/node/mat/simplify-mat.d.ts +10 -8
  90. package/node/mat/simplify-mat.js +12 -10
  91. package/node/mat/simplify-mat.js.map +1 -1
  92. package/node/point-on-shape/create-pos.d.ts +2 -2
  93. package/node/point-on-shape/create-pos.js.map +1 -1
  94. package/node/point-on-shape/point-on-shape.d.ts +6 -6
  95. package/node/svg/get-loop-bounds.d.ts +2 -2
  96. package/node/svg/get-loop-bounds.js +1 -1
  97. package/node/svg/get-loop-bounds.js.map +1 -1
  98. package/package.json +10 -10
  99. package/src/closest-boundary-point/foot-and-endpoint-info.ts +1 -1
  100. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -5
  101. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +9 -9
  102. package/src/cp-node/cp-node.ts +8 -3
  103. package/src/cp-node/fs/add-distance-from.ts +37 -37
  104. package/src/cp-node/fs/clone.ts +23 -17
  105. package/src/cp-node/fs/find-first.ts +14 -11
  106. package/src/cp-node/fs/get-all-on-loop.ts +5 -6
  107. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +1 -1
  108. package/src/cp-node/fs/get-edge-direction.ts +3 -5
  109. package/src/cp-node/fs/is-on-same-circle.ts +1 -0
  110. package/src/cp-node/stringification/cp-node-stringifyable.ts +68 -0
  111. package/src/cp-node/stringification/from-stringifyable.ts +57 -0
  112. package/src/cp-node/stringification/loop-from-stringifyable.ts +15 -0
  113. package/src/cp-node/stringification/loop-stringifyable.ts +8 -0
  114. package/src/cp-node/stringification/loop-to-stringifyable.ts +14 -0
  115. package/src/cp-node/stringification/to-stringifyable.ts +71 -0
  116. package/src/curve/curve.ts +31 -33
  117. package/src/debug/functions/draw-elem/draw-dull-corner.ts +2 -2
  118. package/src/debug/functions/draw-elem/draw-sharp-corner.ts +4 -3
  119. package/src/find-mat/find-mats.ts +8 -2
  120. package/src/find-mat/get-meta.ts +7 -6
  121. package/src/geometry/circle.ts +5 -12
  122. package/src/index.ts +3 -4
  123. package/src/mat/curve-piece.ts +3 -3
  124. package/src/mat/get-boundary-piece-beziers.ts +3 -3
  125. package/src/mat/mat-meta.ts +4 -4
  126. package/src/mat/simplify-mat-map-only.ts +110 -110
  127. package/src/mat/simplify-mat.ts +15 -13
  128. package/src/point-on-shape/create-pos.ts +3 -3
  129. package/src/point-on-shape/point-on-shape.ts +6 -6
  130. package/src/svg/get-loop-bounds.ts +4 -5
  131. package/__tests__/cp-node/fs/add-distance-from.spec.ts +0 -7
  132. package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +0 -7
  133. package/__tests__/cp-node/fs/create-cp-node.spec.ts +0 -7
  134. package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +0 -7
  135. package/__tests__/jsog/get-mats1.ts +0 -41
  136. package/node/curve/curve.d.ts +0 -33
  137. package/node/curve/curve.js +0 -2
  138. package/node/curve/curve.js.map +0 -1
@@ -1,7 +1,18 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { isVertex } from '../../../src/cp-node/fs/is-vertex.js';
3
+ import { isTerminating } from '../../../src/cp-node/fs/is-terminating.js';
4
+ import { getAllOnCircle } from '../../../src/cp-node/fs/get-all-on-circle.js';
5
+ import { getAllOnLoop } from '../../../src/cp-node/fs/get-all-on-loop.js';
6
+ import { getMats1 } from '../../get-mats1.js';
3
7
 
4
- test.skip('isVertex [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
8
+
9
+ test('isVertex', function() {
10
+ const { cpNode } = getMats1()[0];
11
+ const allOnLoop = getAllOnLoop(cpNode);
12
+
13
+ // isVertex(f)(n) === getAllOnCircle(n).some(f)
14
+ const isTerminatingVertex = isVertex(isTerminating);
15
+ for (const n of allOnLoop) {
16
+ expect(isTerminatingVertex(n)).toBe(getAllOnCircle(n).some(isTerminating));
17
+ }
7
18
  });
@@ -1,7 +1,17 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { iterateAllOnLoop } from '../../../src/cp-node/fs/iterate-all-on-loop.js';
3
+ import { getAllOnLoop } from '../../../src/cp-node/fs/get-all-on-loop.js';
4
+ import { getMats1 } from '../../get-mats1.js';
3
5
 
4
- test.skip('iterateAllOnLoop [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
6
+
7
+ test('iterateAllOnLoop', function() {
8
+ const { cpNode } = getMats1()[0];
9
+
10
+ const iterated = [...iterateAllOnLoop(cpNode)];
11
+ const expected = getAllOnLoop(cpNode);
12
+
13
+ expect(iterated.length).toBe(expected.length);
14
+ for (let i = 0; i < iterated.length; i++) {
15
+ expect(iterated[i] === expected[i]).toBe(true);
16
+ }
7
17
  });
@@ -1,7 +1,14 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { traverseAllForward } from '../../../src/cp-node/fs/traverse-all-forward.js';
3
+ import { getMats1 } from '../../get-mats1.js';
3
4
 
4
- test.skip('traverseAllForward [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
5
+
6
+ test('traverseAllForward', function() {
7
+ const { cpNode } = getMats1()[0];
8
+
9
+ const visited: (typeof cpNode)[] = [];
10
+ traverseAllForward(cpNode, cp => visited.push(cp));
11
+
12
+ expect(visited.length).toBeGreaterThan(0);
13
+ expect(visited[0] === cpNode).toBe(true);
7
14
  });
@@ -1,7 +1,13 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { traverseCp } from '../../../src/cp-node/fs/traverse-cp.js';
3
+ import { getMats1 } from '../../get-mats1.js';
3
4
 
4
- test.skip('traverseCp [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
5
+
6
+ test('traverseCp', function() {
7
+ const { cpNode } = getMats1()[0];
8
+
9
+ const visited = traverseCp(cpNode);
10
+
11
+ expect(visited.length).toBeGreaterThan(0);
12
+ expect(visited[0] === cpNode).toBe(true);
7
13
  });
@@ -1,7 +1,17 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { traverseEdges } from '../../../src/cp-node/fs/traverse-edges.js';
3
+ import { getMats1 } from '../../get-mats1.js';
3
4
 
4
- test.skip('traverseEdges [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
5
+
6
+ test('traverseEdges', function() {
7
+ const { cpNode } = getMats1()[0];
8
+
9
+ const visited: (typeof cpNode)[] = [];
10
+ traverseEdges(cpNode, cp => visited.push(cp));
11
+
12
+ expect(visited.length).toBeGreaterThan(0);
13
+
14
+ // traverseEdges uses a `seen` set internally, so no duplicates
15
+ const visitedSet = new Set(visited);
16
+ expect(visitedSet.size).toBe(visited.length);
7
17
  });
@@ -1,7 +1,16 @@
1
1
  import { expect, test } from '@jest/globals';
2
2
  import { traverseVertices } from '../../../src/cp-node/fs/traverse-vertices.js';
3
+ import { getMats1 } from '../../get-mats1.js';
3
4
 
4
- test.skip('traverseVertices [STUB]', () => {
5
- // TODO: implement test
6
- expect(true).toBe(true);
5
+
6
+ test('traverseVertices', function() {
7
+ const { cpNode } = getMats1()[0];
8
+
9
+ const visited: (typeof cpNode)[] = [];
10
+ traverseVertices(cpNode, cp => visited.push(cp));
11
+
12
+ expect(visited.length).toBeGreaterThan(0);
13
+
14
+ // cpStart is visited first
15
+ expect(visited[0] === cpNode).toBe(true);
7
16
  });
@@ -0,0 +1,33 @@
1
+ import type { CpNode } from "../../src/cp-node/cp-node.js";
2
+ import { squares4 } from 'squares-rng';
3
+
4
+
5
+ const NEXT = 0;
6
+ const PREV = 1;
7
+ const NEXT_ON_CIRCLE = 2;
8
+ const PREV_ON_CIRCLE = 3;
9
+
10
+ function randomWalk(
11
+ cpNode: CpNode,
12
+ seed: number,
13
+ steps: number): CpNode {
14
+
15
+ for (let i=0; i<steps; i++) {
16
+ const direction = squares4(seed + i) % 4;
17
+
18
+ if (direction === NEXT) {
19
+ cpNode = cpNode.next;
20
+ } else if (direction === PREV) {
21
+ cpNode = cpNode.prev;
22
+ } else if (direction === NEXT_ON_CIRCLE) {
23
+ cpNode = cpNode.nextOnCircle;
24
+ } else if (direction === PREV_ON_CIRCLE) {
25
+ cpNode = cpNode.prevOnCircle;
26
+ }
27
+ }
28
+
29
+ return cpNode;
30
+ }
31
+
32
+
33
+ export { randomWalk }
@@ -0,0 +1,3 @@
1
+ import { test } from '@jest/globals';
2
+
3
+ test.todo('see to-stringifyable.spec.ts');
@@ -0,0 +1,4 @@
1
+ import { test } from '@jest/globals';
2
+
3
+ test.todo('see loop-to-stringifyable.spec.ts');
4
+
@@ -0,0 +1,19 @@
1
+ import { expect, test } from '@jest/globals';
2
+ import { loopFromBeziers } from 'flo-boolean';
3
+ import { loopToStringifyable } from '../../../src/cp-node/stringification/loop-to-stringifyable.js';
4
+ import { loopFromStringifyable } from '../../../src/cp-node/stringification/loop-from-stringifyable.js';
5
+
6
+
7
+ test('`LoopToStringifyable` and `LoopFromStringifyable`', function() {
8
+ const beziers = [
9
+ [[24,8], [34,18], [4,28]]
10
+ ];
11
+ const _loop_ = loopFromBeziers(beziers, 3);
12
+ const loopStringifyable = loopToStringifyable(_loop_);
13
+
14
+ expect(loopStringifyable.beziers).toEqual(beziers);
15
+ expect(loopStringifyable.idx).toEqual(3);
16
+
17
+ const loop_ = loopFromStringifyable(loopStringifyable);
18
+ expect(loop_).toEqual(_loop_);
19
+ });
@@ -0,0 +1,34 @@
1
+ import { expect, test } from '@jest/globals';
2
+ import { toStringifyable } from '../../../src/cp-node/stringification/to-stringifyable.js';
3
+ import { fromStringifyable } from '../../../src/cp-node/stringification/from-stringifyable.js';
4
+ import { getMats1 } from '../../get-mats1.js';
5
+ import { compareCpNodesByValue } from '../compare-cp-nodes-by-value.js';
6
+
7
+
8
+ test('`toStringifyable` and `fromStringifyable`', function() {
9
+ {
10
+ // Basic test
11
+ const { cpNode } = getMats1()[0];
12
+
13
+ const stringifyable = toStringifyable(cpNode);
14
+ const cpNode_ = fromStringifyable(stringifyable);
15
+
16
+ const r = compareCpNodesByValue(cpNode, cpNode_);
17
+
18
+ expect(r).toBe(true);
19
+ }
20
+ {
21
+ // Test that also JSON.stringify and JSON.parse work with the stringifyable format
22
+ const cpNode = getMats1()[0].cpNode;
23
+
24
+ const stringifyable = toStringifyable(cpNode);
25
+ const jsonStr = JSON.stringify(stringifyable); // Should not throw
26
+ const stringifyable_ = JSON.parse(jsonStr) as ReturnType<typeof toStringifyable>;
27
+
28
+ const cpNode_ = fromStringifyable(stringifyable_);
29
+
30
+ const r = compareCpNodesByValue(cpNode, cpNode_);
31
+
32
+ expect(r).toBe(true);
33
+ }
34
+ });
@@ -0,0 +1,125 @@
1
+ import type { Mat } from "../src/mat/mat.js";
2
+ import type { CpNodeStringifyable } from "../src/cp-node/stringification/cp-node-stringifyable.js";
3
+ import { findMats } from "../src/find-mat/find-mats.js";
4
+ import { fromStringifyable } from "../src/cp-node/stringification/from-stringifyable.js";
5
+
6
+
7
+
8
+ // Cache; we use this one in tests since it is fixed and not susceptible to
9
+ // small perturbations in the algorithm.
10
+ let mats1: Mat[] | undefined = undefined;
11
+ function getMats1() {
12
+ const _cpNode: CpNodeStringifyable = {
13
+ cpNodes: [
14
+ {
15
+ id: 0,
16
+ isHoleClosing: false,
17
+ isIntersection: false,
18
+ cp: {
19
+ circle: {
20
+ center: [24,8],
21
+ radius: 0
22
+ },
23
+ pointOnShape: {
24
+ curveIdx: 0,
25
+ loopIdx: 0,
26
+ p: [24, 8],
27
+ t: 1,
28
+ isSource: true
29
+ },
30
+ order: -1,
31
+ order2: 0
32
+ },
33
+ prev: 11,
34
+ next: 1,
35
+ prevOnCircle: 1,
36
+ nextOnCircle: 1
37
+ },
38
+ { id: 1, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [24, 8], radius: 0 }, pointOnShape: { curveIdx: 0, loopIdx: 0, p: [24, 8], t: 1, isSource: true }, order: 1, order2: 0 }, prev: 0, next: 10, prevOnCircle: 0, nextOnCircle: 0 },
39
+ { id: 10, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [46, -5.21425847941623], radius: 13.21425847941623 }, pointOnShape: { curveIdx: 1, loopIdx: 0, p: [46, 8], t: 1, isSource: true }, order: -1, order2: 0 }, prev: 1, next: 144, prevOnCircle: 11, nextOnCircle: 11 },
40
+ { id: 144, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, -12.641417453935567], radius: 41.064803841095305 }, pointOnShape: { curveIdx: 1, loopIdx: 0, p: [46, 8], t: 1, isSource: false }, order: -0.5026547194480646, order2: 0 }, prev: 10, next: 147, prevOnCircle: 143, nextOnCircle: 142 },
41
+ { id: 147, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, 18.5], radius: 35.5 }, pointOnShape: { curveIdx: 2, loopIdx: 0, p: [46, 18.499999999999996], t: 0.2282608695652173, isSource: false }, order: 0, order2: 0 }, prev: 144, next: 2, prevOnCircle: 146, nextOnCircle: 145 },
42
+ { id: 2, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [46, 54], radius: 0 }, pointOnShape: { curveIdx: 2, loopIdx: 0, p: [46, 54], t: 1, isSource: true }, order: -1, order2: 0 }, prev: 147, next: 3, prevOnCircle: 3, nextOnCircle: 3 },
43
+ { id: 3, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [46, 54], radius: 0 }, pointOnShape: { curveIdx: 2, loopIdx: 0, p: [46, 54], t: 1, isSource: true }, order: 1, order2: 0 }, prev: 2, next: 145, prevOnCircle: 2, nextOnCircle: 2 },
44
+ { id: 145, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, 18.5], radius: 35.5 }, pointOnShape: { curveIdx: 3, loopIdx: 0, p: [81.5, 54], t: 0.5, isSource: false }, order: 0, order2: 0 }, prev: 3, next: 4, prevOnCircle: 147, nextOnCircle: 146 },
45
+ { id: 4, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [117, 54], radius: 0 }, pointOnShape: { curveIdx: 3, loopIdx: 0, p: [117, 54], t: 1, isSource: true }, order: -1, order2: 0 }, prev: 145, next: 5, prevOnCircle: 5, nextOnCircle: 5 },
46
+ { id: 5, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [117, 54], radius: 0 }, pointOnShape: { curveIdx: 3, loopIdx: 0, p: [117, 54], t: 1, isSource: true }, order: 1, order2: 0 }, prev: 4, next: 146, prevOnCircle: 4, nextOnCircle: 4 },
47
+ { id: 146, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, 18.5], radius: 35.5 }, pointOnShape: { curveIdx: 4, loopIdx: 0, p: [117, 18.499999999999996], t: 0.7717391304347827, isSource: false }, order: 0, order2: 0 }, prev: 5, next: 142, prevOnCircle: 145, nextOnCircle: 147 },
48
+ { id: 142, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, -12.641417453935567], radius: 41.064803841095305 }, pointOnShape: { curveIdx: 4, loopIdx: 0, p: [117, 8], t: 1, isSource: false }, order: -0.8644872659655476, order2: 0 }, prev: 146, next: 148, prevOnCircle: 144, nextOnCircle: 143 },
49
+ { id: 148, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.68410160768288, -12.970446490933696], radius: 41.07276841516263 }, pointOnShape: { curveIdx: 4, loopIdx: 0, p: [117, 8], t: 1, isSource: false }, order: -0.8598373023056252, order2: 0 }, prev: 142, next: 119, prevOnCircle: 150, nextOnCircle: 149 },
50
+ { id: 119, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [115.9110440340909, -5.952334953607174], radius: 13.994766012811272 }, pointOnShape: { curveIdx: 4, loopIdx: 0, p: [117, 8], t: 1, isSource: false }, order: -0.07781165936695383, order2: 0 }, prev: 148, next: 6, prevOnCircle: 118, nextOnCircle: 118 },
51
+ { id: 6, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [139, 8], radius: 0 }, pointOnShape: { curveIdx: 5, loopIdx: 0, p: [139, 8], t: 1, isSource: true }, order: -1, order2: 0 }, prev: 119, next: 7, prevOnCircle: 7, nextOnCircle: 7 },
52
+ { id: 7, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [139, 8], radius: 0 }, pointOnShape: { curveIdx: 5, loopIdx: 0, p: [139, 8], t: 1, isSource: true }, order: 1, order2: 0 }, prev: 6, next: 118, prevOnCircle: 6, nextOnCircle: 6 },
53
+ { id: 118, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [115.9110440340909, -5.952334953607174], radius: 13.994766012811272 }, pointOnShape: { curveIdx: 6, loopIdx: 0, p: [128.3125, -12.4375], t: 0.1875, isSource: true }, order: 0, order2: 0 }, prev: 7, next: 149, prevOnCircle: 119, nextOnCircle: 119 },
54
+ { id: 149, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.68410160768288, -12.970446490933696], radius: 41.07276841516263 }, pointOnShape: { curveIdx: 6, loopIdx: 0, p: [118.08071791640388, -32.003539423017145], t: 0.36700494883501966, isSource: false }, order: 0, order2: 0 }, prev: 118, next: 8, prevOnCircle: 148, nextOnCircle: 150 },
55
+ { id: 8, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [82, -101], radius: 0 }, pointOnShape: { curveIdx: 6, loopIdx: 0, p: [82, -101], t: 1, isSource: true }, order: -1, order2: 0 }, prev: 149, next: 9, prevOnCircle: 9, nextOnCircle: 9 },
56
+ { id: 9, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [82, -101], radius: 0 }, pointOnShape: { curveIdx: 6, loopIdx: 0, p: [82, -101], t: 1, isSource: true }, order: 1, order2: 0 }, prev: 8, next: 150, prevOnCircle: 8, nextOnCircle: 8 },
57
+ { id: 150, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.68410160768288, -12.970446490933696], radius: 41.07276841516263 }, pointOnShape: { curveIdx: 0, loopIdx: 0, p: [45.425023320690585, -32.264267964746104], t: 0.6306030461949899, isSource: false }, order: 0, order2: 0 }, prev: 9, next: 143, prevOnCircle: 149, nextOnCircle: 148 },
58
+ { id: 143, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [81.5, -12.641417453935567], radius: 41.064803841095305 }, pointOnShape: { curveIdx: 0, loopIdx: 0, p: [45.24795284642707, -31.931497590699145], t: 0.6336559854064299, isSource: false }, order: 0, order2: 0 }, prev: 150, next: 11, prevOnCircle: 142, nextOnCircle: 144 },
59
+ { id: 11, isHoleClosing: false, isIntersection: false, cp: { circle: { center: [46, -5.21425847941623], radius: 13.21425847941623 }, pointOnShape: { curveIdx: 0, loopIdx: 0, p: [34.33444028251029, -11.421620530924521], t: 0.8218199951291328, isSource: false }, order: 0, order2: 0 }, prev: 143, next: 0, prevOnCircle: 10, nextOnCircle: 10 }
60
+ ],
61
+ loops: [
62
+ { idx: 0, beziers: [[[82, -101], [24, 8]], [[24, 8], [46, 8]], [[46, 8], [46, 54]], [[46, 54], [117, 54]], [[117, 54], [117, 8]], [[117, 8], [139, 8]], [[139, 8], [82, -101]]] }
63
+ ]
64
+ };
65
+
66
+ const cpNode = fromStringifyable(_cpNode);
67
+
68
+ mats1 = [{ cpNode, meta: {
69
+ boundingHulls: undefined!,
70
+ cpTrees: undefined!,
71
+ loops: undefined!,
72
+ dullCorners: undefined!,
73
+ lastInsertId: undefined!,
74
+ looseBoundingBoxes: undefined!,
75
+ maxCoordinate: undefined!,
76
+ pointToCpNode: undefined!,
77
+ sharpCorners: undefined!,
78
+ squaredDiagonalLength: undefined!,
79
+ tightBoundingBoxes: undefined!
80
+ } }];
81
+
82
+ return mats1;
83
+ }
84
+
85
+
86
+ /** mat-demo: "achispado" font, "comma" glyph */
87
+ const loops1 = [
88
+ [
89
+ [[139, 8], [82, -101]],
90
+ [[82, -101], [24, 8]],
91
+ [[24, 8], [46, 8]],
92
+ [[46, 8], [46, 54]],
93
+ [[46, 54], [117, 54]],
94
+ [[117, 54], [117, 8]],
95
+ [[117, 8], [139, 8]],
96
+ [[139, 8], [139, 8]]
97
+ ]
98
+ ];
99
+
100
+
101
+ // Cache
102
+ let _mats1: Mat[] | undefined = undefined;
103
+ function _getMats1() {
104
+ if (_mats1) { return _mats1; }
105
+
106
+ _mats1 = findMats(loops1, {
107
+ applySat: false,
108
+ simplify: true,
109
+ satScale: 1.675,
110
+ maxCurviness: 0.05,
111
+ maxLength: 40,
112
+ // maxCurviness: 5,
113
+ // maxLength: 4000,
114
+ angleIncrement: 15,
115
+ simplifyTolerance: 2**-1
116
+ });
117
+
118
+ return _mats1;
119
+ }
120
+
121
+
122
+ export {
123
+ getMats1,
124
+ // _getMats1
125
+ }
@@ -1,81 +1,61 @@
1
- import type { Mat } from '../../src/mat/mat.js';
2
- import { expect, test } from '@jest/globals';
3
- import { squares4 } from 'squares-rng';
4
- import { mats1_, getMats1 } from './mat-dummys.js';
5
- import { CpNode, getAllOnLoop } from '../../src/index.js';
1
+ import { test } from '@jest/globals';
6
2
 
3
+ test.todo('Ignore this test for now');
7
4
 
8
- test('Check MAT objects equal (JSOG)', function() {
9
- const mats1 = getMats1();
5
+ // //=======================================
6
+ // // NOTE! JSOG not used in tests anymore!
7
+ // //=======================================
10
8
 
11
- // too hard for Jest due to circular references
12
- // expect(mats_obj1).toEqual(mats_calc1);
9
+ // import { expect, test } from '@jest/globals';
10
+ // import type { CpNode } from '../../src/cp-node/cp-node.js';
11
+ // import { mats1_, getMats1 } from './mat-dummys.js';
12
+ // import { getAllOnLoop } from '../../src/cp-node/fs/get-all-on-loop.js';
13
+ // import { randomWalk } from './random-walk.js';
14
+
15
+
16
+ // test('Check MAT objects equal (JSOG)', function() {
17
+ // const mats1 = getMats1();
18
+
19
+ // // too hard for Jest due to circular references
20
+ // // expect(mats_obj1).toEqual(mats_calc1);
13
21
 
14
- // Fast path: check root array structure and length
15
- expect(Array.isArray(mats1_)).toBe(true);
16
- expect(Array.isArray(mats1)).toBe(true);
17
- expect(mats1_.length).toBe(mats1.length);
22
+ // // Fast path: check root array structure and length
23
+ // expect(Array.isArray(mats1_)).toBe(true);
24
+ // expect(Array.isArray(mats1)).toBe(true);
25
+ // expect(mats1_.length).toBe(mats1.length);
18
26
 
19
- // Verify key properties of the MAT objects instead of deep comparison
20
- const mats1_0_ = mats1_[0];
21
- const mats1_0 = mats1[0];
27
+ // // Verify key properties of the MAT objects instead of deep comparison
28
+ // const mats1_0_ = mats1_[0];
29
+ // const mats1_0 = mats1[0];
22
30
 
23
- // Check critical structure exists
24
- expect(mats1_0_).toHaveProperty('cpNode');
25
- expect(mats1_0).toHaveProperty('cpNode');
31
+ // // Check critical structure exists
32
+ // expect(mats1_0_).toHaveProperty('cpNode');
33
+ // expect(mats1_0).toHaveProperty('cpNode');
26
34
 
27
- // Verify circular reference integrity
28
- if (mats1_0_.cpNode && mats1_0_.cpNode.nextOnCircle) {
29
- expect(mats1_0_.cpNode.nextOnCircle).toBeDefined();
30
- }
31
-
32
- getAllOnLoop(mats1_0_.cpNode).length; //?
33
-
34
- // Perform a random walk on the calculated MAT to ensure it behaves as expected
35
- let testCpNode = mats1_0.cpNode;
36
- let testCpNode_ = mats1_0_.cpNode;
37
-
38
- const N = 10;
39
- let reachCpNodes = new Set<CpNode>();
40
- for (let i=0; i<N; i++) {
41
- testCpNode = randomWalk(testCpNode, i*N, N);
42
- testCpNode_ = randomWalk(testCpNode_, i*N, N);
43
-
44
- // testCpNode.cp.pointOnShape.p; //?
45
- // testCpNode_.cp.pointOnShape.p;//?
46
-
47
- reachCpNodes.add(testCpNode);
48
-
49
- expect(testCpNode.cp.pointOnShape).toEqual(testCpNode_.cp.pointOnShape);
50
- }
35
+ // // Verify circular reference integrity
36
+ // if (mats1_0_.cpNode && mats1_0_.cpNode.nextOnCircle) {
37
+ // expect(mats1_0_.cpNode.nextOnCircle).toBeDefined();
38
+ // }
51
39
 
52
- reachCpNodes.size; //?
53
- });
40
+ // getAllOnLoop(mats1_0_.cpNode).length; //?
54
41
 
42
+ // // Perform a random walk on the calculated MAT to ensure it behaves as expected
43
+ // let testCpNode = mats1_0.cpNode;
44
+ // let testCpNode_ = mats1_0_.cpNode;
55
45
 
56
- const NEXT = 0;
57
- const PREV = 1;
58
- const NEXT_ON_CIRCLE = 2;
59
- const PREV_ON_CIRCLE = 3;
46
+ // const N = 10;
47
+ // let reachCpNodes = new Set<CpNode>();
48
+ // for (let i=0; i<N; i++) {
49
+ // testCpNode = randomWalk(testCpNode, i*N, N);
50
+ // testCpNode_ = randomWalk(testCpNode_, i*N, N);
60
51
 
61
- function randomWalk(
62
- cpNode: CpNode,
63
- seed: number,
64
- steps: number) {
52
+ // // testCpNode.cp.pointOnShape.p; //?
53
+ // // testCpNode_.cp.pointOnShape.p;//?
65
54
 
66
- for (let i=0; i<steps; i++) {
67
- const direction = squares4(seed + i) % 4;
55
+ // reachCpNodes.add(testCpNode);
68
56
 
69
- if (direction === NEXT) {
70
- cpNode = cpNode.next;
71
- } else if (direction === PREV) {
72
- cpNode = cpNode.prev;
73
- } else if (direction === NEXT_ON_CIRCLE) {
74
- cpNode = cpNode.nextOnCircle;
75
- } else if (direction === PREV_ON_CIRCLE) {
76
- cpNode = cpNode.prevOnCircle;
77
- }
78
- }
57
+ // expect(testCpNode.cp.pointOnShape).toEqual(testCpNode_.cp.pointOnShape);
58
+ // }
79
59
 
80
- return cpNode;
81
- }
60
+ // reachCpNodes.size; //?
61
+ // });