flo-mat 4.1.3 → 4.1.4

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 (73) hide show
  1. package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs-same-curve.spec.ts +1 -1
  2. package/__tests__/specific-cases/specific-cases.spec.ts +1 -14
  3. package/__tests__/specific-cases/test-svgs/achispado.svg +37 -24
  4. package/browser/index.js +404 -195
  5. package/browser/index.min.js +1 -1
  6. package/node/cp-node/fs/insert-cp-node.d.ts +12 -1
  7. package/node/cp-node/fs/insert-cp-node.js +21 -6
  8. package/node/cp-node/fs/insert-cp-node.js.map +1 -1
  9. package/node/cp-node/fs/is-order-correct.d.ts +9 -1
  10. package/node/cp-node/fs/is-order-correct.js +51 -10
  11. package/node/cp-node/fs/is-order-correct.js.map +1 -1
  12. package/node/cp-node/fs/remove-cp-node.js +1 -1
  13. package/node/cp-node/fs/remove-cp-node.js.map +1 -1
  14. package/node/debug/functions/check-ordering.d.ts +4 -0
  15. package/node/debug/functions/check-ordering.js +43 -0
  16. package/node/debug/functions/check-ordering.js.map +1 -0
  17. package/node/find-2-prong/add-2-prong.js +4 -2
  18. package/node/find-2-prong/add-2-prong.js.map +1 -1
  19. package/node/find-2-prong/find-and-add-2-prongs.js +1 -1
  20. package/node/find-2-prong/find-and-add-2-prongs.js.map +1 -1
  21. package/node/find-2-prong/get-initial-bezier-pieces.js +2 -2
  22. package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
  23. package/node/find-3-prong/find-3-prong-for-delta3s.d.ts +1 -1
  24. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  25. package/node/find-3-prong/find-3-prong.d.ts +1 -1
  26. package/node/find-3-prong/find-3-prong.js.map +1 -1
  27. package/node/find-3-prong/find-and-add-3-prong.js +1 -1
  28. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
  29. package/node/find-3-prong/find-and-add-3-prongs-on-loop.d.ts +1 -1
  30. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js +6 -2
  31. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js.map +1 -1
  32. package/node/find-3-prong/three-prong-info.d.ts +1 -1
  33. package/node/find-mat/create-initial-cp-tree.js +2 -2
  34. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  35. package/node/find-mat/find-mat.js +2 -2
  36. package/node/find-mat/find-mat.js.map +1 -1
  37. package/node/find-mat/get-for-1-prongs-on-loop.js +3 -1
  38. package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
  39. package/node/mat/add-to-cp-tree.d.ts +4 -1
  40. package/node/mat/add-to-cp-tree.js +11 -4
  41. package/node/mat/add-to-cp-tree.js.map +1 -1
  42. package/node/mat/get-boundary-piece-beziers.d.ts +2 -2
  43. package/node/mat/get-boundary-piece-beziers.js +1 -1
  44. package/node/mat/get-boundary-piece-beziers.js.map +1 -1
  45. package/node/mat/get-closeby-cp-if-exist.js +2 -2
  46. package/node/mat/get-closeby-cp-if-exist.js.map +1 -1
  47. package/node/mat/{get-cp-node-to-left-or-same.d.ts → get-cp-node-neighbors.d.ts} +2 -2
  48. package/node/mat/get-cp-node-neighbors.js +31 -0
  49. package/node/mat/get-cp-node-neighbors.js.map +1 -0
  50. package/package.json +8 -8
  51. package/src/cp-node/fs/insert-cp-node.ts +22 -7
  52. package/src/cp-node/fs/is-order-correct copy.ts +60 -0
  53. package/src/cp-node/fs/is-order-correct.ts +61 -13
  54. package/src/cp-node/fs/remove-cp-node.ts +1 -1
  55. package/src/debug/functions/check-ordering.ts +44 -61
  56. package/src/find-2-prong/add-2-prong.ts +3 -1
  57. package/src/find-2-prong/find-and-add-2-prongs.ts +1 -1
  58. package/src/find-2-prong/get-initial-bezier-pieces.ts +2 -2
  59. package/src/find-3-prong/find-3-prong-for-delta3s.ts +14 -6
  60. package/src/find-3-prong/find-3-prong.ts +1 -1
  61. package/src/find-3-prong/find-and-add-3-prong.ts +1 -4
  62. package/src/find-3-prong/find-and-add-3-prongs-on-loop.ts +6 -3
  63. package/src/find-3-prong/three-prong-info.ts +1 -1
  64. package/src/find-mat/create-initial-cp-tree.ts +2 -2
  65. package/src/find-mat/find-mat.ts +3 -2
  66. package/src/find-mat/get-for-1-prongs-on-loop.ts +3 -1
  67. package/src/mat/add-to-cp-tree copy.ts +71 -0
  68. package/src/mat/add-to-cp-tree.ts +12 -4
  69. package/src/mat/get-boundary-piece-beziers.ts +2 -2
  70. package/src/mat/get-closeby-cp-if-exist.ts +2 -2
  71. package/src/mat/{get-cp-node-to-left-or-same.ts → get-cp-node-neighbors.ts} +12 -10
  72. package/node/mat/get-cp-node-to-left-or-same.js +0 -30
  73. package/node/mat/get-cp-node-to-left-or-same.js.map +0 -1
