flo-mat 3.0.9 → 3.0.11

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 (261) hide show
  1. package/__tests__/jsog/check-jsog-eql-calc.spec.ts +81 -0
  2. package/__tests__/jsog/decode-jsog.ts +85 -0
  3. package/__tests__/jsog/get-mats1.ts +41 -0
  4. package/__tests__/{cp-node/fs → jsog}/mat-dummys.ts +51 -564
  5. package/__tests__/jsog/to-jsog-breath-first.ts +107 -0
  6. package/__tests__/jsog/to-jsog-depth-first.ts +55 -0
  7. package/browser/index.js +280 -236
  8. package/browser/index.min.js +1 -1
  9. package/node/add-n-prong.ts/join-spokes.js.map +1 -1
  10. package/node/closest-boundary-point/cull-bezier-pieces.d.ts +5 -4
  11. package/node/closest-boundary-point/cull-bezier-pieces.js +9 -8
  12. package/node/closest-boundary-point/cull-bezier-pieces.js.map +1 -1
  13. package/node/closest-boundary-point/cull-by-loose-bounding-box.d.ts +2 -2
  14. package/node/closest-boundary-point/cull-by-loose-bounding-box.js +8 -8
  15. package/node/closest-boundary-point/cull-by-loose-bounding-box.js.map +1 -1
  16. package/node/closest-boundary-point/cull-by-tight-boundary-box.d.ts +2 -2
  17. package/node/closest-boundary-point/cull-by-tight-boundary-box.js +8 -8
  18. package/node/closest-boundary-point/cull-by-tight-boundary-box.js.map +1 -1
  19. package/node/closest-boundary-point/dd-deflate-with-running-error.js.map +1 -1
  20. package/node/closest-boundary-point/get-best-distance-squared.d.ts +1 -1
  21. package/node/closest-boundary-point/get-best-distance-squared.js +6 -6
  22. package/node/closest-boundary-point/get-best-distance-squared.js.map +1 -1
  23. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +2 -2
  24. package/node/closest-boundary-point/get-close-boundary-points-certified.js +7 -7
  25. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  26. package/node/contact-point/contact-point.js.map +1 -1
  27. package/node/corner/get-corner.js.map +1 -1
  28. package/node/corner/get-interface-ccw.js.map +1 -1
  29. package/node/cp-node/cp-node-fs.d.ts +2 -1
  30. package/node/cp-node/cp-node-fs.js +1 -2
  31. package/node/cp-node/cp-node-fs.js.map +1 -1
  32. package/node/cp-node/fs/cp-node-comparator.d.ts +3 -0
  33. package/node/cp-node/fs/cp-node-comparator.js +6 -0
  34. package/node/cp-node/fs/cp-node-comparator.js.map +1 -0
  35. package/node/cp-node/fs/find-first.js.map +1 -1
  36. package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
  37. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.d.ts +1 -1
  38. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js +11 -16
  39. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js.map +1 -1
  40. package/node/cp-node/fs/get-boundary-beziers-between.js +4 -6
  41. package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
  42. package/node/cp-node/fs/get-boundary-beziers-to-next.d.ts +10 -1
  43. package/node/cp-node/fs/get-boundary-beziers-to-next.js +70 -35
  44. package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
  45. package/node/cp-node/fs/get-branch-beziers.js.map +1 -1
  46. package/node/cp-node/fs/get-branch.js.map +1 -1
  47. package/node/cp-node/fs/get-children.js.map +1 -1
  48. package/node/cp-node/fs/get-first-exit.js.map +1 -1
  49. package/node/cp-node/fs/get-mat-curve-to-next.js.map +1 -1
  50. package/node/cp-node/fs/get-mat-curves-between.js.map +1 -1
  51. package/node/cp-node/fs/get-prong-count.js.map +1 -1
  52. package/node/cp-node/fs/get-real-prong-count.js.map +1 -1
  53. package/node/cp-node/fs/get-salience.js +2 -2
  54. package/node/cp-node/fs/get-salience.js.map +1 -1
  55. package/node/cp-node/fs/get-speed.js +0 -1
  56. package/node/cp-node/fs/get-speed.js.map +1 -1
  57. package/node/cp-node/fs/get-vertex-forward-children.js.map +1 -1
  58. package/node/cp-node/fs/is-fully-terminating.d.ts +1 -1
  59. package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
  60. package/node/cp-node/fs/is-one-prong.js.map +1 -1
  61. package/node/cp-node/fs/is-sharp.js.map +1 -1
  62. package/node/cp-node/fs/is-terminating.js.map +1 -1
  63. package/node/cp-node/fs/traverse-cp.js.map +1 -1
  64. package/node/cp-node/fs/traverse-edges.js.map +1 -1
  65. package/node/cp-node/fs/traverse-vertices.js.map +1 -1
  66. package/node/debug/functions/draw-elem/bounding-hull.js.map +1 -1
  67. package/node/debug/functions/draw-elem/draw-cp-node.js +1 -1
  68. package/node/debug/functions/draw-elem/draw-cp-node.js.map +1 -1
  69. package/node/debug/functions/draw-elem/draw-cull.js.map +1 -1
  70. package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
  71. package/node/debug/functions/draw-elem/draw-elem.js.map +1 -1
  72. package/node/debug/functions/draw-elem/draw-leaves.js.map +1 -1
  73. package/node/debug/functions/draw-elem/draw-loose-bounding-box.js.map +1 -1
  74. package/node/debug/functions/draw-elem/draw-max-vertex.js.map +1 -1
  75. package/node/debug/functions/draw-elem/draw-min-y.js.map +1 -1
  76. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +1 -1
  77. package/node/debug/functions/draw-elem/draw-one-prong.js.map +1 -1
  78. package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
  79. package/node/debug/functions/draw-elem/draw-speed.js.map +1 -1
  80. package/node/debug/functions/draw-elem/draw-three-prong.js.map +1 -1
  81. package/node/debug/functions/draw-elem/draw-tight-bounding-box.js.map +1 -1
  82. package/node/debug/functions/draw-elem/draw-two-prong.js.map +1 -1
  83. package/node/debug/functions/draw-elem/draw-vertex.js.map +1 -1
  84. package/node/debug/functions/general.js.map +1 -1
  85. package/node/find-2-prong/add-1-prong.js.map +1 -1
  86. package/node/find-2-prong/cull-bezier-pieces.d.ts +4 -4
  87. package/node/find-2-prong/cull-bezier-pieces.js +9 -9
  88. package/node/find-2-prong/cull-bezier-pieces.js.map +1 -1
  89. package/node/find-2-prong/find-2-prong.js +8 -8
  90. package/node/find-2-prong/find-2-prong.js.map +1 -1
  91. package/node/find-2-prong/find-equidistant-point-on-line-dd.js.map +1 -1
  92. package/node/find-2-prong/get-initial-bezier-pieces.d.ts +2 -2
  93. package/node/find-2-prong/get-initial-bezier-pieces.js +2 -2
  94. package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
  95. package/node/find-2-prong/reduce-radius.d.ts +1 -1
  96. package/node/find-2-prong/reduce-radius.js +5 -5
  97. package/node/find-2-prong/reduce-radius.js.map +1 -1
  98. package/node/find-3-prong.ts/calc-better-x.d.ts +2 -2
  99. package/node/find-3-prong.ts/calc-better-x.js +3 -3
  100. package/node/find-3-prong.ts/calc-better-x.js.map +1 -1
  101. package/node/find-3-prong.ts/calc-initial-3-prong-center.d.ts +2 -2
  102. package/node/find-3-prong.ts/calc-initial-3-prong-center.js +3 -3
  103. package/node/find-3-prong.ts/calc-initial-3-prong-center.js.map +1 -1
  104. package/node/find-3-prong.ts/find-3-prong-for-delta3s.d.ts +2 -2
  105. package/node/find-3-prong.ts/find-3-prong-for-delta3s.js +16 -16
  106. package/node/find-3-prong.ts/find-3-prong-for-delta3s.js.map +1 -1
  107. package/node/find-3-prong.ts/find-3-prong.js +2 -2
  108. package/node/find-3-prong.ts/find-3-prong.js.map +1 -1
  109. package/node/find-3-prong.ts/find-and-add-3-prong.js.map +1 -1
  110. package/node/find-3-prong.ts/find-and-add-3-prongs.js.map +1 -1
  111. package/node/find-3-prong.ts/get-closest-points.d.ts +2 -2
  112. package/node/find-3-prong.ts/get-closest-points.js +4 -4
  113. package/node/find-3-prong.ts/get-closest-points.js.map +1 -1
  114. package/node/find-mat/find-mats.js.map +1 -1
  115. package/node/geometry/get-closest-square-distance-to-rect.js.map +1 -1
  116. package/node/geometry/get-closest-squared-distance-to-rotated-rect.js.map +1 -1
  117. package/node/index.d.ts +35 -1
  118. package/node/index.js +36 -1
  119. package/node/index.js.map +1 -1
  120. package/node/mat/create-new-cp-tree.js.map +1 -1
  121. package/node/mat/get-boundary-piece-beziers.js +7 -7
  122. package/node/mat/get-boundary-piece-beziers.js.map +1 -1
  123. package/node/mat/get-largest-vertex.js.map +1 -1
  124. package/node/mat/trim-mat.js.map +1 -1
  125. package/node/memoize-primitive.js.map +1 -1
  126. package/node/sat/add-debug-info.js.map +1 -1
  127. package/node/sat/cull.d.ts +7 -5
  128. package/node/sat/cull.js +7 -4
  129. package/node/sat/cull.js.map +1 -1
  130. package/node/sat/get-leaves.js.map +1 -1
  131. package/node/sat/to-scale-axis.d.ts +3 -2
  132. package/node/sat/to-scale-axis.js +3 -2
  133. package/node/sat/to-scale-axis.js.map +1 -1
  134. package/node/svg/get-loop-bounds.js.map +1 -1
  135. package/node/svg/get-min-y-pos.js.map +1 -1
  136. package/node/sweep-line/sweep-line.js.map +1 -1
  137. package/package.json +6 -6
  138. package/src/add-n-prong.ts/join-spokes.ts +11 -11
  139. package/src/closest-boundary-point/cull-bezier-pieces.ts +12 -11
  140. package/src/closest-boundary-point/cull-by-loose-bounding-box.ts +8 -8
  141. package/src/closest-boundary-point/cull-by-tight-boundary-box.ts +8 -8
  142. package/src/closest-boundary-point/dd-deflate-with-running-error.ts +22 -22
  143. package/src/closest-boundary-point/get-best-distance-squared.ts +6 -6
  144. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +41 -41
  145. package/src/contact-point/contact-point.ts +13 -13
  146. package/src/corner/get-corner.ts +39 -39
  147. package/src/corner/get-interface-ccw.ts +3 -3
  148. package/src/cp-node/cp-node-fs.ts +132 -135
  149. package/src/cp-node/cp-node.ts +30 -30
  150. package/src/cp-node/fs/clone.ts +4 -4
  151. package/src/cp-node/fs/cp-node-comparator.ts +13 -0
  152. package/src/cp-node/fs/find-first.ts +6 -6
  153. package/src/cp-node/fs/get-all-on-loop.ts +1 -1
  154. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +12 -18
  155. package/src/cp-node/fs/get-boundary-beziers-between.ts +6 -7
  156. package/src/cp-node/fs/get-boundary-beziers-to-next.ts +79 -53
  157. package/src/cp-node/fs/get-branch-beziers.ts +1 -1
  158. package/src/cp-node/fs/get-branch.ts +1 -1
  159. package/src/cp-node/fs/get-children.ts +8 -8
  160. package/src/cp-node/fs/get-first-exit.ts +11 -11
  161. package/src/cp-node/fs/get-mat-curve-to-next.ts +1 -1
  162. package/src/cp-node/fs/get-mat-curves-between.ts +1 -1
  163. package/src/cp-node/fs/get-prong-count.ts +8 -8
  164. package/src/cp-node/fs/get-real-prong-count.ts +3 -3
  165. package/src/cp-node/fs/get-salience.ts +2 -2
  166. package/src/cp-node/fs/get-speed.ts +1 -6
  167. package/src/cp-node/fs/get-vertex-forward-children.ts +10 -10
  168. package/src/cp-node/fs/is-fully-terminating.ts +3 -3
  169. package/src/cp-node/fs/is-one-prong.ts +8 -8
  170. package/src/cp-node/fs/is-sharp.ts +1 -1
  171. package/src/cp-node/fs/is-terminating.ts +1 -1
  172. package/src/cp-node/fs/iterate-all-on-loop.ts +6 -6
  173. package/src/cp-node/fs/traverse-all-forward.ts +11 -11
  174. package/src/cp-node/fs/traverse-cp.ts +19 -17
  175. package/src/cp-node/fs/traverse-edges.ts +10 -10
  176. package/src/cp-node/fs/traverse-vertices.ts +17 -17
  177. package/src/curve/curve.ts +26 -26
  178. package/src/debug/functions/cmp-cp-on-delta.ts +1 -1
  179. package/src/debug/functions/draw-elem/bounding-hull.ts +2 -2
  180. package/src/debug/functions/draw-elem/culls.ts +2 -2
  181. package/src/debug/functions/draw-elem/draw-cp-node.ts +30 -30
  182. package/src/debug/functions/draw-elem/draw-cull.ts +2 -2
  183. package/src/debug/functions/draw-elem/draw-dull-corner.ts +7 -7
  184. package/src/debug/functions/draw-elem/draw-elem.ts +28 -28
  185. package/src/debug/functions/draw-elem/draw-leaves.ts +12 -12
  186. package/src/debug/functions/draw-elem/draw-loose-bounding-box.ts +7 -7
  187. package/src/debug/functions/draw-elem/draw-max-vertex.ts +2 -2
  188. package/src/debug/functions/draw-elem/draw-min-y.ts +2 -2
  189. package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +1 -1
  190. package/src/debug/functions/draw-elem/draw-one-prong.ts +1 -1
  191. package/src/debug/functions/draw-elem/draw-sharp-corner.ts +6 -6
  192. package/src/debug/functions/draw-elem/draw-speed.ts +2 -2
  193. package/src/debug/functions/draw-elem/draw-three-prong.ts +28 -28
  194. package/src/debug/functions/draw-elem/draw-tight-bounding-box.ts +4 -4
  195. package/src/debug/functions/draw-elem/draw-two-prong.ts +51 -51
  196. package/src/debug/functions/draw-elem/draw-vertex.ts +12 -12
  197. package/src/debug/functions/draw-elem/dull-corner.ts +7 -7
  198. package/src/debug/functions/draw-elem/leaves.ts +2 -2
  199. package/src/debug/functions/draw-elem/loose-bounding-box.ts +7 -7
  200. package/src/debug/functions/draw-elem/max-vertex.ts +2 -2
  201. package/src/debug/functions/draw-elem/min-y.ts +2 -2
  202. package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +1 -1
  203. package/src/debug/functions/draw-elem/one-prong.ts +1 -1
  204. package/src/debug/functions/draw-elem/sharp-corner.ts +6 -6
  205. package/src/debug/functions/draw-elem/three-prong.ts +19 -19
  206. package/src/debug/functions/draw-elem/tight-bounding-box.ts +4 -4
  207. package/src/debug/functions/draw-elem/two-prong.ts +44 -44
  208. package/src/debug/functions/draw-elem/vertex.ts +28 -28
  209. package/src/debug/functions/general.ts +18 -18
  210. package/src/debug/functions/three-prong.ts +184 -184
  211. package/src/debug/functions/two-prong.ts +201 -201
  212. package/src/debug/two-prong-for-debugging.ts +26 -26
  213. package/src/find-2-prong/add-1-prong.ts +25 -25
  214. package/src/find-2-prong/add-debug-info.ts +38 -38
  215. package/src/find-2-prong/cull-bezier-pieces.ts +10 -10
  216. package/src/find-2-prong/find-2-prong.ts +158 -158
  217. package/src/find-2-prong/find-equidistant-point-on-line-dd.ts +50 -50
  218. package/src/find-2-prong/find-equidistant-point-on-line.ts +27 -27
  219. package/src/find-2-prong/get-initial-bezier-pieces.ts +2 -2
  220. package/src/find-2-prong/reduce-radius.ts +5 -5
  221. package/src/find-3-prong.ts/calc-better-x.ts +3 -3
  222. package/src/find-3-prong.ts/calc-initial-3-prong-center.ts +3 -3
  223. package/src/find-3-prong.ts/find-3-prong-for-delta3s.ts +17 -17
  224. package/src/find-3-prong.ts/find-3-prong.ts +23 -23
  225. package/src/find-3-prong.ts/find-and-add-3-prong.ts +37 -37
  226. package/src/find-3-prong.ts/find-and-add-3-prongs.ts +30 -30
  227. package/src/find-3-prong.ts/get-closest-points.ts +4 -4
  228. package/src/find-mat/add-2-prongs-by-error.ts +8 -8
  229. package/src/find-mat/find-mats.ts +49 -49
  230. package/src/find-mat/fix-ordering.ts +2 -2
  231. package/src/find-mat/get-total-by.ts +12 -12
  232. package/src/geometry/get-closest-square-distance-to-rect.ts +37 -37
  233. package/src/geometry/get-closest-squared-distance-to-rotated-rect.ts +14 -14
  234. package/src/get-curve/get-curve-between.ts +1 -1
  235. package/src/index.ts +41 -4
  236. package/src/mat/cmp-cp-on-delta.ts +1 -1
  237. package/src/mat/create-new-cp-tree.ts +12 -12
  238. package/src/mat/get-boundary-piece-beziers.ts +7 -7
  239. package/src/mat/get-edges-as-array.ts +9 -9
  240. package/src/mat/get-largest-3-prong.ts +8 -8
  241. package/src/mat/get-largest-three-prong.ts +5 -5
  242. package/src/mat/get-largest-vertex.ts +6 -6
  243. package/src/mat/get-two-prong-type.ts +9 -9
  244. package/src/mat/trim-mat.ts +1 -1
  245. package/src/memoize-primitive.ts +14 -14
  246. package/src/sat/add-debug-info.ts +4 -4
  247. package/src/sat/cull-by-salience.ts +1 -1
  248. package/src/sat/cull.ts +10 -7
  249. package/src/sat/get-leaves.ts +0 -1
  250. package/src/sat/to-scale-axis.ts +18 -17
  251. package/src/svg/get-extreme.ts +8 -8
  252. package/src/svg/get-loop-bounds.ts +84 -84
  253. package/src/svg/get-min-y-pos.ts +1 -1
  254. package/src/sweep-line/sweep-line.ts +23 -23
  255. package/src/utils/bezier-piece-to-bezier.ts +7 -7
  256. package/__tests__/cp-node/fs/check-jsog-eql-calc.spec.ts +0 -30
  257. package/node/cp-node/fs/cp-nodes-to-boundary-beziers.d.ts +0 -3
  258. package/node/cp-node/fs/cp-nodes-to-boundary-beziers.js +0 -6
  259. package/node/cp-node/fs/cp-nodes-to-boundary-beziers.js.map +0 -1
  260. package/src/closest-boundary-point/get-closest-boundary-point-certified.ts +0 -70
  261. package/src/cp-node/fs/cp-nodes-to-boundary-beziers.ts +0 -10
