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
@@ -3,11 +3,11 @@ import { Circle } from '../geometry/circle.js';
3
3
  import { PointOnShape } from '../point-on-shape/point-on-shape.js';
4
4
  import { getOsculatingCircle } from '../point-on-shape/get-osculating-circle.js';
5
5
  import { findEquidistantPointOnLineDd } from './find-equidistant-point-on-line-dd.js';
6
- import { getInitialBezierPieces } from './get-initial-bezier-pieces.js';
6
+ import { getInitialCurvePieces } from './get-initial-bezier-pieces.js';
7
7
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
8
8
  import { reduceRadius } from './reduce-radius.js';
9
9
  import { squaredDistanceBetweenDd } from './squared-distance-between-dd.js';
10
- import { cullBezierPieces2 } from './cull-bezier-pieces.js';
10
+ import { cullCurvePieces2 } from './cull-bezier-pieces.js';
11
11
  import { add1Prong } from './add-1-prong.js';
12
12
  import { createPos } from '../point-on-shape/create-pos.js';
13
13
  import { MatMeta } from '../mat/mat-meta.js';
@@ -41,166 +41,166 @@ const { ceil, log2, max, sqrt, abs, sin, cos } = Math;
41
41
  * @param loopIdx The loop array index
42
42
  */
43
43
  function find2Prong(
44
- meta: MatMeta,
45
- isHoleClosing: boolean,
46
- for1Prong: boolean,
47
- angle: number,
48
- y: PointOnShape): { circle: Circle, zs: PointOnShape[] } | undefined {
49
-
50
- const { loops, maxCoordinate, squaredDiagonalLength } = meta;
51
-
52
- const loop = y.curve.loop;
53
-
54
- const MAX_ITERATIONS = 25;
55
- const minSquaredSeperationTolerance = ((2**-21)*maxCoordinate)**2;
56
- const errorTolerance = (2**-46)*maxCoordinate;
57
- // const errorTolerance = (2**-28)*maxCoordinate;
58
- const maxOsculatingCircleRadius = sqrt(squaredDiagonalLength);
59
- const minCurvature = 1/maxOsculatingCircleRadius;
60
- const oneProngTolerance = (2**-16)*maxCoordinate;
61
-
62
- const [xO,rO] = getO(
63
- angle, isHoleClosing, maxOsculatingCircleRadius, minCurvature, y
64
- );
65
-
66
- const p = y.p;
67
-
68
- // The boundary piece that should contain the other point of
69
- // the 2-prong circle. (Defined by start and end points).
70
- let bezierPieces = getInitialBezierPieces(
71
- angle, isHoleClosing, loop, loops, meta, y, { center: xO, radius: rO }
72
- );
73
- // console.log(bezierPieces.length);
74
-
75
- /** The center of the two-prong (successively refined) */
76
- let x = xO;
77
-
78
- // The lines below is an optimization.
79
- const r_ = sqrt(reduceRadius(maxCoordinate, bezierPieces, p, xO));
80
- if (rO > r_) {
81
- x = interpolate(p, xO, r_/rO);
82
- }
83
-
84
- /** The antipode of the two-prong (successively refined) */
85
- let zs: PointOnShape[] = undefined!;
86
- let z: PointOnShape = undefined!;
87
-
88
- let i = 0;
89
- while (i < MAX_ITERATIONS) {
90
- const xy = squaredDistanceBetweenDd(x, y.p);
91
-
92
- if (i < 2) { bezierPieces = cullBezierPieces2(bezierPieces, x, xy); }
93
- const pow = max(0,ceil(log2(maxCoordinate/xy))) + 1; // determines accuracy
94
- // console.log(pow);
95
- const _zs = getCloseBoundaryPointsCertified(
96
- pow, bezierPieces, x, y.curve, y.t,
97
- for1Prong && i == 0 && rO !== 1/minCurvature,
98
- angle
99
- ).map(info => createPos(info.curve, info.t, false));
100
-
101
- let maxD = Number.NEGATIVE_INFINITY;
102
- let maxPos: PointOnShape = undefined!;
103
- zs = [];
104
- for (const z of _zs) {
105
- if (z === undefined) { continue; }
106
- const _yz = squaredDistanceBetweenDd(y.p, z.p);
107
- if (_yz > maxD) {
108
- maxD = _yz;
109
- maxPos = z;
110
- }
111
- if (_yz !== 0) {
112
- zs.push(z);
113
- }
114
- }
115
- // z = zs[0];
116
- const yz = maxD;
117
- z = maxPos;
118
-
119
- if (z === undefined || yz === 0) {
120
- // addDebugInfo2(isHoleClosing);
121
- return undefined;
122
- }
123
-
124
- const xz = squaredDistanceBetweenDd(x, z.p);
125
-
126
- // if on first try
127
- if (i === 0) {
128
- if (rO < (1 - oneProngTolerance)*sqrt(xz)) {
129
- // console.log('1prong');
130
- add1Prong(meta, rO, xO, y);
131
- return undefined;
132
- }
133
- }
134
-
135
- // if (typeof _debug_ !== 'undefined') { xs.push({ x, y, z: createPos(z.curve, z.t, false), t: y.t }); }
136
-
137
-
138
- if (!isHoleClosing) {
139
- const squaredSeperationTolerance = max(calcSeperationTolerance(
140
- rO, sqrt(xz), 2**2*errorTolerance
141
- ), minSquaredSeperationTolerance);
142
- if (yz <= squaredSeperationTolerance) {
143
- // if (typeof _debug_ !== 'undefined') { console.log(`failed: seperation too small - ${sqrt(yz)}`); }
144
- return undefined;
145
- }
146
- }
147
-
148
- // Find the point on the line connecting y with x that is
149
- // equidistant from y and z. This will be our next x.
150
- const nextX = findEquidistantPointOnLineDd(x, y.p, z.p);
151
- const error = abs(sqrt(xy) - sqrt(xz));
152
- // if (xy < xz) { return undefined; }
153
-
154
- x = nextX;
155
-
156
- if (error < errorTolerance) {
157
- break;
158
- }
159
-
160
- i++;
161
-
162
- if (i === MAX_ITERATIONS) {
163
- // Convergence was too slow.
164
- // if (typeof _debug_ !== 'undefined') { console.log('failed (slow): max iterations reached'); }
165
- return undefined;
166
- }
167
- }
168
-
169
- const circle = { center: x, radius: distanceBetween(x, z.p) };
170
-
171
- // if (typeof _debug_ !== 'undefined') { addDebugInfo(bezierPieces, false, x, y, z, circle!, δ!, xs, isHoleClosing); }
172
-
173
- // return { circle, zs };
174
- // zs = zs.filter(z => z !== undefined)
175
- return { circle, zs: [z] };
44
+ meta: MatMeta,
45
+ isHoleClosing: boolean,
46
+ for1Prong: boolean,
47
+ angle: number,
48
+ y: PointOnShape): { circle: Circle, zs: PointOnShape[] } | undefined {
49
+
50
+ const { loops, maxCoordinate, squaredDiagonalLength } = meta;
51
+
52
+ const loop = y.curve.loop;
53
+
54
+ const MAX_ITERATIONS = 25;
55
+ const minSquaredSeperationTolerance = ((2**-21)*maxCoordinate)**2;
56
+ const errorTolerance = (2**-46)*maxCoordinate;
57
+ // const errorTolerance = (2**-28)*maxCoordinate;
58
+ const maxOsculatingCircleRadius = sqrt(squaredDiagonalLength);
59
+ const minCurvature = 1/maxOsculatingCircleRadius;
60
+ const oneProngTolerance = (2**-16)*maxCoordinate;
61
+
62
+ const [xO,rO] = getO(
63
+ angle, isHoleClosing, maxOsculatingCircleRadius, minCurvature, y
64
+ );
65
+
66
+ const p = y.p;
67
+
68
+ // The boundary piece that should contain the other point of
69
+ // the 2-prong circle. (Defined by start and end points).
70
+ let curvePieces = getInitialCurvePieces(
71
+ angle, isHoleClosing, loop, loops, meta, y, { center: xO, radius: rO }
72
+ );
73
+ // console.log(curvePieces.length);
74
+
75
+ /** The center of the two-prong (successively refined) */
76
+ let x = xO;
77
+
78
+ // The lines below is an optimization.
79
+ const r_ = sqrt(reduceRadius(maxCoordinate, curvePieces, p, xO));
80
+ if (rO > r_) {
81
+ x = interpolate(p, xO, r_/rO);
82
+ }
83
+
84
+ /** The antipode of the two-prong (successively refined) */
85
+ let zs: PointOnShape[] = undefined!;
86
+ let z: PointOnShape = undefined!;
87
+
88
+ let i = 0;
89
+ while (i < MAX_ITERATIONS) {
90
+ const xy = squaredDistanceBetweenDd(x, y.p);
91
+
92
+ if (i < 2) { curvePieces = cullCurvePieces2(curvePieces, x, xy); }
93
+ const pow = max(0,ceil(log2(maxCoordinate/xy))) + 1; // determines accuracy
94
+ // console.log(pow);
95
+ const _zs = getCloseBoundaryPointsCertified(
96
+ pow, curvePieces, x, y.curve, y.t,
97
+ for1Prong && i == 0 && rO !== 1/minCurvature,
98
+ angle
99
+ ).map(info => createPos(info.curve, info.t, false));
100
+
101
+ let maxD = Number.NEGATIVE_INFINITY;
102
+ let maxPos: PointOnShape = undefined!;
103
+ zs = [];
104
+ for (const z of _zs) {
105
+ if (z === undefined) { continue; }
106
+ const _yz = squaredDistanceBetweenDd(y.p, z.p);
107
+ if (_yz > maxD) {
108
+ maxD = _yz;
109
+ maxPos = z;
110
+ }
111
+ if (_yz !== 0) {
112
+ zs.push(z);
113
+ }
114
+ }
115
+ // z = zs[0];
116
+ const yz = maxD;
117
+ z = maxPos;
118
+
119
+ if (z === undefined || yz === 0) {
120
+ // addDebugInfo2(isHoleClosing);
121
+ return undefined;
122
+ }
123
+
124
+ const xz = squaredDistanceBetweenDd(x, z.p);
125
+
126
+ // if on first try
127
+ if (i === 0) {
128
+ if (rO < (1 - oneProngTolerance)*sqrt(xz)) {
129
+ // console.log('1prong');
130
+ add1Prong(meta, rO, xO, y);
131
+ return undefined;
132
+ }
133
+ }
134
+
135
+ // if (typeof _debug_ !== 'undefined') { xs.push({ x, y, z: createPos(z.curve, z.t, false), t: y.t }); }
136
+
137
+
138
+ if (!isHoleClosing) {
139
+ const squaredSeperationTolerance = max(calcSeperationTolerance(
140
+ rO, sqrt(xz), 2**2*errorTolerance
141
+ ), minSquaredSeperationTolerance);
142
+ if (yz <= squaredSeperationTolerance) {
143
+ // if (typeof _debug_ !== 'undefined') { console.log(`failed: seperation too small - ${sqrt(yz)}`); }
144
+ return undefined;
145
+ }
146
+ }
147
+
148
+ // Find the point on the line connecting y with x that is
149
+ // equidistant from y and z. This will be our next x.
150
+ const nextX = findEquidistantPointOnLineDd(x, y.p, z.p);
151
+ const error = abs(sqrt(xy) - sqrt(xz));
152
+ // if (xy < xz) { return undefined; }
153
+
154
+ x = nextX;
155
+
156
+ if (error < errorTolerance) {
157
+ break;
158
+ }
159
+
160
+ i++;
161
+
162
+ if (i === MAX_ITERATIONS) {
163
+ // Convergence was too slow.
164
+ // if (typeof _debug_ !== 'undefined') { console.log('failed (slow): max iterations reached'); }
165
+ return undefined;
166
+ }
167
+ }
168
+
169
+ const circle = { center: x, radius: distanceBetween(x, z.p) };
170
+
171
+ // if (typeof _debug_ !== 'undefined') { addDebugInfo(curvePieces, false, x, y, z, circle!, δ!, xs, isHoleClosing); }
172
+
173
+ // return { circle, zs };
174
+ // zs = zs.filter(z => z !== undefined)
175
+ return { circle, zs: [z] };
176
176
  }