@@ -1,12 +1,12 @@
1
1
  import type { CpNode } from '../cp-node/cp-node.js';
2
2
  import type { CurvePiece } from './curve-piece.js';
3
3
  /**
4
- * Returns the ordered bezier pieces between from the given boundary piece.
4
+ * Returns the ordered bezier pieces between the two given `CpNode`s.
5
5
  *
6
6
  * @param cpNodes - An ordered pair that represents the start and end points of
7
7
  * the boundary piece
8
8
  *
9
9
  * @internal
10
10
  */
11
- declare function getBoundaryPieceBeziers(cpNodes: CpNode[]): CurvePiece[];
11
+ declare function getBoundaryPieceBeziers(cpNodes: [CpNode, CpNode]): CurvePiece[];
12
12
  export { getBoundaryPieceBeziers };
@@ -1,6 +1,6 @@
1
1
  import { comparePoss } from '../point-on-shape/compare-poss.js';
2
2
  /**
3
- * Returns the ordered bezier pieces between from the given boundary piece.
3
+ * Returns the ordered bezier pieces between the two given `CpNode`s.
4
4
  *
5
5
  * @param cpNodes - An ordered pair that represents the start and end points of
6
6
  * the boundary piece
@@ -1 +1 @@
1
- {"version":3,"file":"get-boundary-piece-beziers.js","sourceRoot":"","sources":["../../src/mat/get-boundary-piece-beziers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAGhE;;;;;;;GAOG;AAC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,oDAAoD;IACpD,gBAAgB;IAChB,YAAY;IACZ,QAAQ;IACR,IAAI;IAEJ,4EAA4E;IAC5E,sEAAsE;IACtE,8EAA8E;IAC9E,2CAA2C;IAC3C,gEAAgE;IAEhE,gFAAgF;IAChF,gCAAgC;IAChC,+BAA+B;IAC/B,0CAA0C;IAE1C,wCAAwC;IACxC,iCAAiC;IACjC,YAAY;IACZ,4CAA4C;IAC5C,QAAQ;IACR,IAAI;IAEJ,OAAO,WAAW,CAAC;AACvB,CAAC;AAGD;;;GAGG;AACH,SAAS,iBAAiB,CAClB,WAAuC,EACvC,UAAiB,EACjB,QAAe,EACf,EAAU;IAEd,gEAAgE;IAChE,IAAI,SAAS,GAAG,UAAU,CAAC;IAC3B,GAAG,CAAC;QACA,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC;QAC3B,MAAM,IAAI,GAAG,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC,QAAQ,SAAS,KAAK,QAAQ,EAAE;AACrC,CAAC;AAGD,OAAO,EAAE,uBAAuB,EAAE,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { distanceBetween, toUnitVector, fromTo, dot } from 'flo-vector2d';
2
- import { getCpNodeToLeftOrSame } from './get-cp-node-to-left-or-same.js';
2
+ import { getCpNodeNeighbors } from './get-cp-node-neighbors.js';
3
3
  /** @internal */
4
4
  const DEGREES = 1;
5
5
  const ANGLE_THRESHOLD = Math.cos(DEGREES * (Math.PI / 180));