@@ -27,7 +27,7 @@ const calcVectorToZeroV_StraightToIt = fromTo;
27
27
  * Finds a 3-prong using only the 3 given δs.
28
28
  * @param δs The boundary pieces
29
29
  * @param idx δ identifier
30
- * @param bezierPiecess
30
+ * @param curvePiecess
31
31
  * @param maxCoordinate The maximum coordinate value used to calculate floating point
32
32
  * tolerances.
33
33
  */
@@ -35,7 +35,7 @@ function find3ProngForDelta3s(
35
35
  δs: CpNode[][],
36
36
  idx: number,
37
37
  k: number,
38
- bezierPiecess: CurvePiece[][],
38
+ curvePiecess: CurvePiece[][],
39
39
  maxCoordinate: number) {
40
40
 
41
41
  const TOLERANCE = 2**-32*maxCoordinate;
@@ -47,10 +47,10 @@ function find3ProngForDelta3s(
47
47
  δs[δs.length-1]
48
48
  ];
49
49
 
50
- const bezierPieces_ = [
51
- bezierPiecess[0],
52
- bezierPiecess[idx],
53
- bezierPiecess[δs.length-1]
50
+ const curvePieces_ = [
51
+ curvePiecess[0],
52
+ curvePiecess[idx],
53
+ curvePiecess[δs.length-1]
54
54
  ];
55
55
 
56
56
  const δ3ss = [
@@ -59,15 +59,15 @@ function find3ProngForDelta3s(
59
59
  [δs_[2], δs_[0], δs_[1]],
60
60
  ];
61
61
 
62
- const bezierPiecess_ = [
63
- [bezierPieces_[0], bezierPieces_[1], bezierPieces_[2]],
64
- [bezierPieces_[1], bezierPieces_[2], bezierPieces_[0]],
65
- [bezierPieces_[2], bezierPieces_[0], bezierPieces_[1]],
62
+ const curvePiecess_ = [
63
+ [curvePieces_[0], curvePieces_[1], curvePieces_[2]],
64
+ [curvePieces_[1], curvePieces_[2], curvePieces_[0]],
65
+ [curvePieces_[2], curvePieces_[0], curvePieces_[1]],
66
66
  ]
67
67
 
68
68
 
69
69
  const δ3s = δ3ss[k];
70
- const bezierPiece3s = bezierPiecess_[k];
70
+ const curvePiece3s = curvePiecess_[k];
71
71
 
72
72
  if (isSharp(δ3s[0][0])) { return undefined; }
73
73
 
@@ -75,13 +75,13 @@ function find3ProngForDelta3s(
75
75
  let poss: PointOnShape[] = undefined!;
76
76
  let circumCenter_;
77
77
  let j = 0; // Safeguard for slow convergence
78
- let x = calcInitial3ProngCenter(maxCoordinate, δ3s, bezierPiece3s);
78
+ let x = calcInitial3ProngCenter(maxCoordinate, δ3s, curvePiece3s);
79
79
 
80
80
  let tolerance = Number.POSITIVE_INFINITY;
81
81
  while (tolerance > TOLERANCE && j < MAX_ITERATIONS) {
82
82
  j++;
83
83
 
84
- poss = getClosestPoints(x, bezierPiece3s);
84
+ poss = getClosestPoints(x, curvePiece3s);
85
85
  if (!Number.isFinite(x[0]) || !Number.isFinite(x[1])) {
86
86
 
87
87
  // TODO - the code can be cleaned up and sped up a lot if we don't
@@ -103,7 +103,7 @@ function find3ProngForDelta3s(
103
103
  // loop. This check, for instance, would be eliminated completely.
104
104
  return undefined;
105
105
  }
106
- const upds = calcBetterX(bezierPiece3s, x, vectorToZeroV);
106
+ const upds = calcBetterX(curvePiece3s, x, vectorToZeroV);
107
107
  x = upds.newX;
108
108
  poss = upds.newPoss;
109
109
 
@@ -164,7 +164,7 @@ function find3ProngForDelta3s(
164
164
  const cross_ = Math.abs( Math.asin( cross(v1, v2) ) );
165
165
 
166
166
  totalAngleError += cross_;
167
- }
167
+ }
168
168
  }
169
169
 
170
170
  //-------------------------------------------------------------------------
@@ -173,10 +173,10 @@ function find3ProngForDelta3s(
173
173
  // candidate for the 3-prong.
174
174
  //-------------------------------------------------------------------------
175
175
  const closestDs = [];
176
- for (let i=0; i<bezierPiecess.length; i++) {
176
+ for (let i=0; i<curvePiecess.length; i++) {
177
177
  const p = getCloseBoundaryPointsCertified(
178
178
  5, // TODO - see find-2-prong
179
- bezierPiecess[i], x
179
+ curvePiecess[i], x
180
180
  )[0];
181
181
 
182
182
  closestDs.push( distanceBetween(p.p, x) );
@@ -13,35 +13,35 @@ import { getBoundaryPieceBeziers } from '../mat/get-boundary-piece-beziers.js';
13
13
  * tolerances.
14
14
  */
15
15
  function find3Prong(
16
- δs: CpNode[][], extreme: number) {
16
+ δs: CpNode[][], extreme: number) {
17
17
 
18
- const bezierPiecess = δs.map(getBoundaryPieceBeziers);
18
+ const curvePiecess = δs.map(getBoundaryPieceBeziers);
19
19
 
20
- // The best candidate amongst the different 'permutations' of the given δs.
21
- let threeProng: {
20
+ // The best candidate amongst the different 'permutations' of the given δs.
21
+ let threeProng: {
22
22
  circle: Circle,
23
23
  poss: PointOnShape[],
24
24
  δ3s: CpNode[][]
25
25
  };
26
- let smallestError = Number.POSITIVE_INFINITY;
27
- for (let i=1; i<δs.length-1; i++) {
28
- for (let k=0; k<3; k++) {
29
- const threeProngInfo =
30
- find3ProngForDelta3s(δs, i, k, bezierPiecess, extreme);
31
- if (!threeProngInfo) { continue; }
32
-
33
- const { circle, poss: poss, error, δ3s } = threeProngInfo;
34
-
35
- if (error < smallestError) {
36
- smallestError = error;
37
-
38
- threeProng = { circle, poss: poss as PointOnShape[], δ3s };
39
- }
40
- }
41
- }
42
-
43
-
44
- return threeProng!;
26
+ let smallestError = Number.POSITIVE_INFINITY;
27
+ for (let i=1; i<δs.length-1; i++) {
28
+ for (let k=0; k<3; k++) {
29
+ const threeProngInfo =
30
+ find3ProngForDelta3s(δs, i, k, curvePiecess, extreme);
31
+ if (!threeProngInfo) { continue; }
32
+
33
+ const { circle, poss: poss, error, δ3s } = threeProngInfo;
34
+
35
+ if (error < smallestError) {
36
+ smallestError = error;
37
+
38
+ threeProng = { circle, poss: poss as PointOnShape[], δ3s };
39
+ }
40
+ }
41
+ }
42
+
43
+
44
+ return threeProng!;
45
45
  }
46
46
 
47
47
 
@@ -18,43 +18,43 @@ import { getProngCount } from '../cp-node/fs/get-prong-count.js';
18
18
  * tolerances.
19
19
  */
20
20
  function findAndAdd3Prong(
21
- meta: MatMeta,
22
- visitedCps: CpNode[]) {
23
-
24
- const δs: [CpNode, CpNode][] = [];
25
- for (const visitedCp of visitedCps) {
26
- δs.push([visitedCp, visitedCp.next]);
27
- }
28
-
29
- const threeProngInfo = find3Prong(δs, meta.maxCoordinate);
30
-
31
- const { circle, poss, δ3s } = threeProngInfo;
32
-
33
- const orders: number[] = [];
34
- for (let i=0; i<3; i++) {
35
- orders.push(calcPosOrder(circle, poss[i]));
36
- }
37
-
38
- const closeBysFor3Prong: CpNode[] = [];
39
- for (let i=0; i<poss.length; i++) {
40
- const pos = poss[i];
41
- const order = orders[i];
42
- const closeBy = getCloseByCpIfExist(meta, pos, circle, order, 0, 3);
43
- if (closeBy !== undefined) {
44
- const prongCount = getProngCount(closeBy);
45
- if (prongCount <= 2 && !closeBy.isHoleClosing) {
46
- closeBysFor3Prong.push(closeBy);
47
- }
48
- }
49
- }
50
-
51
- const cpNodes = closeBysFor3Prong.length === 0
52
- ? addToCpTree(
53
- true, false, circle, orders, meta, poss, δ3s.map(v => v[0])
54
- ).cpNodes
55
- : [];
56
-
57
- return { closeBysFor3Prong, cpNodes: cpNodes as CpNode[] };
21
+ meta: MatMeta,
22
+ visitedCps: CpNode[]) {
23
+
24
+ const δs: [CpNode, CpNode][] = [];
25
+ for (const visitedCp of visitedCps) {
26
+ δs.push([visitedCp, visitedCp.next]);
27
+ }
28
+
29
+ const threeProngInfo = find3Prong(δs, meta.maxCoordinate);
30
+
31
+ const { circle, poss, δ3s } = threeProngInfo;
32
+
33
+ const orders: number[] = [];
34
+ for (let i=0; i<3; i++) {
35
+ orders.push(calcPosOrder(circle, poss[i]));
36
+ }
37
+
38
+ const closeBysFor3Prong: CpNode[] = [];
39
+ for (let i=0; i<poss.length; i++) {
40
+ const pos = poss[i];
41
+ const order = orders[i];
42
+ const closeBy = getCloseByCpIfExist(meta, pos, circle, order, 0, 3);
43
+ if (closeBy !== undefined) {
44
+ const prongCount = getProngCount(closeBy);
45
+ if (prongCount <= 2 && !closeBy.isHoleClosing) {
46
+ closeBysFor3Prong.push(closeBy);
47
+ }
48
+ }
49
+ }
50
+
51
+ const cpNodes = closeBysFor3Prong.length === 0
52
+ ? addToCpTree(
53
+ true, false, circle, orders, meta, poss, δ3s.map(v => v[0])
54
+ ).cpNodes
55
+ : [];
56
+
57
+ return { closeBysFor3Prong, cpNodes: cpNodes as CpNode[] };
58
58
  }
59
59
 
60
60
 
@@ -25,36 +25,36 @@ let ii = 0;
25
25
  * @internal
26
26
  */
27
27
  function findAndAdd3Prongs(
28
- meta: MatMeta,
29
- cpStart: CpNode) {
30
-
31
- if (isPosSharpCorner(cpStart.cp.pointOnShape)) {
32
- return { closeBysFor3Prong: undefined, addedCpNodes: [] };
33
- }
34
-
35
- const addedCpNodes: CpNode[][] = [];
36
- let closeBysFor3Prong: CpNode[] | undefined = undefined;
37
- do {
38
- if (cpStart === undefined) { continue; }
39
- const visitedCps = traverseCp(cpStart);
40
-
41
- if (visitedCps.length <= 2) { break; }
42
-
43
- const { closeBysFor3Prong, cpNodes } = findAndAdd3Prong(meta, visitedCps);
44
-
45
- addedCpNodes.push(cpNodes);
46
- if (closeBysFor3Prong.length > 0) {
47
- return { closeBysFor3Prong, addedCpNodes };
48
- }
49
-
50
- if (typeof _debug_ !== 'undefined') {
51
- if (++ii === _debug_.directives.stopAfterThreeProngsNum) {
52
- return undefined!;
53
- }
54
- }
55
- } while (true);
56
-
57
- return { closeBysFor3Prong, addedCpNodes };
28
+ meta: MatMeta,
29
+ cpStart: CpNode) {
30
+
31
+ if (isPosSharpCorner(cpStart.cp.pointOnShape)) {
32
+ return { closeBysFor3Prong: undefined, addedCpNodes: [] };
33
+ }
34
+
35
+ const addedCpNodes: CpNode[][] = [];
36
+ let closeBysFor3Prong: CpNode[] | undefined = undefined;
37
+ do {
38
+ if (cpStart === undefined) { continue; }
39
+ const visitedCps = traverseCp(cpStart);
40
+
41
+ if (visitedCps.length <= 2) { break; }
42
+
43
+ const { closeBysFor3Prong, cpNodes } = findAndAdd3Prong(meta, visitedCps);
44
+
45
+ addedCpNodes.push(cpNodes);
46
+ if (closeBysFor3Prong.length > 0) {
47
+ return { closeBysFor3Prong, addedCpNodes };
48
+ }
49
+
50
+ if (typeof _debug_ !== 'undefined') {
51
+ if (++ii === _debug_.directives.stopAfterThreeProngsNum) {
52
+ return undefined!;
53
+ }
54
+ }
55
+ } while (true);
56
+
57
+ return { closeBysFor3Prong, addedCpNodes };
58
58
  }
59
59
 
60
60
 
@@ -5,17 +5,17 @@ import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-c
5
5
  /**
6
6
  * @internal
7
7
  * @param x
8
- * @param bezierPiece3s
8
+ * @param curvePiece3s
9
9
  * @param extreme
10
10
  */
11
11
  function getClosestPoints(
12
12
  x: number[],
13
- bezierPiece3s: CurvePiece[][]) {
13
+ curvePiece3s: CurvePiece[][]) {
14
14
 
15
- return bezierPiece3s.map(bezierPieces => {
15
+ return curvePiece3s.map(curvePieces => {
16
16
  return getCloseBoundaryPointsCertified(
17
17
  5, // TODO - see find-2-prong
18
- bezierPieces, x
18
+ curvePieces, x
19
19
  )[0];
20
20
  });
21
21
  }
@@ -1,18 +1,18 @@
1
- import { drawFs } from "flo-draw";
1
+ // import { drawFs } from "flo-draw";
2
2
  import { closestPointOnBezier } from "flo-bezier3";
3
3
  import { CpNode } from "../cp-node/cp-node.js";
4
4
  import { findAndAdd2Prong } from "../find-2-prong/find-and-add-2-prong.js";
5
5
  import { MatMeta } from "../mat/mat-meta.js";
6
6
  import { getHalfAngle } from "./get-half-angles.js";
7
7
  import { getMatCurveToNext } from "../cp-node/fs/get-mat-curve-to-next.js";
8
- import { getAllOnCircle } from "../cp-node/fs/get-all-on-circle.js";
8
+ // import { getAllOnCircle } from "../cp-node/fs/get-all-on-circle.js";
9
9
  import { isTerminating } from "../cp-node/fs/is-terminating.js";
10
- import { findAndAdd3Prongs } from "../find-3-prong.ts/find-and-add-3-prongs.js";
11
- import { getBoundaryBezierPartsToNext } from "../cp-node/fs/get-boundary-bezier-parts-to-next.js";
12
- import { drawBezierPieces } from "../debug/functions/draw/draw-bezier-pieces.js";
10
+ // import { findAndAdd3Prongs } from "../find-3-prong.ts/find-and-add-3-prongs.js";
11
+ // import { getBoundaryBezierPartsToNext } from "../cp-node/fs/get-boundary-bezier-parts-to-next.js";
12
+ // import { drawBezierPieces } from "../debug/functions/draw/draw-bezier-pieces.js";
13
13
  import { getAllOnLoop } from "../cp-node/fs/get-all-on-loop.js";
14
- import { PointOnShape } from "../point-on-shape/point-on-shape.js";
15
- import { getBoundaryBeziersToNext } from "../cp-node/fs/get-boundary-beziers-to-next.js";
14
+ // import { PointOnShape } from "../point-on-shape/point-on-shape.js";
15
+ // import { getBoundaryBeziersToNext } from "../cp-node/fs/get-boundary-beziers-to-next.js";
16
16
  import { isPosQuiteDullCorner } from "../point-on-shape/is-pos-quite-dull-corner.js";
17
17
  import { MatOptions } from "./mat-options.js";
18
18
 
@@ -62,7 +62,7 @@ function add2rongsByError(
62
62
  if (d > maxError) {
63
63
  maxError = d;
64
64
  }
65
- }
65
+ }
66
66
 
67
67
  if (maxError > 0) {
68
68
  // console.log(maxError);
@@ -33,49 +33,49 @@ import { defaultMatOptions, MatOptions } from './mat-options.js';
33
33
  * in [1,100].
34
34
  */
35
35
  function findMats(
36
- bezierLoops: number[][][][],
37
- options?: MatOptions): Mat[] {
38
-
39
- // if (typeof _debug_ !== 'undefined') { var timingStart = performance.now(); }
40
- const { maxCoordinate, maxRadius } = getLoopsMetrics(bezierLoops);
41
-
42
- const options_: Required<MatOptions> = clipOptions(
43
- maxCoordinate,
44
- maxRadius, {
45
- ...defaultMatOptions,
46
- ...(options || {})
47
- });
48
-
49
- const {
50
- applySat, simplify,
51
- satScale, simplifyTolerance
52
- } = options_;
53
-
54
-
55
- const loopss = simplifyPaths(bezierLoops);
56
- // console.log(loopsToSvgPathStr(bezierLoops));
57
- // const loopss = [bezierLoops.map(loop => loopFromBeziers(loop,0))];
58
- // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => v.map(v => v*2**4))))));
59
- // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => [-v[0],v[1]])))));
60
- // console.log(loopsToSvgPathStr(loopss[0].map(loop => loop.beziers)));
61
-
62
- const mats: Mat[] = [];
63
- for (const loops of loopss) {
64
- let mat = findMat(loops, maxCoordinate, options_);
65
- if (mat === undefined) { continue; }
66
-
67
- if (applySat) {
68
- mat = toScaleAxis(mat, satScale);
69
- }
70
-
71
- if (simplify) {
72
- mat = simplifyMat(mat, simplifyTolerance, 50)
73
- }
74
-
75
- mats.push(mat);
76
- }
77
-
78
- return mats;
36
+ bezierLoops: number[][][][],
37
+ options?: MatOptions): Mat[] {
38
+
39
+ // if (typeof _debug_ !== 'undefined') { var timingStart = performance.now(); }
40
+ const { maxCoordinate, maxRadius } = getLoopsMetrics(bezierLoops);
41
+
42
+ const options_: Required<MatOptions> = clipOptions(
43
+ maxCoordinate,
44
+ maxRadius, {
45
+ ...defaultMatOptions,
46
+ ...(options || {})
47
+ });
48
+
49
+ const {
50
+ applySat, simplify,
51
+ satScale, simplifyTolerance
52
+ } = options_;
53
+
54
+
55
+ const loopss = simplifyPaths(bezierLoops);
56
+ // console.log(loopsToSvgPathStr(bezierLoops));
57
+ // const loopss = [bezierLoops.map(loop => loopFromBeziers(loop,0))];
58
+ // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => v.map(v => v*2**4))))));
59
+ // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => [-v[0],v[1]])))));
60
+ // console.log(loopsToSvgPathStr(loopss[0].map(loop => loop.beziers)));
61
+
62
+ const mats: Mat[] = [];
63
+ for (const loops of loopss) {
64
+ let mat = findMat(loops, maxCoordinate, options_);
65
+ if (mat === undefined) { continue; }
66
+
67
+ if (applySat) {
68
+ mat = toScaleAxis(mat, satScale);
69
+ }
70
+
71
+ if (simplify) {
72
+ mat = simplifyMat(mat, simplifyTolerance, 50)
73
+ }
74
+
75
+ mats.push(mat);
76
+ }
77
+
78
+ return mats;
79
79
  }
80
80
 
81
81
 
@@ -86,14 +86,14 @@ function findMats(
86
86
  * an array of control points.
87
87
  */
88
88
  function loopsToSvgPathStr(
89
- loops: number[][][][]) {
89
+ loops: number[][][][]) {
90
90
 
91
- let str = '';
92
- for (const loop of loops) {
93
- str = str + beziersToSvgPathStr(loop) + '\n';
94
- }
91
+ let str = '';
92
+ for (const loop of loops) {
93
+ str = str + beziersToSvgPathStr(loop) + '\n';
94
+ }
95
95
 
96
- return str;
96
+ return str;
97
97
  }
98
98
 
99
99
 
@@ -59,10 +59,10 @@ function fixOrdering(
59
59
  }
60
60
  }
61
61
  }
62
- }
62
+ }
63
63
  */
64
64
 
65
- // return cpNodes;
65
+ // return cpNodes;
66
66
  }
67
67
 
68
68
 
@@ -9,18 +9,18 @@ import type { Curve } from '../curve/curve.js';
9
9
  * @param totalByF
10
10
  */
11
11
  function getTotalBy(totalByF: (curve: Curve) => number) {
12
-
13
- return function(loop: Loop) {
14
- let node = loop.curves[0];
15
- let total = 0;
16
- do {
17
- total += totalByF(node);
18
-
19
- node = node.next;
20
- } while (node !== loop.curves[0]);
21
-
22
- return total;
23
- }
12
+
13
+ return function(loop: Loop) {
14
+ let node = loop.curves[0];
15
+ let total = 0;
16
+ do {
17
+ total += totalByF(node);
18
+
19
+ node = node.next;
20
+ } while (node !== loop.curves[0]);
21
+
22
+ return total;
23
+ }
24
24
  }
25
25
 
26
26
 
@@ -7,45 +7,45 @@ const squaredDistanceBetween = squaredDistanceBetween_;
7
7
  * @internal
8
8
  */
9
9
  function getClosestSquareDistanceToRect(
10
- box: number[][], p: number[]): number {
10
+ box: number[][], p: number[]): number {
11
11
 
12
- const p0 = box[0];
13
- const p1 = box[1];
14
- const x0 = p0[0];
15
- const y0 = p0[1];
16
- const x1 = p1[0];
17
- const y1 = p1[1];
18
- const xp = p[0];
19
- const yp = p[1];
12
+ const p0 = box[0];
13
+ const p1 = box[1];
14
+ const x0 = p0[0];
15
+ const y0 = p0[1];
16
+ const x1 = p1[0];
17
+ const y1 = p1[1];
18
+ const xp = p[0];
19
+ const yp = p[1];
20
20
 
21
- //let [[x0,y0],[x1,y1]] = box;
22
- //let [xp,yp] = p;
23
-
24
- if (xp < x0) {
25
- if (yp < y0) {
26
- return squaredDistanceBetween(box[0], p);
27
- } else if (yp > y1) {
28
- return squaredDistanceBetween([x0,y1], p);
29
- } else {
30
- return (x0 - xp)**2;
31
- }
32
- } else if (xp > x1) {
33
- if (yp < y0) {
34
- return squaredDistanceBetween([x1,y0], p);
35
- } else if (yp > y1) {
36
- return squaredDistanceBetween(box[1], p);
37
- } else {
38
- return (xp - x1)**2;
39
- }
40
- } else {
41
- if (yp < y0) {
42
- return (y0 - yp)**2;
43
- } else if (yp > y1) {
44
- return (yp - y1)**2;
45
- }
46
-
47
- return 0;
48
- }
21
+ //let [[x0,y0],[x1,y1]] = box;
22
+ //let [xp,yp] = p;
23
+
24
+ if (xp < x0) {
25
+ if (yp < y0) {
26
+ return squaredDistanceBetween(box[0], p);
27
+ } else if (yp > y1) {
28
+ return squaredDistanceBetween([x0,y1], p);
29
+ } else {
30
+ return (x0 - xp)**2;
31
+ }
32
+ } else if (xp > x1) {
33
+ if (yp < y0) {
34
+ return squaredDistanceBetween([x1,y0], p);
35
+ } else if (yp > y1) {
36
+ return squaredDistanceBetween(box[1], p);
37
+ } else {
38
+ return (xp - x1)**2;
39
+ }
40
+ } else {
41
+ if (yp < y0) {
42
+ return (y0 - yp)**2;
43
+ } else if (yp > y1) {
44
+ return (yp - y1)**2;
45
+ }
46
+
47
+ return 0;
48
+ }
49
49
  }
50
50
 
51
51
 
@@ -1,5 +1,5 @@
1
1
  import {
2
- squaredDistanceBetweenPointAndLineSegment, squaredDistanceBetween
2
+ squaredDistanceBetweenPointAndLineSegment, squaredDistanceBetween
3
3
  } from 'flo-vector2d';
4
4
 
5
5
 
@@ -7,22 +7,22 @@ import {
7
7
  * @internal
8
8
  */
9
9
  function getClosestSquaredDistanceToRotatedRect(ps: number[][], p: number[]) {
10
- const ds = [0,1,2,3].map(i => squaredDistanceBetweenPointAndLineSegment(
11
- p,
12
- [ps[i], ps[(i + 1) % 4]]
13
- )
14
- );
15
-
16
- const width = squaredDistanceBetween(ps[0], ps[1]);
17
- const height = squaredDistanceBetween(ps[0], ps[3]);
10
+ const ds = [0,1,2,3].map(i => squaredDistanceBetweenPointAndLineSegment(
11
+ p,
12
+ [ps[i], ps[(i + 1) % 4]]
13
+ )
14
+ );
15
+
16
+ const width = squaredDistanceBetween(ps[0], ps[1]);
17
+ const height = squaredDistanceBetween(ps[0], ps[3]);
18
18
 
19
- if (ds[0] <= height && ds[2] <= height &&
20
- ds[1] <= width && ds[3] <= width) {
19
+ if (ds[0] <= height && ds[2] <= height &&
20
+ ds[1] <= width && ds[3] <= width) {
21
21
 
22
- return 0; // Inside rotated rect
23
- }
22
+ return 0; // Inside rotated rect
23
+ }
24
24
 
25
- return Math.min(...ds);
25
+ return Math.min(...ds);
26
26
  }
27
27
 
28
28
 
@@ -39,7 +39,7 @@ function getCurveBetween(
39
39
  const a = fromTo(fromCc, mid);
40
40
  const b = fromTo(toCc, mid);
41
41
 
42
- twisted = dot(a,c) < 0 || dot(b,c) > 0;
42
+ twisted = dot(a,c) < 0 || dot(b,c) > 0;
43
43
  }
44
44
 
45
45
  if (!twisted) {