177
177
 
178
178
 
179
179
  function getO(
180
- angle: number,
181
- isHoleClosing: boolean,
182
- maxOsculatingCircleRadius: number,
183
- minCurvature: number,
184
- y: PointOnShape) {
185
-
186
- let xO: number[]; // the original x to mitigate drift
187
- const p = y.p;
188
- let rO: number;
189
- if (isHoleClosing) {
190
- xO = [p[0], p[1] - maxOsculatingCircleRadius];
191
- rO = maxOsculatingCircleRadius;
192
- } else {
193
- if (angle === 0) {
194
- ({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y));
195
- } else {
196
- ({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y, true));
197
- const v = fromTo(y.p, xO);
198
- const v_ = rotate(sin(angle), cos(angle))(v);
199
- xO = translate(y.p)(v_);
200
- }
201
- }
202
-
203
- return [xO,rO] as [number[],number];
180
+ angle: number,
181
+ isHoleClosing: boolean,
182
+ maxOsculatingCircleRadius: number,
183
+ minCurvature: number,
184
+ y: PointOnShape) {
185
+
186
+ let xO: number[]; // the original x to mitigate drift
187
+ const p = y.p;
188
+ let rO: number;
189
+ if (isHoleClosing) {
190
+ xO = [p[0], p[1] - maxOsculatingCircleRadius];
191
+ rO = maxOsculatingCircleRadius;
192
+ } else {
193
+ if (angle === 0) {
194
+ ({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y));
195
+ } else {
196
+ ({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y, true));
197
+ const v = fromTo(y.p, xO);
198
+ const v_ = rotate(sin(angle), cos(angle))(v);
199
+ xO = translate(y.p)(v_);
200
+ }
201
+ }
202
+
203
+ return [xO,rO] as [number[],number];
204
204
  }