@@ -19,7 +19,7 @@ function getCloseByCpIfExist(meta, pos, circle, order, order2, forProngCount) {
19
19
  const DISTANCE_THRESHOLD = 2 ** (maxCoordPowerOf2 - 40); // approx. 1e-9 for 1024 x 1024 shapes
20
20
  const DISTANCE_THRESHOLD_2 = 2 ** (maxCoordPowerOf2 - 46);
21
21
  const cpTree = cpTrees.get(pos.curve.loop);
22
- const cur = getCpNodeToLeftOrSame(cpTree, pos, order, order2);
22
+ const cur = getCpNodeNeighbors(cpTree, pos, order, order2)?.[0];
23
23
  if (!cur) {
24
24
  return undefined;
25
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get-closeby-cp-if-exist.js","sourceRoot":"","sources":["../../src/mat/get-closeby-cp-if-exist.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,gBAAgB;AAChB,MAAM,OAAO,GAAG,CAAC,CAAC;AAClB,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AAG5D;;;;;;;;;;GAUG;AACH,SAAS,mBAAmB,CACpB,IAAa,EACb,GAAoB,EACpB,MAAc,EACd,KAAa,EACb,MAAc,EACd,aAAsB;IAE1B,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAC;IAE3C,MAAM,kBAAkB,GAAG,CAAC,IAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAE,sCAAsC;IAC9F,MAAM,oBAAoB,GAAG,CAAC,IAAE,CAAC,gBAAgB,GAAG,EAAE,CAAC,CAAC;IAExD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAE,CAAC;IAC5C,MAAM,GAAG,GAAG,qBAAqB,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9D,IAAI,CAAC,GAAG,EAAE,CAAC;QAAC,OAAO,SAAS,CAAC;IAAC,CAAC;IAC/B,MAAM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,GAAG,kBAAkB,EAAE,CAAC;YACzB,SAAS;QACb,CAAC;QACD,iBAAiB;QAEjB,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QACvE,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,GAAG,CAAC,EAAE,EAAC,EAAE,CAAC,CAAC;QAE5B,IAAI,QAAQ,GAAG,eAAe;YAC1B,CAAC,CAAC,GAAG,oBAAoB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAEnD,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;gBACtB,4BAA4B;gBAC5B,kBAAkB;gBAClB,uCAAuC;gBACvC,qBAAqB;YACzB,CAAC;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACrB,CAAC;AAGD,OAAO,EAAE,mBAAmB,EAAE,CAAA"}
@@ -14,5 +14,5 @@ import { RbTree } from 'flo-ll-rb-tree';
14
14
  * @param order
15
15
  * @param order2
16
16
  */
17
- declare function getCpNodeToLeftOrSame(cpTree: RbTree<CpNode>, pos: PrePointOnShape, order: number, order2: number): CpNode | undefined;
18
- export { getCpNodeToLeftOrSame };
17
+ declare function getCpNodeNeighbors(cpTree: RbTree<CpNode>, pos: PrePointOnShape, order: number, order2: number): [CpNode, CpNode] | undefined;
18
+ export { getCpNodeNeighbors };
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @internal
3
+ *
4
+ * Returns the predecessor `CpNode` in the `CpTree` or the same one if they fall
5
+ * on top of each other.
6
+ *
7
+ * * returns `undefined` if the tree is still empty
8
+ *
9
+ * @param cpTree
10
+ * @param pos
11
+ * @param order
12
+ * @param order2
13
+ */
14
+ function getCpNodeNeighbors(cpTree, pos, order, order2) {
15
+ const pointOnShape = { ...pos, order, order2 };
16
+ const cps = cpTree.findBounds({ pointOnShape });
17
+ const [cp0, cp1] = cps;
18
+ if (cp0 === undefined && cp1 === undefined) {
19
+ // The tree is still empty
20
+ return undefined;
21
+ }
22
+ if (cp0 === undefined || cp1 === undefined) {
23
+ // Smaller than all OR larger than all
24
+ const minNode = cpTree.getMinNode()?.datum;
25
+ const maxNode = cpTree.getMaxNode()?.datum;
26
+ return [maxNode, minNode];
27
+ }
28
+ return [cp0.datum, cp1.datum];
29
+ }
30
+ export { getCpNodeNeighbors };
31
+ //# sourceMappingURL=get-cp-node-neighbors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-cp-node-neighbors.js","sourceRoot":"","sources":["../../src/mat/get-cp-node-neighbors.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,SAAS,kBAAkB,CACnB,MAAsB,EACtB,GAAoB,EACpB,KAAa,EACb,MAAc;IAElB,MAAM,YAAY,GAAG,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,EAAE,YAAY,EAAY,CAAC,CAAC;IAC1D,MAAM,CAAC,GAAG,EAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAEtB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACzC,0BAA0B;QAC1B,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;QACzC,sCAAsC;QACtC,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,KAAM,CAAC;QAC5C,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,KAAM,CAAC;QAE5C,OAAO,CAAC,OAAO,EAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAGD,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "flo-mat",
3
3
  "sideEffects": false,
4
4
  "description": "Medial / Scale Axis Transform (MAT/SAT) Library.",
5
- "version": "4.1.3",
5
+ "version": "4.1.4",
6
6
  "author": {
7
7
  "name": "Floris Steenkamp"
8
8
  },
@@ -33,10 +33,10 @@
33
33
  "dependencies": {
34
34
  "big-float-ts": "^4.0.4",
35
35
  "double-double": "^3.0.4",
36
- "flo-bezier3": "^8.0.14",
36
+ "flo-bezier3": "^8.1.1",
37
37
  "flo-boolean": "^6.0.2",
38
38
  "flo-gauss-quadrature": "^2.1.4",
39
- "flo-ll-rb-tree": "^1.0.1",
39
+ "flo-ll-rb-tree": "^1.0.4",
40
40
  "flo-memoize": "^2.0.1",
41
41
  "flo-poly": "^8.1.4",
42
42
  "flo-vector2d": "^4.0.6"
@@ -44,20 +44,20 @@
44
44
  "devDependencies": {
45
45
  "squares-rng": "^2.0.4",
46
46
  "@jest/globals": "^30.5.1",
47
- "@swc/core": "^1.16.1",
47
+ "@swc/core": "^1.16.2",
48
48
  "@swc/jest": "^0.2.39",
49
49
  "@types/jest": "^30.0.0",
50
50
  "jest": "^30.5.1",
51
51
  "jest-ts-webcompat-resolver": "^1.0.1",
52
52
  "ts-node": "^10.9.2",
53
- "@types/node": "^26.4.1",
53
+ "@types/node": "^26.6.0",
54
54
  "c8": "^12.0.0",
55
55
  "cheerio": "^1.2.0",
56
56
  "circular-dependency-plugin": "^5.2.2",
57
57
  "rimraf": "^6.1.3",
58
58
  "ts-loader": "^9.6.2",
59
59
  "typescript": "^6.0.3",
60
- "webpack": "^5.110.3",
60
+ "webpack": "^5.111.0",
61
61
  "webpack-cli": "^7.2.3"
62
62
  },
63
63
  "scripts": {
@@ -68,8 +68,8 @@
68
68
  "test-package": "npm pack"
69
69
  },
70
70
  "allowScripts": {
71
- "@swc/core@1.16.1": true,
72
71
  "unrs-resolver@1.12.2": true,
73
- "@parcel/watcher@2.6.0": true
72
+ "@parcel/watcher@2.6.0": true,
73
+ "@swc/core@1.16.2": true
74
74
  }
75
75
  }
@@ -5,19 +5,34 @@ import { RbTree } from "flo-ll-rb-tree";
5
5
  import { isOrderCorrect } from "./is-order-correct.js";
6
6
 
7
7
 
8
+ /**
9
+ *
10
+ * @param insertIfOrderWrong order cannot be checked for hole-closers since they're on different loops
11
+ * @param isHoleClosing
12
+ * @param isIntersection
13
+ * @param cpTree
14
+ * @param pos
15
+ * @param pred predecessor (to `pos`) on sampe loop (found via `cpTree`)
16
+ * @param succ successor (to `pos`) on sampe loop (found via `cpTree`)
17
+ * @param lastInsertId
18
+ */
8
19
  function insertCpNode(
9
20
  insertIfOrderWrong: boolean,
10
21
  isHoleClosing: boolean,
11
22
  isIntersection: boolean,
12
23
  cpTree: RbTree<CpNode>,
13
24
  pos: PointOnShape,
14
- _prev: CpNode | undefined,
25
+ pred: CpNode | undefined,
26
+ succ: CpNode | undefined,
15
27
  lastInsertId: { id: number }): CpNode | undefined {
16
28
 
17
- if (_prev !== undefined &&
18
- !isOrderCorrect(cpTree, pos, _prev.next)) {
19
-
20
- if (!insertIfOrderWrong) {
29
+ if (pred !== undefined && succ !== undefined) {
30
+ // !isOrderCorrect(cpTree, pos, pred.next, false)) {
31
+ const orderCorrect = isOrderCorrect(cpTree, pred, pos, succ, false);
32
+ // if (!orderCorrect) {
33
+ // console.log('aaaaa');
34
+ // }
35
+ if (!insertIfOrderWrong && !orderCorrect) {
21
36
  return undefined;
22
37
  }
23
38
  }
@@ -34,8 +49,8 @@ function insertCpNode(
34
49
  };
35
50
  lastInsertId.id++;
36
51
 
37
- const prev = _prev === undefined ? cpNode : _prev;
38
- const next = _prev === undefined ? cpNode : prev.next;
52
+ const prev = pred === undefined ? cpNode : pred;
53
+ const next = pred === undefined ? cpNode : prev.next;
39
54
 
40
55
  (next as Mutable<CpNode>).prev = cpNode;
41
56
  (prev as Mutable<CpNode>).next = cpNode;
@@ -0,0 +1,60 @@
1
+ import type { CpNode } from "../cp-node.js";
2
+ import { RbTree } from "flo-ll-rb-tree";
3
+ import { PointOnShape } from "../../point-on-shape/point-on-shape.js";
4
+ import { comparePoss } from "../../point-on-shape/compare-poss.js";
5
+
6
+
7
+ /**
8
+ *
9
+ * @param cpTree
10
+ * @param pos
11
+ * @param succ
12
+ * @param alreadyInserted set to `true` if the given `pos` has already been
13
+ * inserted, `false` otherwise.
14
+ */
15
+ function isOrderCorrect(
16
+ cpTree: RbTree<CpNode>,
17
+ pred: CpNode,
18
+ pos: PointOnShape,
19
+ succ: CpNode,
20
+ alreadyInserted: boolean): boolean {
21
+
22
+ if (cpTree.size <= (alreadyInserted ? 2 : 1)) {
23
+ return true;
24
+ }
25
+
26
+ const c = comparePoss(pos, succ.pointOnShape);
27
+
28
+
29
+ if (c < 0) { return true; }
30
+ if (c === 0) { return false; }
31
+
32
+ const minNode = cpTree.getMinNode()!.datum;
33
+ const maxNode = cpTree.getMaxNode()!.datum;
34
+
35
+ // larger than all -> crossing zero on loop
36
+ const largerThanAll = comparePoss(pos, maxNode.pointOnShape!) >= 0;
37
+ const r =
38
+ largerThanAll &&
39
+ minNode === succ;
40
+
41
+
42
+ // const r = (pos === max.pointOnShape) && (next === min);
43
+
44
+ if (!r) {
45
+ console.log(c);
46
+ console.log(cpTree.toArr().map(v => {
47
+ return {
48
+ curveIdx: v.pointOnShape.curve.idx,
49
+ t: v.pointOnShape.t,
50
+ order: v.pointOnShape.order,
51
+ order2: v.pointOnShape.order2
52
+ }
53
+ }));
54
+ }
55
+
56
+ return r;
57
+ }
58
+
59
+
60
+ export { isOrderCorrect }
@@ -4,27 +4,75 @@ import { PointOnShape } from "../../point-on-shape/point-on-shape.js";
4
4
  import { comparePoss } from "../../point-on-shape/compare-poss.js";
5
5
 
6
6
 
7
+ /**
8
+ *
9
+ * @param cpTree
10
+ * @param pos
11
+ * @param succ
12
+ * @param alreadyInserted set to `true` if the given `pos` has already been
13
+ * inserted, `false` otherwise.
14
+ */
7
15
  function isOrderCorrect(
8
16
  cpTree: RbTree<CpNode>,
17
+ pred: CpNode,
9
18
  pos: PointOnShape,
10
- next: CpNode): boolean {
19
+ succ: CpNode,
20
+ alreadyInserted: boolean): boolean {
11
21
 
12
- const c = comparePoss(pos, next.pointOnShape);
13
- if (c < 0) { return true; }
14
- if (c === 0) {
15
- return false;
16
- }
17
-
18
- const minNode = cpTree.getMinNode();
19
- if (minNode === undefined) { // if tree not empty
22
+ if (cpTree.size <= (alreadyInserted ? 2 : 1)) {
20
23
  return true;
21
24
  }
22
25
 
23
- const min = minNode.datum;
24
- const max = cpTree.getMaxNode()!.datum;
26
+ const a = pred.pointOnShape;
27
+ const b = pos;
28
+ const c = succ.pointOnShape;
29
+
30
+ // Let a = pred, b = pos, and c = succ.
31
+ // For a cyclic order we need:
32
+ // `(a < b && b < c)` || `(b < c && c < a)` || `(c < a && a < b)`
33
+ // Let `X = a < b, Y = b < c, Z = c < a` then
34
+ // `(X && Y)` || `(Y && Z)` || `(Z && X)`
35
+
36
+ const _X = comparePoss(a, b);
37
+ if (_X === 0) { // two points must have different order
38
+ // console.log('aaa');
39
+ // throw 'a';
40
+ return false;
41
+ }
42
+ const _Y = comparePoss(b, c);
43
+ if (_Y === 0) { // two points must have different order
44
+ // console.log('bbb');
45
+ // throw 'b';
46
+ return false;
47
+ }
48
+ const _Z = comparePoss(c, a);
49
+ if (_Z === 0) {
50
+ // console.log('bbb');
51
+ // throw 'c';
52
+ return false;
53
+ } // impossible anyway at this point
54
+
55
+ // Now neither `_X` nor `_Y` nor `_Z` === `0`
56
+ const X = _X < 0;
57
+ const Y = _Y < 0;
58
+ const Z = _Z < 0;
59
+
60
+ // Cyclic order condition
61
+ if ((X && Y) || (Y && Z) || (Z && X)) { return true; }
62
+
63
+ // throw 'd';
64
+
65
+ // console.log(_X, _Y, _Z);
66
+ // console.log(cpTree.toArr().map(v => {
67
+ // return {
68
+ // curveIdx: v.pointOnShape.curve.idx,
69
+ // t: v.pointOnShape.t,
70
+ // order: v.pointOnShape.order,
71
+ // order2: v.pointOnShape.order2
72
+ // }
73
+ // }));
25
74
 
26
- // larger than all -> crossing zero on loop
27
- return (comparePoss(max.pointOnShape!, pos) < 0 && min === next);
75
+ return false;
28
76
  }
29
77
 
30
78
 
@@ -15,7 +15,7 @@ function removeCpNode(
15
15
  (next as Mutable<CpNode>).prev = prev;
16
16
 
17
17
  const cpTree = cpTrees.get(cpNode.pointOnShape.curve.loop)!;
18
- cpTree.remove(cpNode, false);
18
+ cpTree.remove(cpNode);
19
19
  }
20
20
 
21
21
 
@@ -4,7 +4,18 @@ import { CpNode } from "../../cp-node/cp-node.js";
4
4
  import { getAllOnLoop } from "../../cp-node/fs/get-all-on-loop.js";
5
5
  import { getProngCount } from "../../cp-node/fs/get-prong-count.js";
6
6
  import { isOrderCorrect } from "../../cp-node/fs/is-order-correct.js";
7
- import { comparePoss } from "../../point-on-shape/compare-poss.js";
7
+
8
+
9
+ interface Order {
10
+ prongCount: number;
11
+ cpNode: CpNode;
12
+ p: number[];
13
+ /** From highest to lowest significance */
14
+ curveIdx: number;
15
+ t: number;
16
+ order: number;
17
+ order2: number;
18
+ }
8
19
 
9
20
 
10
21
  function checkOrdering(
@@ -16,81 +27,53 @@ function checkOrdering(
16
27
  const cpNodes = getAllOnLoop(cpStart);
17
28
 
18
29
  const wrongsPerLoop: Map<Loop,[Order,Order][]> = new Map();
19
- for (const cpNodeA of cpNodes) {
20
- const cpNodeB = cpNodeA.next;
21
-
22
- const posA = cpNodeA.pointOnShape;
23
- const idxA = posA.curve.idx;
24
- const pA = posA.p;
25
- const loopA = posA.curve.loop;
26
- const cpTreeA = cpTrees.get(loopA)!;
27
-
28
- const posB = cpNodeB.pointOnShape;
29
- const idxB = posB.curve.idx;
30
- const pB = posB.p;
31
- // const loopB = posB.curve.loop;
32
- // const cpTreeB = cpTrees.get(loopB)!;
33
-
30
+ for (const cpNode of cpNodes) {
31
+ const pos = cpNode.pointOnShape;
32
+ const loop = pos.curve.loop;
33
+
34
+ if (loop !== cpNode.prev.pointOnShape.curve.loop ||
35
+ loop !== cpNode.next.pointOnShape.curve.loop) {
36
+
37
+ continue;
38
+ }
39
+
40
+ const cpTree = cpTrees.get(loop)!;
41
+
34
42
  const orderCorrect = isOrderCorrect(
35
- cpTreeA, posA, cpNodeB
36
- )
43
+ cpTree, cpNode.prev, cpNode.pointOnShape, cpNode.next, true
44
+ );
37
45
  if (!orderCorrect) {
38
- const A: Order = {
39
- prongCount: getProngCount(cpNodeA),
40
- p: pA,
41
- cpNode: cpNodeA,
42
- curveIdx: idxA,
43
- t: posA.t,
44
- order: posA.order,
45
- order2: posA.order2
46
- }
47
- const B: Order = {
48
- prongCount: getProngCount(cpNodeB),
49
- p: pB,
50
- cpNode: cpNodeB,
51
- curveIdx: idxB,
52
- t: posB.t,
53
- order: posB.order,
54
- order2: posB.order2
55
- }
56
- const loopA = A.cpNode.pointOnShape.curve.loop;
57
- let wrongs = wrongsPerLoop.get(loopA);
58
- if (wrongs === undefined) {
59
- wrongs = [];
60
- wrongsPerLoop.set(loopA, wrongs);
61
- }
46
+ const A = toOrder(cpNode);
47
+ const B = toOrder(cpNode.next);
48
+
49
+ let wrongs = wrongsPerLoop.getOrInsert(loop, []);
62
50
  wrongs.push([A,B]);
63
51
  }
64
52
  }
65
53
 
66
54
  for (const [loop,wrongs] of wrongsPerLoop) {
67
- let maxOrder = -Infinity;
68
- let max: Order | undefined = undefined;
69
55
  for (const wrong of wrongs) {
70
56
  const A = wrong[0];
71
57
  const B = wrong[1];
72
- const c = comparePoss(A.cpNode.pointOnShape, B.cpNode.pointOnShape);
73
- if (c > maxOrder) {
74
-
75
- }
76
- // console.log(wrong[0]);
77
- // console.log(wrong[1]);
78
- // console.log('---------');
58
+ // const c = comparePoss(A.cpNode.pointOnShape, B.cpNode.pointOnShape);
59
+
60
+ console.log(A);
61
+ console.log(B);
62
+ console.log('---------');
79
63
  }
80
64
  }
81
- // }
82
65
  }
83
66
 
84
67
 
85
- interface Order {
86
- prongCount: number;
87
- cpNode: CpNode;
88
- p: number[];
89
- /** From highest to lowest significance */
90
- curveIdx: number;
91
- t: number;
92
- order: number;
93
- order2: number;
68
+ function toOrder(
69
+ cpNode: CpNode): Order {
70
+
71
+ const prongCount = getProngCount(cpNode);
72
+ const { pointOnShape } = cpNode;
73
+ const { p, t, order, order2, curve } = pointOnShape;
74
+ const curveIdx = curve.idx;
75
+
76
+ return { cpNode, prongCount, p, curveIdx, t, order, order2 };
94
77
  }
95
78
 
96
79
 
@@ -90,6 +90,7 @@ function closeHole(
90
90
  cpTrees.get(posAntipode.curve.loop)!,
91
91
  { ...posAntipode, order2: +1 },
92
92
  cpNodeAntipode,
93
+ undefined, // unused
93
94
  meta.lastInsertId
94
95
  )! as Mutable<CpNode>;
95
96
  cpNodeAntipodeTwin.holeCloserTwin = cpNodeAntipode;
@@ -100,8 +101,9 @@ function closeHole(
100
101
  const cpNodeSourceTwin = insertCpNode(
101
102
  true, true, false,
102
103
  cpTrees.get(posSource.curve.loop)!,
103
- { ...cpNodeSource.pointOnShape!, order2: -1 },
104
+ { ...posSource!, order2: -1 },
104
105
  cpNodeSource.prev,
106
+ undefined, // unused
105
107
  meta.lastInsertId
106
108
  )! as Mutable<CpNode>;
107
109
  cpNodeSourceTwin.holeCloserTwin = cpNodeSource;
@@ -37,7 +37,7 @@ function findAndAdd2Prongs(
37
37
  for (let i=0; i<for2Prongs.length; i++) {
38
38
  const pos = for2Prongs[i];
39
39
 
40
- const angles = getValidAngles(angleIncrement_, pos);
40
+ const angles = for1Prong ? [0] : getValidAngles(angleIncrement_, pos);
41
41
 
42
42
  for (const angle of angles) {
43
43
  const twoProngInfo = find2Prong_(
@@ -2,7 +2,7 @@ import type { Loop } from 'flo-boolean';
2
2
  import type { CurvePiece } from '../mat/curve-piece.js';
3
3
  import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
4
4
  import type { MatMeta } from '../mat/mat-meta.js';
5
- import { getCpNodeToLeftOrSame } from '../mat/get-cp-node-to-left-or-same.js';
5
+ import { getCpNodeNeighbors } from '../mat/get-cp-node-neighbors.js';
6
6
  import { getBoundaryPieceBeziers } from '../mat/get-boundary-piece-beziers.js';
7
7
  import { calcPosOrder } from '../point-on-shape/calc-pos-order.js';
8
8
  import { isPosCorner } from '../point-on-shape/is-pos-corner.js';
@@ -38,7 +38,7 @@ function getInitialCurvePieces(
38
38
  : calcPosOrder(xO, yPos)
39
39
  : 0;
40
40
 
41
- const cpNode = getCpNodeToLeftOrSame(cpTrees.get(loop)!, yPos, order, 0);
41
+ const cpNode = getCpNodeNeighbors(cpTrees.get(loop)!, yPos, order, 0)?.[0];
42
42
  if (!cpNode ||
43
43
  // The special case if there is only a single sharp corner or
44
44
  // two-way terminating 2-prong currently in the MAT. Don't remove!
@@ -28,7 +28,7 @@ const { min, abs, asin } = Math;
28
28
  * @internal
29
29
  */
30
30
  function find3ProngForDelta3s(
31
- δs: CpNode[][],
31
+ δs: [CpNode, CpNode][],
32
32
  idx: number,
33
33
  k: number,
34
34
  curvePiecess: CurvePiece[][],
@@ -37,25 +37,33 @@ function find3ProngForDelta3s(
37
37
  const TOLERANCE = 2**(maxCoordPowerOf2 - 32);
38
38
  const MAX_ITERATIONS = 10;
39
39
 
40
- const δs_ = [
40
+ const δs_: [[CpNode,CpNode], [CpNode,CpNode], [CpNode,CpNode]] = [
41
41
  δs[0],
42
42
  δs[idx],
43
43
  δs[δs.length-1]
44
44
  ];
45
45
 
46
- const curvePieces_ = [
46
+ const curvePieces_: [CurvePiece[], CurvePiece[], CurvePiece[]] = [
47
47
  curvePiecess[0],
48
48
  curvePiecess[idx],
49
- curvePiecess[δs.length-1]
49
+ curvePiecess[δs.length - 1]
50
50
  ];
51
51
 
52
- const δ3ss = [
52
+ const δ3ss: [
53
+ [[CpNode, CpNode], [CpNode, CpNode], [CpNode, CpNode]],
54
+ [[CpNode, CpNode], [CpNode, CpNode], [CpNode, CpNode]],
55
+ [[CpNode, CpNode], [CpNode, CpNode], [CpNode, CpNode]]
56
+ ] = [
53
57
  [δs_[0], δs_[1], δs_[2]],
54
58
  [δs_[1], δs_[2], δs_[0]],
55
59
  [δs_[2], δs_[0], δs_[1]],
56
60
  ];
57
61
 
58
- const curvePiecess_ = [
62
+ const curvePiecess_: [
63
+ [CurvePiece[], CurvePiece[], CurvePiece[]],
64
+ [CurvePiece[], CurvePiece[], CurvePiece[]],
65
+ [CurvePiece[], CurvePiece[], CurvePiece[]]
66
+ ] = [
59
67
  [curvePieces_[0], curvePieces_[1], curvePieces_[2]],
60
68
  [curvePieces_[1], curvePieces_[2], curvePieces_[0]],
61
69
  [curvePieces_[2], curvePieces_[0], curvePieces_[1]],
@@ -14,7 +14,7 @@ import { getBoundaryPieceBeziers } from '../mat/get-boundary-piece-beziers.js';
14
14
  * @internal
15
15
  */
16
16
  function find3Prong(
17
- δs: CpNode[][],
17
+ δs: [CpNode, CpNode][],
18
18
  maxCoordPowerOf2: number): ThreeProngInfo {
19
19
 
20
20
  // FUTURE if `δs.length > (some threshold (say 4 or 5))` then add two-prongs
@@ -25,7 +25,6 @@ function findAndAdd3Prong(
25
25
  δs.push([visitedCp, visitedCp.next]);
26
26
  }
27
27
 
28
-
29
28
  const threeProngInfo = find3Prong(δs, meta.maxCoordPowerOf2);
30
29
 
31
30
  const { circle, poss, δ3s } = threeProngInfo;
@@ -49,9 +48,7 @@ function findAndAdd3Prong(
49
48
  }
50
49
 
51
50
  const cpNodes = closeBysFor3Prong.length === 0
52
- ? addToCpTree(
53
- true, false, circle, orders, meta, poss, δ3s.map(v => v[0])
54
- ).cpNodes
51
+ ? addToCpTree(true, false, circle, orders, meta, poss, δ3s).cpNodes
55
52
  : [];
56
53
 
57
54
  return { closeBysFor3Prong, cpNodes: cpNodes as CpNode[] };