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
@@ -8,14 +8,14 @@ import { Circle } from '../geometry/circle.js';
8
8
  * calculated.
9
9
  */
10
10
  interface ContactPoint {
11
- /** Identifies the point on the shape boundary. */
12
- pointOnShape: PointOnShape;
13
- /** The maximal disk circle touching this point. */
14
- circle: Circle;
15
- /** Internally used to order two points lying at the same planar point. */
16
- order: number;
17
- /** Internally used to order two points lying at the same planar point. */
18
- order2: number;
11
+ /** Identifies the point on the shape boundary. */
12
+ pointOnShape: PointOnShape;
13
+ /** The maximal disk circle touching this point. */
14
+ circle: Circle;
15
+ /** Internally used to order two points lying at the same planar point. */
16
+ order: number;
17
+ /** Internally used to order two points lying at the same planar point. */
18
+ order2: number;
19
19
  }
20
20
 
21
21
 
@@ -28,14 +28,14 @@ interface ContactPoint {
28
28
  * @param b The second contact point.
29
29
  */
30
30
  function compareCps(a: ContactPoint, b: ContactPoint) {
31
- let res = comparePoss(a.pointOnShape, b.pointOnShape);
31
+ let res = comparePoss(a.pointOnShape, b.pointOnShape);
32
32
 
33
- if (res !== 0) { return res; }
33
+ if (res !== 0) { return res; }
34
34
 
35
- res = a.order - b.order;
36
- if (res !== 0) { return res; }
35
+ res = a.order - b.order;
36
+ if (res !== 0) { return res; }
37
37
 
38
- return a.order2 - b.order2;
38
+ return a.order2 - b.order2;
39
39
  }
40
40
 
41
41
 
@@ -8,11 +8,11 @@ import { getInterfaceCcw } from './get-interface-ccw.js';
8
8
  * Angle in degrees to radians.
9
9
  */
10
10
  const DEGREES = {
11
- //'0' : 0.0000,
12
- 0.25 : 0.0050,
13
- 1 : 0.0167,
14
- 4 : 0.0698,
15
- 16 : 0.2756,
11
+ //'0' : 0.0000,
12
+ 0.25 : 0.0050,
13
+ 1 : 0.0167,
14
+ 4 : 0.0698,
15
+ 16 : 0.2756,
16
16
  };
17
17
 
18
18
 
@@ -35,45 +35,45 @@ const DEGREE_LIMIT = DEGREES[4];
35
35
  * @param psO The outgoing bezier that starts at the corner
36
36
  */
37
37
  function getCorner(
38
- psI: number[][],
39
- psO: number[][]): Corner {
38
+ psI: number[][],
39
+ psO: number[][]): Corner {
40
40
 
41
- // getInterfaceCcw must return a number !== 0 if psI and psO are not the
42
- // same as seen as a curve extension with t ∈ [-∞,+∞]
43
- const { ccw, tangentI, tangentO, dotTangents } = getInterfaceCcw(psI, psO);
44
- const isSharp = ccw < 0;
45
- const isDull = ccw > 0;
41
+ // getInterfaceCcw must return a number !== 0 if psI and psO are not the
42
+ // same as seen as a curve extension with t ∈ [-∞,+∞]
43
+ const { ccw, tangentI, tangentO, dotTangents } = getInterfaceCcw(psI, psO);
44
+ const isSharp = ccw < 0;
45
+ const isDull = ccw > 0;
46
46
 
47
- // These use square root and are thus not exact
48
- const unitTangents = [
49
- toUnitVector(tangentI.map(v => v[1])),
50
- toUnitVector(tangentO.map(v => v[1])),
51
- ];
47
+ // These use square root and are thus not exact
48
+ const unitTangents = [
49
+ toUnitVector(tangentI.map(v => v[1])),
50
+ toUnitVector(tangentO.map(v => v[1])),
51
+ ];
52
52
 
53
- // The cross calculated below should be exact due to beziers having been
54
- // normalized!
55
- const crossTangents = cross(unitTangents[0], unitTangents[1]);
53
+ // The cross calculated below should be exact due to beziers having been
54
+ // normalized!
55
+ const crossTangents = cross(unitTangents[0], unitTangents[1]);
56
56
 
57
- let isQuiteSharp: boolean;
58
- let isQuiteDull: boolean;
59
- // const dotTangents = dot(tangentAtIncoming, tangentAtOutgoing);
60
- if (dotTangents > 0) {
61
- // Curves go in same direction
62
- isQuiteSharp = crossTangents < -DEGREE_LIMIT;
63
- isQuiteDull = crossTangents > +DEGREE_LIMIT;
64
- } else {
65
- isQuiteSharp = isSharp;
66
- isQuiteDull = isDull;
67
- }
57
+ let isQuiteSharp: boolean;
58
+ let isQuiteDull: boolean;
59
+ // const dotTangents = dot(tangentAtIncoming, tangentAtOutgoing);
60
+ if (dotTangents > 0) {
61
+ // Curves go in same direction
62
+ isQuiteSharp = crossTangents < -DEGREE_LIMIT;
63
+ isQuiteDull = crossTangents > +DEGREE_LIMIT;
64
+ } else {
65
+ isQuiteSharp = isSharp;
66
+ isQuiteDull = isDull;
67
+ }
68
68
 
69
- return {
70
- tangents: unitTangents,
71
- // crossTangents,
72
- isSharp,
73
- isDull,
74
- isQuiteSharp,
75
- isQuiteDull
76
- };
69
+ return {
70
+ tangents: unitTangents,
71
+ // crossTangents,
72
+ isSharp,
73
+ isDull,
74
+ isQuiteSharp,
75
+ isQuiteDull
76
+ };
77
77
  }
78
78
 
79
79
 
@@ -48,8 +48,8 @@ function getInterfaceCcw(
48
48
  const crossTangents = crossPrecise(p0,p1,p2); // sign will be correct
49
49
 
50
50
  const xI = twoDiff(p1[0],p0[0]); // tangent x-coordinate
51
- const yI = twoDiff(p1[1],p0[1]); // tangent y-coordinate
52
- const xO = twoDiff(p2[0],p1[0]); // tangent x-coordinate
51
+ const yI = twoDiff(p1[1],p0[1]); // tangent y-coordinate
52
+ const xO = twoDiff(p2[0],p1[0]); // tangent x-coordinate
53
53
  const yO = twoDiff(p2[1],p1[1]); // tangent y-coordinate
54
54
 
55
55
  const tangentI = [xI,yI];
@@ -57,7 +57,7 @@ function getInterfaceCcw(
57
57
  const dotTangents = dotPrecise(tangentI,tangentO);
58
58
 
59
59
  if (crossTangents !== 0 || dotTangents > 0) {
60
- return {
60
+ return {
61
61
  ccw: crossTangents,
62
62
  tangentI,
63
63
  tangentO,
@@ -1,4 +1,3 @@
1
- import { compareCps } from "../contact-point/contact-point.js";
2
1
  import { CpNode } from "./cp-node.js";
3
2
  import { getHoleClosers } from "./fs/get-hole-closers.js";
4
3
  import { getSpeed } from "./fs/get-speed.js";
@@ -34,111 +33,109 @@ import { getBoundaryBeziersBetween } from './fs/get-boundary-beziers-between.js'
34
33
  import { getMatCurvesBetween } from './fs/get-mat-curves-between.js';
35
34
  import { getInitialDegAngleBetweenMatCurves } from "./fs/get-angle-between-mat-curves.js";
36
35
  import { getAllVertices } from "./fs/get-all-vertices.js";
37
-
38
-
39
- const cpNodeComparator = (a: CpNode, b: CpNode) => compareCps(a.cp, b.cp);
36
+ import { cpNodeComparator } from './fs/cp-node-comparator.js';
40
37
 
41
38
 
42
39
  const CpNodeFs = {
43
- /**
44
- * Returns the children of this `CpNode` when seen as a MAT edge. Only
45
- * children in a 'forward' direction are returned. These include all edges
46
- * except the 'backward' edge given by `prevOnCircle`, even terminating
47
- * edges.
48
- */
49
- getChildren,
50
- /**
51
- * Similar to `getChildren` but returns the child nodes of the tree when
52
- * `CpNode` is seen as a MAT vertex point (as opposed to edge). In this
53
- * way the dual graph of the tree can easily be traversed - see e.g.
54
- * `traverseVertices`. Generally, however, traversing the edges is
55
- * preferred as it returns the entire Medial Axis (by utilizing
56
- * `getMatCurveToNext` on each returned edge).
57
- */
58
- getVertexForwardChildren,
59
- /**
60
- * Returns all `CpNode`s on the MAT that this `CpNode` is part of
61
- * starting from the current one and going anti-clockwise around the shape.
62
- */
63
- getAllOnLoop,
64
- /**
65
- * Return this (except if exclThis is truthy) and the the other CpNodes
66
- * around the maximal disk vertex circle in an anti-clockwise order.
67
- * @param exclThis If true the returned array does not include this
68
- * `CpNode`.
69
- */
70
- getAllOnCircle,
71
- /**
72
- * Returns true if the 2 given `CpNode`s are on the same maximal disk
73
- * circle.
74
- * @param cpNode1 A `CpNode`.
75
- * @param cpNode2 Another `CpNode`
76
- */
77
- isOnSameCircle,
78
- /**
79
- * Returns true if this `CpNode` is terminating, i.e. implies a leaf MAT
80
- * vertex.
81
- *
82
- * This is always the case for sharp corners and maximal disks with
83
- * a single contact point. Note, however, that even in these cases there are
84
- * two contact points stored (sitting 'on top' of each other) for the
85
- * maximal disk. It can be seen as a limiting case of a two-prong where the
86
- * distance between two of the contact points tend to zero. One point
87
- * (represented by a `CpNode` of course) will be terminating with the
88
- * other point being its `next`, whereas the other point will *not* be
89
- * terminating and 'points' back into the shape.
90
- */
91
- isTerminating,
92
- /**
93
- * Like isTerminating() but only returns true if all cpNodes on the circle
94
- * (except this.prevOnCircle) is terminating.
95
- */
96
- isFullyTerminating,
97
- /**
98
- * Returns the first `CpNode` (from this one by successively applying
99
- * .nextOnCircle) that exits the circle.
100
- */
101
- getFirstExit,
102
- /**
103
- * Returns true if this `CpNode` represents a sharp corner, i.e. the
104
- * limiting case of a two-prong having zero radius.
105
- *
106
- * Note that two `CpNode`s are stored for each sharp corner, one being
107
- * terminating and one not. See `isTerminating` for more details.
108
- */
109
- isSharp,
110
- /**
111
- * Returns true if this `CpNode`'s maximal disk has only one contact point
112
- * on the shape boundary (up to planar coordinates). These includes sharp
113
- * corners.
114
- *
115
- * Note, however, that two `CpNode`s are stored for each such point to
116
- * preserve symmetry - see `isTerminating` for more details.
117
- */
118
- isOneProng,
119
- /**
120
- * Returns the number of contact points on the maximal disk circle implied
121
- * by this `CpNode`.
122
- *
123
- * Note, however, that even one-prongs and sharp corners will return 2 (see
124
- * `isTerminating` for more details); if this is not desired use
125
- * `getRealProngCount` instead which will return 1 in these cases.
126
- */
127
- getProngCount,
128
- /**
129
- * Returns the number of contact points (up to planar coordinates) on the
130
- * maximal disk circle implied by this `CpNode`.
131
- *
132
- * See also `getProngCount`.
133
- */
134
- getRealProngCount,
135
- /**
136
- * Primarily for internal use.
137
- *
138
- * Compares the order of two `CpNode`s. The order is cyclic and depends
139
- * on a `CpNode`'s relative position along the shape boundary.
140
- */
141
- cpNodeComparator,
40
+ /**
41
+ * Returns the children of this `CpNode` when seen as a MAT edge. Only
42
+ * children in a 'forward' direction are returned. These include all edges
43
+ * except the 'backward' edge given by `prevOnCircle`, even terminating
44
+ * edges.
45
+ */
46
+ getChildren,
47
+ /**
48
+ * Similar to `getChildren` but returns the child nodes of the tree when
49
+ * `CpNode` is seen as a MAT vertex point (as opposed to edge). In this
50
+ * way the dual graph of the tree can easily be traversed - see e.g.
51
+ * `traverseVertices`. Generally, however, traversing the edges is
52
+ * preferred as it returns the entire Medial Axis (by utilizing
53
+ * `getMatCurveToNext` on each returned edge).
54
+ */
55
+ getVertexForwardChildren,
56
+ /**
57
+ * Returns all `CpNode`s on the MAT that this `CpNode` is part of
58
+ * starting from the current one and going anti-clockwise around the shape.
59
+ */
60
+ getAllOnLoop,
61
+ /**
62
+ * Return this (except if exclThis is truthy) and the the other CpNodes
63
+ * around the maximal disk vertex circle in an anti-clockwise order.
64
+ * @param exclThis If true the returned array does not include this
65
+ * `CpNode`.
66
+ */
67
+ getAllOnCircle,
68
+ /**
69
+ * Returns true if the 2 given `CpNode`s are on the same maximal disk
70
+ * circle.
71
+ * @param cpNode1 A `CpNode`.
72
+ * @param cpNode2 Another `CpNode`
73
+ */
74
+ isOnSameCircle,
75
+ /**
76
+ * Returns true if this `CpNode` is terminating, i.e. implies a leaf MAT
77
+ * vertex.
78
+ *
79
+ * This is always the case for sharp corners and maximal disks with
80
+ * a single contact point. Note, however, that even in these cases there are
81
+ * two contact points stored (sitting 'on top' of each other) for the
82
+ * maximal disk. It can be seen as a limiting case of a two-prong where the
83
+ * distance between two of the contact points tend to zero. One point
84
+ * (represented by a `CpNode` of course) will be terminating with the
85
+ * other point being its `next`, whereas the other point will *not* be
86
+ * terminating and 'points' back into the shape.
87
+ */
88
+ isTerminating,
89
+ /**
90
+ * Like isTerminating() but only returns true if all cpNodes on the circle
91
+ * (except this.prevOnCircle) is terminating.
92
+ */
93
+ isFullyTerminating,
94
+ /**
95
+ * Returns the first `CpNode` (from this one by successively applying
96
+ * .nextOnCircle) that exits the circle.
97
+ */
98
+ getFirstExit,
99
+ /**
100
+ * Returns true if this `CpNode` represents a sharp corner, i.e. the
101
+ * limiting case of a two-prong having zero radius.
102
+ *
103
+ * Note that two `CpNode`s are stored for each sharp corner, one being
104
+ * terminating and one not. See `isTerminating` for more details.
105
+ */
106
+ isSharp,
107
+ /**
108
+ * Returns true if this `CpNode`'s maximal disk has only one contact point
109
+ * on the shape boundary (up to planar coordinates). These includes sharp
110
+ * corners.
111
+ *
112
+ * Note, however, that two `CpNode`s are stored for each such point to
113
+ * preserve symmetry - see `isTerminating` for more details.
114
+ */
115
+ isOneProng,
116
+ /**
117
+ * Returns the number of contact points on the maximal disk circle implied
118
+ * by this `CpNode`.
119
+ *
120
+ * Note, however, that even one-prongs and sharp corners will return 2 (see
121
+ * `isTerminating` for more details); if this is not desired use
122
+ * `getRealProngCount` instead which will return 1 in these cases.
123
+ */
124
+ getProngCount,
125
+ /**
126
+ * Returns the number of contact points (up to planar coordinates) on the
127
+ * maximal disk circle implied by this `CpNode`.
128
+ *
129
+ * See also `getProngCount`.
130
+ */
131
+ getRealProngCount,
132
+ /**
133
+ * Primarily for internal use.
134
+ *
135
+ * Compares the order of two `CpNode`s. The order is cyclic and depends
136
+ * on a `CpNode`'s relative position along the shape boundary.
137
+ */
138
+ cpNodeComparator,
142
139
  /**
143
140
  * For debugging
144
141
  * @param cpNode
@@ -196,38 +193,38 @@ const CpNodeFs = {
196
193
  * @param cpNode The `CpNode` to remove.
197
194
  */
198
195
  removeVertex,
199
- /**
200
- * Returns the bezier curve from the maximal disk of the given `CpNode` to the
201
- * next `CpNode`'s maximal disk and thus directly represents a piece of the
202
- * medial axis.
203
- * @param cpNode
204
- */
205
- getMatCurveToNext,
206
- isTwoProng,
207
- getBranch,
208
- getBranchBeziers,
209
- getSalience,
210
- /**
211
- * Returns the bezier curve from the maximal disk of one `CpNode` to another
212
- * `CpNode`'s maximal disk.
213
- * @param cpNodeFrom
214
- * @param cpNodeTo
215
- */
216
- getMatCurveBetween,
217
- /**
218
- * @internal
219
- * Returns a line segment of unit length starting in the given Vertex center and
220
- * pointing in the direction of the medial axis (viewed as a rooted tree).
221
- * @param cpNode
222
- */
223
- getEdgeDirection,
224
- getBoundaryBeziersBetween,
225
- getMatCurvesBetween,
226
- getHoleClosers,
227
- getSpeed,
228
- getSmoothedSpeed$,
229
- getInitialDegAngleBetweenMatCurves,
230
- getAllVertices
196
+ /**
197
+ * Returns the bezier curve from the maximal disk of the given `CpNode` to the
198
+ * next `CpNode`'s maximal disk and thus directly represents a piece of the
199
+ * medial axis.
200
+ * @param cpNode
201
+ */
202
+ getMatCurveToNext,
203
+ isTwoProng,
204
+ getBranch,
205
+ getBranchBeziers,
206
+ getSalience,
207
+ /**
208
+ * Returns the bezier curve from the maximal disk of one `CpNode` to another
209
+ * `CpNode`'s maximal disk.
210
+ * @param cpNodeFrom
211
+ * @param cpNodeTo
212
+ */
213
+ getMatCurveBetween,
214
+ /**
215
+ * @internal
216
+ * Returns a line segment of unit length starting in the given Vertex center and
217
+ * pointing in the direction of the medial axis (viewed as a rooted tree).
218
+ * @param cpNode
219
+ */
220
+ getEdgeDirection,
221
+ getBoundaryBeziersBetween,
222
+ getMatCurvesBetween,
223
+ getHoleClosers,
224
+ getSpeed,
225
+ getSmoothedSpeed$,
226
+ getInitialDegAngleBetweenMatCurves,
227
+ getAllVertices
231
228
  }
232
229
 
233
230
 
@@ -50,37 +50,37 @@ import { ContactPoint } from '../contact-point/contact-point.js';
50
50
  * in opposite directions.
51
51
  */
52
52
  interface CpNode {
53
- /** The shape boundary contact point, i.e. a `CpNode` without its edges. */
54
- cp: ContactPoint;
55
- /** If true, this `CpNode` belongs to a hole-closing maximal disk. */
56
- isHoleClosing: boolean;
57
- /** true if this cpNode is at a shape boundary intersection point, false otherwise */
58
- isIntersection: boolean;
59
- /** The previous (going clockwise around the boundary) contact point (`CpNode`).*/
60
- prev: CpNode;
61
- /** The next (going anti-clockwise around the boundary) contact point (`CpNode`). */
62
- next: CpNode;
63
- /**
64
- * The previous `CpNode` (going clockwise around the inscribed circle
65
- * defined by the maximal disk).
66
- */
67
- prevOnCircle: CpNode;
68
- /**
69
- * The next `CpNode` (going anti-clockwise around
70
- * the inscribed circle defined by the maximal disk).
71
- */
72
- nextOnCircle: CpNode;
73
- /**
74
- * For hole closers only - the next `CpNode` ignoring the hole closer
75
- */
76
- holeCloserNext?: CpNode | undefined;
77
- /**
78
- * For hole closers only - the prev `CpNode` ignoring the hole closer
79
- */
80
- holeCloserPrev?: CpNode | undefined;
53
+ /** The shape boundary contact point, i.e. a `CpNode` without its edges. */
54
+ cp: ContactPoint;
55
+ /** If true, this `CpNode` belongs to a hole-closing maximal disk. */
56
+ isHoleClosing: boolean;
57
+ /** true if this cpNode is at a shape boundary intersection point, false otherwise */
58
+ isIntersection: boolean;
59
+ /** The previous (going clockwise around the boundary) contact point (`CpNode`).*/
60
+ prev: CpNode;
61
+ /** The next (going anti-clockwise around the boundary) contact point (`CpNode`). */
62
+ next: CpNode;
63
+ /**
64
+ * The previous `CpNode` (going clockwise around the inscribed circle
65
+ * defined by the maximal disk).
66
+ */
67
+ prevOnCircle: CpNode;
68
+ /**
69
+ * The next `CpNode` (going anti-clockwise around
70
+ * the inscribed circle defined by the maximal disk).
71
+ */
72
+ nextOnCircle: CpNode;
73
+ /**
74
+ * For hole closers only - the next `CpNode` ignoring the hole closer
75
+ */
76
+ holeCloserNext?: CpNode | undefined;
77
+ /**
78
+ * For hole closers only - the prev `CpNode` ignoring the hole closer
79
+ */
80
+ holeCloserPrev?: CpNode | undefined;
81
81
 
82
- /** Only used in export */
83
- id: number;
82
+ /** Only used in export */
83
+ id: number;
84
84
  }
85
85
 
86
86
 
@@ -4,9 +4,9 @@ import { CpNode } from "../cp-node.js";
4
4
  /** @internal */
5
5
  type Edge =
6
6
  | 'prev'
7
- | 'next'
8
- | 'prevOnCircle'
9
- | 'nextOnCircle';
7
+ | 'next'
8
+ | 'prevOnCircle'
9
+ | 'nextOnCircle';
10
10
 
11
11
  /** @internal */
12
12
  const EDGES: Edge[] = ['prev', 'next', 'prevOnCircle', 'nextOnCircle'];
@@ -38,7 +38,7 @@ function clone(cpNode: CpNode): CpNode {
38
38
  for (const edge of EDGES) {
39
39
  const node = cpNode[edge];
40
40
  let newNode = nodeMap.get(node);
41
- if (!newNode) {
41
+ if (!newNode) {
42
42
  newNode = cloneWithoutLinks(node);
43
43
 
44
44
  nodeMap.set(node, newNode);
@@ -0,0 +1,13 @@
1
+ import type { CpNode } from "../cp-node.js";
2
+ import { compareCps } from "../../contact-point/contact-point.js";
3
+
4
+
5
+ function cpNodeComparator(
6
+ a: CpNode,
7
+ b: CpNode) {
8
+
9
+ return compareCps(a.cp, b.cp);
10
+ }
11
+
12
+
13
+ export { cpNodeComparator }
@@ -10,15 +10,15 @@ function findFirst(
10
10
 
11
11
  if (f(cpStart)) { return cpStart; }
12
12
 
13
- let cpNode_ = cpNode.next;
14
- while (cpNode_ !== cpStart) {
15
- if (f(cpNode_)) {
13
+ let cpNode_ = cpNode.next;
14
+ while (cpNode_ !== cpStart) {
15
+ if (f(cpNode_)) {
16
16
  return cpNode_;
17
17
  }
18
- cpNode_ = cpNode_.next;
19
- }
18
+ cpNode_ = cpNode_.next;
19
+ }
20
20
 
21
- return undefined;
21
+ return undefined;
22
22
  }
23
23
 
24
24
 
@@ -2,7 +2,7 @@ import type { CpNode } from "../cp-node.js";
2
2
 
3
3
 
4
4
  function getAllOnLoop(
5
- cpNode: CpNode) {
5
+ cpNode: CpNode) {
6
6
 
7
7
  const cpStart = cpNode;
8
8
  const cpNodes: CpNode[] = [cpStart];
@@ -13,7 +13,7 @@ import type { Curve } from '../../curve/curve.js';
13
13
  * @param cpNode
14
14
  */
15
15
  function getBoundaryBezierPartsToNext(
16
- cpNode: CpNode): BezierPiece[] | undefined {
16
+ cpNode: CpNode): BezierPiece[] {
17
17
 
18
18
  const cpThis = cpNode;
19
19
  const cpNext = cpNode.next;
@@ -27,27 +27,22 @@ function getBoundaryBezierPartsToNext(
27
27
  if (curveThis.loop !== curveNext.loop) {
28
28
  // It is a hole-closer going over to the other loop - a kind of terminal
29
29
  // CpNode.
30
- return undefined;
30
+ // return undefined;
31
+ return [];
31
32
  }
32
33
 
33
34
  const bezierPieces: BezierPiece[] = [];
34
35
 
35
36
  if (curveNext === curveThis) {
36
37
  bezierPieces.push(
37
- {
38
- ps: posThis.curve.ps,
39
- ts: [posThis.t, posNext.t]
40
- }
38
+ { ps: posThis.curve.ps, ts: [posThis.t, posNext.t] }
41
39
  );
42
40
  } else {
43
41
  bezierPieces.push(
44
- {
45
- ps: posThis.curve.ps,
46
- ts: [posThis.t, 1]
47
- }
42
+ { ps: posThis.curve.ps, ts: [posThis.t, 1] }
48
43
  );
49
44
 
50
- addSkippedBeziers(
45
+ addSkippedBezierPiecess(
51
46
  bezierPieces,
52
47
  posThis.curve,
53
48
  posNext.curve,
@@ -60,10 +55,10 @@ function getBoundaryBezierPartsToNext(
60
55
 
61
56
 
62
57
  /**
63
- * @internal
64
58
  * Adds pieces of skipped beziers.
59
+ * @internal
65
60
  */
66
- function addSkippedBeziers(
61
+ function addSkippedBezierPiecess(
67
62
  bezierPieces: BezierPiece[],
68
63
  curveStart: Curve,
69
64
  curveEnd: Curve,
@@ -72,11 +67,10 @@ function addSkippedBeziers(
72
67
  let curveThis = curveStart;
73
68
  do {
74
69
  curveThis = curveThis.next;
75
- const bezierPart = curveThis === curveEnd
76
- ? { ps: curveThis.ps, ts: [0, t1] }
77
- : { ps: curveThis.ps, ts: [0, 1] }
78
-
79
- bezierPieces.push(bezierPart);
70
+ const tEnd = curveThis === curveEnd ? t1 : 1;
71
+ bezierPieces.push({
72
+ ps: curveThis.ps, ts: [0, tEnd]
73
+ });
80
74
  } while (curveThis !== curveEnd);
81
75
  }
82
76