205
205
 
206
206
 
@@ -1,6 +1,6 @@
1
1
  import {
2
- twoDiff, twoSum, twoProduct, doubleDivDouble, ddDivDd,
3
- ddAddDd, ddDiffDd, ddMultDd, ddMultBy2, ddMultDouble1
2
+ twoDiff, twoSum, twoProduct, doubleDivDouble, ddDivDd,
3
+ ddAddDd, ddDiffDd, ddMultDd, ddMultBy2, ddMultDouble1
4
4
  } from "double-double";
5
5
 
6
6
 
@@ -20,57 +20,57 @@ const tp = twoProduct;
20
20
  * @param z
21
21
  */
22
22
  function findEquidistantPointOnLineDd(
23
- x: number[],
24
- y: number[],
25
- z: number[]) {
26
- // Some basic algebra (not shown) finds the required point.
27
-
28
- // Swap axes if x and y are more aligned to y-axis than to x-axis.
29
- const swapAxes = abs(x[1] - y[1]) > abs(x[0] - y[0]);
30
-
31
- // Cache
32
- let x1: number;
33
- let x2: number;
34
- let y1: number;
35
- let y2: number;
36
- let z1: number;
37
- let z2: number;
38
-
39
- if (swapAxes) {
40
- x1 = x[1]; x2 = x[0];
41
- y1 = y[1]; y2 = y[0];
42
- z1 = z[1]; z2 = z[0];
43
- } else {
44
- x1 = x[0]; x2 = x[1];
45
- y1 = y[0]; y2 = y[1];
46
- z1 = z[0]; z2 = z[1];
47
- }
48
-
49
- // a <= 1 (due to swapped axes)
50
- // const a = (x2 - y2) / (x1 - y1);
51
- // const b = y2 - a*y1;
52
- // const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
53
- // const d = y1 - z1 + a*(y2 - z2);
54
- // const t1 = c/(2*d);
55
- // const t2 = a*t1 + b;
23
+ x: number[],
24
+ y: number[],
25
+ z: number[]) {
26
+ // Some basic algebra (not shown) finds the required point.
27
+
28
+ // Swap axes if x and y are more aligned to y-axis than to x-axis.
29
+ const swapAxes = abs(x[1] - y[1]) > abs(x[0] - y[0]);
30
+
31
+ // Cache
32
+ let x1: number;
33
+ let x2: number;
34
+ let y1: number;
35
+ let y2: number;
36
+ let z1: number;
37
+ let z2: number;
38
+
39
+ if (swapAxes) {
40
+ x1 = x[1]; x2 = x[0];
41
+ y1 = y[1]; y2 = y[0];
42
+ z1 = z[1]; z2 = z[0];
43
+ } else {
44
+ x1 = x[0]; x2 = x[1];
45
+ y1 = y[0]; y2 = y[1];
46
+ z1 = z[0]; z2 = z[1];
47
+ }
48
+
49
+ // a <= 1 (due to swapped axes)
50
+ // const a = (x2 - y2) / (x1 - y1);
51
+ // const b = y2 - a*y1;
52
+ // const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
53
+ // const d = y1 - z1 + a*(y2 - z2);
54
+ // const t1 = c/(2*d);
55
+ // const t2 = a*t1 + b;
56
56
 
57
-
58
- const a = ddDivDd(td(x2,y2),td(x1,y1));
59
- const b = ddDiffDd([0,y2], ddMultDouble1(y1,a));
57
+
58
+ const a = ddDivDd(td(x2,y2),td(x1,y1));
59
+ const b = ddDiffDd([0,y2], ddMultDouble1(y1,a));
60
60
 
61
- const c = ddAddDd(
62
- (ddDiffDd(
63
- ddAddDd(tp(y1,y1), tp(y2,y2)),
64
- ddAddDd(tp(z1,z1), tp(z2,z2))
65
- )),
66
- ddMultBy2(ddMultDd(b,(td(z2,y2))))
67
- );
61
+ const c = ddAddDd(
62
+ (ddDiffDd(
63
+ ddAddDd(tp(y1,y1), tp(y2,y2)),
64
+ ddAddDd(tp(z1,z1), tp(z2,z2))
65
+ )),
66
+ ddMultBy2(ddMultDd(b,(td(z2,y2))))
67
+ );
68
68
 
69
- const d = ddAddDd(td(y1,z1), ddMultDd(a,td(y2,z2)));
70
- const t1 = ddDivDd(c,ddMultBy2(d));
71
- const t2 = ddAddDd(ddMultDd(a,t1), b);
72
-
73
- return swapAxes ? [t2[1],t1[1]] : [t1[1],t2[1]];
69
+ const d = ddAddDd(td(y1,z1), ddMultDd(a,td(y2,z2)));
70
+ const t1 = ddDivDd(c,ddMultBy2(d));
71
+ const t2 = ddAddDd(ddMultDd(a,t1), b);
72
+
73
+ return swapAxes ? [t2[1],t1[1]] : [t1[1],t2[1]];
74
74
  }
75
75
 
76
76
 
@@ -7,33 +7,33 @@
7
7
  * @returns The point on the line from y to x that is equidistant from y and z.
8
8
  */
9
9
  function findEquidistantPointOnLine(x: number[], y: number[], z: number[]) {
10
- // Some basic algebra (not shown) finds the required point.
11
-
12
- // Swap axes if x and y are more aligned to y-axis than to x-axis.
13
- const swapAxes = Math.abs((x[1] - y[1]) / (x[0] - y[0])) > 1;
14
-
15
- // Cache
16
- let x1, x2, y1, y2, z1, z2;
17
-
18
- if (swapAxes) {
19
- x1 = x[1]; x2 = x[0];
20
- y1 = y[1]; y2 = y[0];
21
- z1 = z[1]; z2 = z[0];
22
- } else {
23
- x1 = x[0]; x2 = x[1];
24
- y1 = y[0]; y2 = y[1];
25
- z1 = z[0]; z2 = z[1];
26
- }
27
-
28
- // a <= 1 (due to swapped axes)
29
- const a = (x2 - y2) / (x1 - y1);
30
- const b = y2 - a*y1;
31
- const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
32
- const d = y1 - z1 + a*(y2 - z2);
33
- const t1 = c/(2*d);
34
- const t2 = a*t1 + b;
35
-
36
- return swapAxes ? [t2,t1] : [t1,t2];
10
+ // Some basic algebra (not shown) finds the required point.
11
+
12
+ // Swap axes if x and y are more aligned to y-axis than to x-axis.
13
+ const swapAxes = Math.abs((x[1] - y[1]) / (x[0] - y[0])) > 1;
14
+
15
+ // Cache
16
+ let x1, x2, y1, y2, z1, z2;
17
+
18
+ if (swapAxes) {
19
+ x1 = x[1]; x2 = x[0];
20
+ y1 = y[1]; y2 = y[0];
21
+ z1 = z[1]; z2 = z[0];
22
+ } else {
23
+ x1 = x[0]; x2 = x[1];
24
+ y1 = y[0]; y2 = y[1];
25
+ z1 = z[0]; z2 = z[1];
26
+ }
27
+
28
+ // a <= 1 (due to swapped axes)
29
+ const a = (x2 - y2) / (x1 - y1);
30
+ const b = y2 - a*y1;
31
+ const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
32
+ const d = y1 - z1 + a*(y2 - z2);
33
+ const t1 = c/(2*d);
34
+ const t2 = a*t1 + b;
35
+
36
+ return swapAxes ? [t2,t1] : [t1,t2];
37
37
  }
38
38
 
39
39
 
@@ -13,7 +13,7 @@ import { MatMeta } from '../index.js';
13
13
 
14
14
 
15
15
  /** @internal */
16
- function getInitialBezierPieces(
16
+ function getInitialCurvePieces(
17
17
  angle: number,
18
18
  isHoleClosing: boolean,
19
19
  loop: Loop,
@@ -54,4 +54,4 @@ function getInitialBezierPieces(
54
54
  }
55
55
 
56
56
 
57
- export { getInitialBezierPieces }
57
+ export { getInitialCurvePieces }
@@ -10,22 +10,22 @@ import { CurvePiece } from '../mat/curve-piece.js';
10
10
  */
11
11
  function reduceRadius(
12
12
  extreme: number,
13
- bezierPieces: CurvePiece[],
13
+ curvePieces: CurvePiece[],
14
14
  p: number[],
15
15
  x: number[]) {
16
16
 
17
17
  const TOLERANCE = 1 + 2**-10;
18
18
 
19
19
  let minRadius = Number.POSITIVE_INFINITY;
20
- for (let i=0; i<bezierPieces.length; i++) {
21
- const bezierPiece = bezierPieces[i];
20
+ for (let i=0; i<curvePieces.length; i++) {
21
+ const curvePiece = curvePieces[i];
22
22
 
23
- const ps = bezierPiece.curve.ps;
23
+ const ps = curvePiece.curve.ps;
24
24
 
25
25
  // let min = Number.POSITIVE_INFINITY;
26
26
  const num = 2;
27
27
  for (let j=0; j<(num + 1); j++) {
28
- const p_ = evalDeCasteljau(ps, bezierPiece.ts[j/num]);
28
+ const p_ = evalDeCasteljau(ps, curvePiece.ts[j/num]);
29
29
  const cc = getCircleCenterFrom2PointsAndNormal(extreme, p, x, p_);
30
30
  if (cc) {
31
31
  let r = squaredDistanceBetween(p, cc);
@@ -9,14 +9,14 @@ import { getClosestPoints } from './get-closest-points.js';
9
9
  * Find new x and ps that are a better estimate of the 3-prong circle.
10
10
  * The potential function, V, is defined as the distance to the actual 3 prong
11
11
  * circle center.
12
- * @param bezierPiece3s The three boundary pieces, each of which should contain
12
+ * @param curvePiece3s The three boundary pieces, each of which should contain
13
13
  * a point of the 3-prong to be found.
14
14
  * @param x The currently best guess at the center of the 3-prong circle.
15
15
  * @param vectorToZeroV
16
16
  * @param extreme
17
17
  */
18
18
  function calcBetterX(
19
- bezierPiece3s: CurvePiece[][],
19
+ curvePiece3s: CurvePiece[][],
20
20
  x: number[],
21
21
  vectorToZeroV: number[]) {
22
22
 
@@ -33,7 +33,7 @@ function calcBetterX(
33
33
  newX = translate(shift, x);
34
34
 
35
35
 
36
- newPoss = getClosestPoints(newX, bezierPiece3s);
36
+ newPoss = getClosestPoints(newX, curvePiece3s);
37
37
 
38
38
  // Point of zero V
39
39
  const newCircleCenter = circumCenter(newPoss.map(pos => pos!.p));
@@ -13,13 +13,13 @@ const { max, ceil, log2 } = Math;
13
13
  * must be within the shape.
14
14
  * @param δ3s - The three boundary pieces of which we need to find the three
15
15
  * 3-prong points.
16
- * @param bezierPiece3s
16
+ * @param curvePiece3s
17
17
  * @param extreme
18
18
  */
19
19
  function calcInitial3ProngCenter(
20
20
  maxCoordinate: number,
21
21
  δ3s: CpNode[][],
22
- bezierPiece3s: CurvePiece[][]) {
22
+ curvePiece3s: CurvePiece[][]) {
23
23
 
24
24
  const circle = δ3s[0][0].cp.circle;
25
25
  const twoProngCircleCenter = circle.center;
@@ -27,7 +27,7 @@ function calcInitial3ProngCenter(
27
27
  const pow = max(0,ceil(log2(maxCoordinate/circle.radius))) + 1; // determines accuracy;
28
28
  const pos = getCloseBoundaryPointsCertified(
29
29
  pow,
30
- bezierPiece3s[1],
30
+ curvePiece3s[1],
31
31
  twoProngCircleCenter
32
32
  )[0];
33
33