@ccpc/math 0.1.0 → 0.1.3

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 (459) hide show
  1. package/index.cjs +226 -0
  2. package/package.json +19 -37
  3. package/types/algorithm/bool_operate/bool2d/bool2d.d.ts +22 -0
  4. package/types/algorithm/bool_operate/bool2d/difference.d.ts +9 -0
  5. package/types/algorithm/bool_operate/bool2d/intersect.d.ts +9 -0
  6. package/types/algorithm/bool_operate/bool2d/split.d.ts +3 -0
  7. package/types/algorithm/bool_operate/bool2d/union.d.ts +9 -0
  8. package/types/algorithm/bool_operate/bool2d/utils.d.ts +40 -0
  9. package/types/algorithm/bool_operate/bool_operate_clipper.d.ts +18 -0
  10. package/types/algorithm/bool_operate/polycurve_polygon_bool.d.ts +13 -0
  11. package/types/algorithm/bool_operate_2d.d.ts +67 -0
  12. package/types/algorithm/calc_d.d.ts +85 -0
  13. package/types/algorithm/calc_offset.d.ts +70 -0
  14. package/types/algorithm/calc_overlap.d.ts +56 -0
  15. package/types/algorithm/calc_project.d.ts +29 -0
  16. package/types/algorithm/calc_x.d.ts +215 -0
  17. package/types/algorithm/calculate_util/geometry_subdevide_infos.d.ts +73 -0
  18. package/types/algorithm/calculate_util/iterative_method.d.ts +30 -0
  19. package/types/algorithm/discrete/discrete_curve.d.ts +31 -0
  20. package/types/algorithm/discrete/discrete_refiner.d.ts +35 -0
  21. package/types/algorithm/discrete/discrete_surface.d.ts +74 -0
  22. package/types/algorithm/discrete/discrete_topology.d.ts +32 -0
  23. package/types/algorithm/discrete/discrete_util.d.ts +96 -0
  24. package/types/algorithm/discrete/grid_discrete_data.d.ts +58 -0
  25. package/types/algorithm/discrete/libtess.d.ts +12 -0
  26. package/types/algorithm/discrete/uniform_grid_discrete.d.ts +3 -0
  27. package/types/algorithm/distance/base_calc_distance/curves_distance_util.d.ts +20 -0
  28. package/types/algorithm/distance/base_calc_distance/define_of_calculate_distance.d.ts +12 -0
  29. package/types/algorithm/distance/curve2ds_distance/arc2s_distance.d.ts +17 -0
  30. package/types/algorithm/distance/curve2ds_distance/line2d_to_arc2d_distance.d.ts +17 -0
  31. package/types/algorithm/distance/curve2ds_distance/line2s_distance.d.ts +15 -0
  32. package/types/algorithm/distance/curve2s_distance.d.ts +15 -0
  33. package/types/algorithm/distance/curve3ds_distance/line3d_to_line3d_distance_paramed.d.ts +12 -0
  34. package/types/algorithm/distance/curve3s_distance.d.ts +31 -0
  35. package/types/algorithm/distance/pt_to_curve2_signed_distance.d.ts +17 -0
  36. package/types/algorithm/distance/pt_to_curve3_distance.d.ts +25 -0
  37. package/types/algorithm/distance/pt_to_curve_distance_info.d.ts +12 -0
  38. package/types/algorithm/distance/pt_to_surface_distance.d.ts +17 -0
  39. package/types/algorithm/distance/pts_to_curves_distance.d.ts +13 -0
  40. package/types/algorithm/distance/pts_to_pts_distance.d.ts +7 -0
  41. package/types/algorithm/geometry_merge.d.ts +22 -0
  42. package/types/algorithm/index.d.ts +32 -0
  43. package/types/algorithm/intersect/box_cut_line.d.ts +6 -0
  44. package/types/algorithm/intersect/curve_self_x.d.ts +13 -0
  45. package/types/algorithm/intersect/curve_surface_x.d.ts +34 -0
  46. package/types/algorithm/intersect/curve_surface_x_util.d.ts +32 -0
  47. package/types/algorithm/intersect/curves_x/circulars_x.d.ts +35 -0
  48. package/types/algorithm/intersect/curves_x/linear_circular_x.d.ts +40 -0
  49. package/types/algorithm/intersect/curves_x/lines_x.d.ts +17 -0
  50. package/types/algorithm/intersect/curves_x/lines_x_util.d.ts +4 -0
  51. package/types/algorithm/intersect/curves_x.d.ts +26 -0
  52. package/types/algorithm/intersect/curves_x_util.d.ts +35 -0
  53. package/types/algorithm/intersect/intersect_info_util.d.ts +9 -0
  54. package/types/algorithm/intersect/surface_self_x.d.ts +8 -0
  55. package/types/algorithm/intersect/surfaces_x.d.ts +53 -0
  56. package/types/algorithm/intersect/surfaces_x_complex.d.ts +29 -0
  57. package/types/algorithm/intersect/surfaces_x_special.d.ts +16 -0
  58. package/types/algorithm/intersect/surfaces_x_util.d.ts +41 -0
  59. package/types/algorithm/intersect/x_info.d.ts +65 -0
  60. package/types/algorithm/loop_property/loop-area.d.ts +49 -0
  61. package/types/algorithm/loop_property/loop-centroid.d.ts +40 -0
  62. package/types/algorithm/merge_geometry/halfplane.d.ts +24 -0
  63. package/types/algorithm/merge_geometry/merge_curve.d.ts +14 -0
  64. package/types/algorithm/merge_geometry/merge_point.d.ts +18 -0
  65. package/types/algorithm/mesh/clip_mesh.d.ts +27 -0
  66. package/types/algorithm/mesh/extrude_clip.d.ts +236 -0
  67. package/types/algorithm/mesh/mesh_assist.d.ts +21 -0
  68. package/types/algorithm/mesh/mesh_contour.d.ts +26 -0
  69. package/types/algorithm/mesh/mesh_util.d.ts +115 -0
  70. package/types/algorithm/offset/loop2d_offset.d.ts +22 -0
  71. package/types/algorithm/offset/polygon_offset.d.ts +27 -0
  72. package/types/algorithm/overlap/curve_surface_coincide.d.ts +6 -0
  73. package/types/algorithm/overlap/curves_colinear.d.ts +38 -0
  74. package/types/algorithm/overlap/curves_merge.d.ts +74 -0
  75. package/types/algorithm/overlap/curves_overlap.d.ts +34 -0
  76. package/types/algorithm/overlap/i_overlap.d.ts +9 -0
  77. package/types/algorithm/overlap/surfaces_coplaner.d.ts +5 -0
  78. package/types/algorithm/pattern/blocks2Geometry.d.ts +50 -0
  79. package/types/algorithm/pattern/math.d.ts +42 -0
  80. package/types/algorithm/pattern/pattern.d.ts +43 -0
  81. package/types/algorithm/pattern/pattern_util.d.ts +53 -0
  82. package/types/algorithm/pattern/pave.d.ts +33 -0
  83. package/types/algorithm/pj/curves_oj.d.ts +19 -0
  84. package/types/algorithm/pj/curves_pj.d.ts +19 -0
  85. package/types/algorithm/pj/loops_pj.d.ts +13 -0
  86. package/types/algorithm/pj/pj_type.d.ts +46 -0
  87. package/types/algorithm/pj/pt_loop_pj.d.ts +24 -0
  88. package/types/algorithm/pj/pt_polygon_pj.d.ts +18 -0
  89. package/types/algorithm/pj/pt_polygon_position_judger.d.ts +11 -0
  90. package/types/algorithm/position_judge.d.ts +72 -0
  91. package/types/algorithm/project/curve3d_to_plane_project.d.ts +11 -0
  92. package/types/algorithm/project/curve_curve_project.d.ts +9 -0
  93. package/types/algorithm/search_graph/iloops_polygonex.d.ts +28 -0
  94. package/types/algorithm/search_graph/loop_tree_node.d.ts +30 -0
  95. package/types/algorithm/search_graph/loops_to_loop_tree_search_graph.d.ts +25 -0
  96. package/types/algorithm/search_graph/polygon_polygonex.d.ts +13 -0
  97. package/types/algorithm/search_graph/search_loop2d.d.ts +20 -0
  98. package/types/algorithm/search_graph/search_polyline.d.ts +11 -0
  99. package/types/algorithm/search_graph.d.ts +45 -0
  100. package/types/algorithm/topology_edit.d.ts +10 -0
  101. package/types/base/box.d.ts +100 -0
  102. package/types/base/box2.d.ts +17 -0
  103. package/types/base/box3.d.ts +20 -0
  104. package/types/base/coord.d.ts +10 -0
  105. package/types/base/coord2.d.ts +92 -0
  106. package/types/base/coord3.d.ts +139 -0
  107. package/types/base/discrete_param.d.ts +28 -0
  108. package/types/base/euler.d.ts +102 -0
  109. package/types/base/geo_element.d.ts +54 -0
  110. package/types/base/interval.d.ts +122 -0
  111. package/types/base/ivector.d.ts +126 -0
  112. package/types/base/matrix.d.ts +108 -0
  113. package/types/base/matrix3.d.ts +118 -0
  114. package/types/base/matrix4.d.ts +166 -0
  115. package/types/base/matrix_util.d.ts +5 -0
  116. package/types/base/period_inverval.d.ts +127 -0
  117. package/types/base/quaternion.d.ts +39 -0
  118. package/types/base/tangent_cone.d.ts +11 -0
  119. package/types/base/tilt_box.d.ts +11 -0
  120. package/types/base/tol.d.ts +120 -0
  121. package/types/base/vec.d.ts +46 -0
  122. package/types/base/vec2.d.ts +146 -0
  123. package/types/base/vec3.d.ts +158 -0
  124. package/types/brep-src/algorithm/alg_const.d.ts +23 -0
  125. package/types/brep-src/algorithm/alg_types.d.ts +47 -0
  126. package/types/brep-src/algorithm/algorithm_util/base_define.d.ts +7 -0
  127. package/types/brep-src/algorithm/algorithm_util/body_base_util.d.ts +4 -0
  128. package/types/brep-src/algorithm/algorithm_util/curve_solid_analysis.d.ts +28 -0
  129. package/types/brep-src/algorithm/algorithm_util/face_face_analysis.d.ts +39 -0
  130. package/types/brep-src/algorithm/algorithm_util/search_wire.d.ts +8 -0
  131. package/types/brep-src/algorithm/body_builder/basic_body_builder.d.ts +15 -0
  132. package/types/brep-src/algorithm/body_builder/extrude_body.d.ts +23 -0
  133. package/types/brep-src/algorithm/body_builder/sweep_body.d.ts +37 -0
  134. package/types/brep-src/algorithm/body_builder.d.ts +36 -0
  135. package/types/brep-src/algorithm/body_util.d.ts +21 -0
  136. package/types/brep-src/algorithm/bool_sk/brep_converter.d.ts +11 -0
  137. package/types/brep-src/algorithm/brep_calc_project.d.ts +50 -0
  138. package/types/brep-src/algorithm/brep_calc_x.d.ts +34 -0
  139. package/types/brep-src/algorithm/brep_pj.d.ts +47 -0
  140. package/types/brep-src/algorithm/index.d.ts +5 -0
  141. package/types/brep-src/algorithm/intersect/curve_face_overlap.d.ts +10 -0
  142. package/types/brep-src/algorithm/intersect/face_face_intersect.d.ts +22 -0
  143. package/types/brep-src/algorithm/intersect/face_faces_intersect.d.ts +15 -0
  144. package/types/brep-src/algorithm/intersect/line_face_intersect.d.ts +16 -0
  145. package/types/brep-src/algorithm/podition_judge/body_pj.d.ts +25 -0
  146. package/types/brep-src/algorithm/podition_judge/extrude_pj.d.ts +28 -0
  147. package/types/brep-src/algorithm/podition_judge/pt_body_pj.d.ts +32 -0
  148. package/types/brep-src/algorithm/project/body_project.d.ts +8 -0
  149. package/types/brep-src/algorithm/project/face_project.d.ts +20 -0
  150. package/types/brep-src/algorithm/project/face_surface_project.d.ts +8 -0
  151. package/types/brep-src/algorithm/project/space_project.d.ts +26 -0
  152. package/types/brep-src/algorithm/project/space_project_simple.d.ts +10 -0
  153. package/types/brep-src/algorithm/project/view_project.d.ts +25 -0
  154. package/types/brep-src/algorithm/shell_builder/create_shell_from_curves.d.ts +38 -0
  155. package/types/brep-src/algorithm/shell_builder.d.ts +25 -0
  156. package/types/brep-src/algorithm/shell_edit/add_edges/add_edges.d.ts +14 -0
  157. package/types/brep-src/algorithm/shell_edit/add_edges/add_edges_core.d.ts +11 -0
  158. package/types/brep-src/algorithm/shell_edit/copy_faces.d.ts +20 -0
  159. package/types/brep-src/algorithm/shell_edit/delete_faces_edges/delete_edge.d.ts +9 -0
  160. package/types/brep-src/algorithm/shell_edit/delete_faces_edges/delete_faces_edges.d.ts +17 -0
  161. package/types/brep-src/algorithm/shell_edit/faces_boolean/faces_boolean.d.ts +19 -0
  162. package/types/brep-src/algorithm/shell_edit/faces_boolean/faces_shells_boolean.d.ts +13 -0
  163. package/types/brep-src/algorithm/shell_edit/faces_boolean/octree.d.ts +11 -0
  164. package/types/brep-src/algorithm/shell_edit/isolate_faces.d.ts +21 -0
  165. package/types/brep-src/algorithm/shell_edit/merge_connect_faces.d.ts +14 -0
  166. package/types/brep-src/algorithm/shell_edit/merge_edges.d.ts +8 -0
  167. package/types/brep-src/algorithm/shell_edit/move_operators/move_edges.d.ts +31 -0
  168. package/types/brep-src/algorithm/shell_edit/move_operators/move_faces.d.ts +14 -0
  169. package/types/brep-src/algorithm/shell_edit/operator/dispose_topo.d.ts +2 -0
  170. package/types/brep-src/algorithm/shell_edit/operator/merge_connect_edge.d.ts +3 -0
  171. package/types/brep-src/algorithm/shell_edit/operator/merge_connect_face.d.ts +2 -0
  172. package/types/brep-src/algorithm/shell_edit/operator/merge_overlap_edge.d.ts +3 -0
  173. package/types/brep-src/algorithm/shell_edit/operator/merge_shell.d.ts +11 -0
  174. package/types/brep-src/algorithm/shell_edit/operator/merge_vertex.d.ts +2 -0
  175. package/types/brep-src/algorithm/shell_edit/operator/split_edge.d.ts +4 -0
  176. package/types/brep-src/algorithm/shell_edit/operator/split_shell.d.ts +6 -0
  177. package/types/brep-src/algorithm/shell_edit/pull_push_face/pull_push_face.d.ts +18 -0
  178. package/types/brep-src/algorithm/shell_edit/pull_push_face/pull_push_face_core.d.ts +6 -0
  179. package/types/brep-src/algorithm/shell_edit/pull_push_face/pull_push_face_preview.d.ts +16 -0
  180. package/types/brep-src/algorithm/shell_edit/pull_push_face/pull_push_face_preview_core.d.ts +24 -0
  181. package/types/brep-src/algorithm/shell_edit/roundinng/2d_rounding.d.ts +22 -0
  182. package/types/brep-src/algorithm/shell_edit/shell_modeling_base.d.ts +10 -0
  183. package/types/brep-src/algorithm/shell_edit/shell_modeling_result.d.ts +21 -0
  184. package/types/brep-src/algorithm/shell_edit/smooth/detect_loop_util.d.ts +27 -0
  185. package/types/brep-src/algorithm/shell_edit/smooth/shell_modeling_util.d.ts +24 -0
  186. package/types/brep-src/algorithm/shell_edit/smooth/smooth_util.d.ts +22 -0
  187. package/types/brep-src/algorithm/shell_edit/split_edge.d.ts +10 -0
  188. package/types/brep-src/algorithm/shell_edit.d.ts +119 -0
  189. package/types/brep-src/algorithm/shell_valid/base_brep_topo_error.d.ts +176 -0
  190. package/types/brep-src/algorithm/shell_valid/diagnose_shell.d.ts +14 -0
  191. package/types/brep-src/brep/brep_body.d.ts +19 -0
  192. package/types/brep-src/brep/coedge3d.d.ts +83 -0
  193. package/types/brep-src/brep/edge.d.ts +96 -0
  194. package/types/brep-src/brep/face.d.ts +150 -0
  195. package/types/brep-src/brep/shell.d.ts +166 -0
  196. package/types/brep-src/brep/topo_object.d.ts +40 -0
  197. package/types/brep-src/brep/vertex.d.ts +48 -0
  198. package/types/brep-src/brep/wire.d.ts +66 -0
  199. package/types/brep-src/continuous/continuous_edge.d.ts +17 -0
  200. package/types/brep-src/continuous/continuous_face.d.ts +10 -0
  201. package/types/brep-src/continuous/continuous_util.d.ts +60 -0
  202. package/types/brep-src/continuous/continuous_uv.d.ts +24 -0
  203. package/types/brep-src/continuous/index.d.ts +4 -0
  204. package/types/brep-src/index.d.ts +14 -0
  205. package/types/brep-src/type_define/i_types.d.ts +46 -0
  206. package/types/brep-src/util/util.d.ts +23 -0
  207. package/types/conversion/units_conversion.d.ts +14 -0
  208. package/types/geometry/arc2d.d.ts +249 -0
  209. package/types/geometry/arc3d.d.ts +204 -0
  210. package/types/geometry/circle3d.d.ts +92 -0
  211. package/types/geometry/circular_surface.d.ts +52 -0
  212. package/types/geometry/coord_based_surface.d.ts +25 -0
  213. package/types/geometry/curve.d.ts +228 -0
  214. package/types/geometry/curve2.d.ts +62 -0
  215. package/types/geometry/curve3d.d.ts +66 -0
  216. package/types/geometry/cylinder.d.ts +73 -0
  217. package/types/geometry/discrete_arrow.d.ts +3 -0
  218. package/types/geometry/extend_curve2.d.ts +75 -0
  219. package/types/geometry/geometry2d.d.ts +35 -0
  220. package/types/geometry/geometry3d.d.ts +36 -0
  221. package/types/geometry/intersect_curve3.d.ts +90 -0
  222. package/types/geometry/ln2.d.ts +168 -0
  223. package/types/geometry/ln3.d.ts +152 -0
  224. package/types/geometry/nurbs_curve2.d.ts +106 -0
  225. package/types/geometry/nurbs_curve3.d.ts +191 -0
  226. package/types/geometry/offset_curve2.d.ts +63 -0
  227. package/types/geometry/offset_curve3.d.ts +97 -0
  228. package/types/geometry/offset_parameter_mapper.d.ts +72 -0
  229. package/types/geometry/plane.d.ts +109 -0
  230. package/types/geometry/polyline.d.ts +12 -0
  231. package/types/geometry/smooth_poly2.d.ts +78 -0
  232. package/types/geometry/smooth_poly3.d.ts +85 -0
  233. package/types/geometry/surface.d.ts +173 -0
  234. package/types/index.d.ts +78 -0
  235. package/types/io/obj_parser.d.ts +4 -0
  236. package/types/io/svgparser.d.ts +22 -0
  237. package/types/loader/loader.d.ts +23 -0
  238. package/types/loader/register_geo.d.ts +7 -0
  239. package/types/math/gauss_integration.d.ts +13 -0
  240. package/types/math/inv_bilinear.d.ts +33 -0
  241. package/types/solve_equations/cubic_equation.d.ts +7 -0
  242. package/types/solve_equations/linear_system.d.ts +6 -0
  243. package/types/solve_equations/nonlinear_system.d.ts +11 -0
  244. package/types/solve_equations/plurality.d.ts +9 -0
  245. package/types/solve_equations/polynomial_equation.d.ts +6 -0
  246. package/types/solve_equations/quadratic_equation.d.ts +6 -0
  247. package/types/solve_equations/quartic_equation.d.ts +6 -0
  248. package/types/solve_equations/solve_equation_util.d.ts +50 -0
  249. package/types/test_util/loop_generator.d.ts +21 -0
  250. package/types/topology/evolution_map.d.ts +90 -0
  251. package/types/topology/loop.d.ts +50 -0
  252. package/types/topology/polycurve.d.ts +109 -0
  253. package/types/topology/polygon.d.ts +118 -0
  254. package/types/topology/trimmed_surface.d.ts +136 -0
  255. package/types/type_define/const.d.ts +18 -0
  256. package/types/type_define/i_element.d.ts +9 -0
  257. package/types/type_define/i_element_type.d.ts +34 -0
  258. package/types/type_define/i_geometry.d.ts +191 -0
  259. package/types/type_define/i_types.d.ts +280 -0
  260. package/types/util/array_util.d.ts +8 -0
  261. package/types/util/assert.d.ts +21 -0
  262. package/types/util/clipper2_util.d.ts +5 -0
  263. package/types/util/clipper_format_converter.d.ts +21 -0
  264. package/types/util/clipper_util.d.ts +10 -0
  265. package/types/util/curve_util.d.ts +72 -0
  266. package/types/util/geom_util.d.ts +23 -0
  267. package/types/util/log.d.ts +19 -0
  268. package/types/util/math_error.d.ts +37 -0
  269. package/types/util/surface_util.d.ts +13 -0
  270. package/types/util/util.d.ts +18 -0
  271. package/types/util/uv_util.d.ts +68 -0
  272. package/types/verb/export_verb.d.ts +2 -0
  273. package/types/wasm/a2d.d.ts +19 -0
  274. package/types/wasm/bx2.d.ts +16 -0
  275. package/types/wasm/c2d.d.ts +29 -0
  276. package/types/wasm/elli.d.ts +19 -0
  277. package/types/wasm/grapher2d.d.ts +39 -0
  278. package/types/wasm/grapherutil.d.ts +9 -0
  279. package/types/wasm/l2d.d.ts +14 -0
  280. package/types/wasm/loader.d.ts +8 -0
  281. package/types/wasm/pt.d.ts +19 -0
  282. package/types/wasm/wasm-geom.d.ts +296 -0
  283. package/types/wasm/wasminstance.d.ts +19 -0
  284. package/types/wasm/wrapper.d.ts +82 -0
  285. package/README.md +0 -21
  286. package/dist/constants/geom_type.d.ts +0 -13
  287. package/dist/constants/geom_type.d.ts.map +0 -1
  288. package/dist/constants/geom_type.js +0 -17
  289. package/dist/constants/math_const.d.ts +0 -9
  290. package/dist/constants/math_const.d.ts.map +0 -1
  291. package/dist/constants/math_const.js +0 -12
  292. package/dist/core/box2.d.ts +0 -71
  293. package/dist/core/box2.d.ts.map +0 -1
  294. package/dist/core/box2.js +0 -243
  295. package/dist/core/coord2d.d.ts +0 -62
  296. package/dist/core/coord2d.d.ts.map +0 -1
  297. package/dist/core/coord2d.js +0 -155
  298. package/dist/core/geom_base.d.ts +0 -19
  299. package/dist/core/geom_base.d.ts.map +0 -1
  300. package/dist/core/geom_base.js +0 -18
  301. package/dist/core/mat3.d.ts +0 -101
  302. package/dist/core/mat3.d.ts.map +0 -1
  303. package/dist/core/mat3.js +0 -290
  304. package/dist/core/vec2.d.ts +0 -138
  305. package/dist/core/vec2.d.ts.map +0 -1
  306. package/dist/core/vec2.js +0 -297
  307. package/dist/curves/arc2.d.ts +0 -49
  308. package/dist/curves/arc2.d.ts.map +0 -1
  309. package/dist/curves/arc2.js +0 -265
  310. package/dist/curves/bspline2.d.ts +0 -150
  311. package/dist/curves/bspline2.d.ts.map +0 -1
  312. package/dist/curves/bspline2.js +0 -793
  313. package/dist/curves/circle2.d.ts +0 -42
  314. package/dist/curves/circle2.d.ts.map +0 -1
  315. package/dist/curves/circle2.js +0 -135
  316. package/dist/curves/circle_curve2.d.ts +0 -38
  317. package/dist/curves/circle_curve2.d.ts.map +0 -1
  318. package/dist/curves/circle_curve2.js +0 -112
  319. package/dist/curves/curve2.d.ts +0 -214
  320. package/dist/curves/curve2.d.ts.map +0 -1
  321. package/dist/curves/curve2.js +0 -238
  322. package/dist/curves/ellipse2.d.ts +0 -42
  323. package/dist/curves/ellipse2.d.ts.map +0 -1
  324. package/dist/curves/ellipse2.js +0 -125
  325. package/dist/curves/ellipse_arc2.d.ts +0 -49
  326. package/dist/curves/ellipse_arc2.d.ts.map +0 -1
  327. package/dist/curves/ellipse_arc2.js +0 -184
  328. package/dist/curves/ellipse_curve2.d.ts +0 -56
  329. package/dist/curves/ellipse_curve2.d.ts.map +0 -1
  330. package/dist/curves/ellipse_curve2.js +0 -262
  331. package/dist/curves/interval.d.ts +0 -112
  332. package/dist/curves/interval.d.ts.map +0 -1
  333. package/dist/curves/interval.js +0 -200
  334. package/dist/curves/line2.d.ts +0 -64
  335. package/dist/curves/line2.d.ts.map +0 -1
  336. package/dist/curves/line2.js +0 -193
  337. package/dist/curves/period_interval.d.ts +0 -129
  338. package/dist/curves/period_interval.d.ts.map +0 -1
  339. package/dist/curves/period_interval.js +0 -240
  340. package/dist/discretize/discretize_defaults.d.ts +0 -12
  341. package/dist/discretize/discretize_defaults.d.ts.map +0 -1
  342. package/dist/discretize/discretize_defaults.js +0 -12
  343. package/dist/discretize/discretize_engine.d.ts +0 -33
  344. package/dist/discretize/discretize_engine.d.ts.map +0 -1
  345. package/dist/discretize/discretize_engine.js +0 -347
  346. package/dist/discretize/discretize_errors.d.ts +0 -15
  347. package/dist/discretize/discretize_errors.d.ts.map +0 -1
  348. package/dist/discretize/discretize_errors.js +0 -30
  349. package/dist/discretize/discretize_options.d.ts +0 -18
  350. package/dist/discretize/discretize_options.d.ts.map +0 -1
  351. package/dist/discretize/discretize_options.js +0 -19
  352. package/dist/discretize/discretize_types.d.ts +0 -36
  353. package/dist/discretize/discretize_types.d.ts.map +0 -1
  354. package/dist/discretize/discretize_types.js +0 -1
  355. package/dist/discretize/internal/curve_guards.d.ts +0 -35
  356. package/dist/discretize/internal/curve_guards.d.ts.map +0 -1
  357. package/dist/discretize/internal/curve_guards.js +0 -62
  358. package/dist/discretize/internal/postprocess.d.ts +0 -5
  359. package/dist/discretize/internal/postprocess.d.ts.map +0 -1
  360. package/dist/discretize/internal/postprocess.js +0 -109
  361. package/dist/discretize/internal/sampling_utils.d.ts +0 -8
  362. package/dist/discretize/internal/sampling_utils.d.ts.map +0 -1
  363. package/dist/discretize/internal/sampling_utils.js +0 -36
  364. package/dist/discretize/register_builtin_strategies.d.ts +0 -3
  365. package/dist/discretize/register_builtin_strategies.d.ts.map +0 -1
  366. package/dist/discretize/register_builtin_strategies.js +0 -10
  367. package/dist/discretize/strategies/bspline_strategy.d.ts +0 -4
  368. package/dist/discretize/strategies/bspline_strategy.d.ts.map +0 -1
  369. package/dist/discretize/strategies/bspline_strategy.js +0 -115
  370. package/dist/discretize/strategies/circle_strategy.d.ts +0 -7
  371. package/dist/discretize/strategies/circle_strategy.d.ts.map +0 -1
  372. package/dist/discretize/strategies/circle_strategy.js +0 -55
  373. package/dist/discretize/strategies/ellipse_strategy.d.ts +0 -7
  374. package/dist/discretize/strategies/ellipse_strategy.d.ts.map +0 -1
  375. package/dist/discretize/strategies/ellipse_strategy.js +0 -86
  376. package/dist/discretize/strategies/line_strategy.d.ts +0 -4
  377. package/dist/discretize/strategies/line_strategy.d.ts.map +0 -1
  378. package/dist/discretize/strategies/line_strategy.js +0 -40
  379. package/dist/discretize/strategy_registry.d.ts +0 -9
  380. package/dist/discretize/strategy_registry.d.ts.map +0 -1
  381. package/dist/discretize/strategy_registry.js +0 -34
  382. package/dist/index.d.ts +0 -30
  383. package/dist/index.d.ts.map +0 -1
  384. package/dist/index.js +0 -24
  385. package/dist/intersections/analytic_x_algorithm.d.ts +0 -10
  386. package/dist/intersections/analytic_x_algorithm.d.ts.map +0 -1
  387. package/dist/intersections/analytic_x_algorithm.js +0 -83
  388. package/dist/intersections/curve_x_engine.d.ts +0 -9
  389. package/dist/intersections/curve_x_engine.d.ts.map +0 -1
  390. package/dist/intersections/curve_x_engine.js +0 -27
  391. package/dist/intersections/index.d.ts +0 -5
  392. package/dist/intersections/index.d.ts.map +0 -1
  393. package/dist/intersections/index.js +0 -11
  394. package/dist/intersections/internal/certification.d.ts +0 -34
  395. package/dist/intersections/internal/certification.d.ts.map +0 -1
  396. package/dist/intersections/internal/certification.js +0 -238
  397. package/dist/intersections/internal/interval_clipping.d.ts +0 -29
  398. package/dist/intersections/internal/interval_clipping.d.ts.map +0 -1
  399. package/dist/intersections/internal/interval_clipping.js +0 -123
  400. package/dist/intersections/internal/kind.d.ts +0 -4
  401. package/dist/intersections/internal/kind.d.ts.map +0 -1
  402. package/dist/intersections/internal/kind.js +0 -16
  403. package/dist/intersections/internal/pair.d.ts +0 -9
  404. package/dist/intersections/internal/pair.d.ts.map +0 -1
  405. package/dist/intersections/internal/pair.js +0 -14
  406. package/dist/intersections/internal/result.d.ts +0 -20
  407. package/dist/intersections/internal/result.d.ts.map +0 -1
  408. package/dist/intersections/internal/result.js +0 -125
  409. package/dist/intersections/internal/sampling.d.ts +0 -15
  410. package/dist/intersections/internal/sampling.d.ts.map +0 -1
  411. package/dist/intersections/internal/sampling.js +0 -131
  412. package/dist/intersections/internal/segment.d.ts +0 -32
  413. package/dist/intersections/internal/segment.d.ts.map +0 -1
  414. package/dist/intersections/internal/segment.js +0 -137
  415. package/dist/intersections/internal/tolerance.d.ts +0 -10
  416. package/dist/intersections/internal/tolerance.d.ts.map +0 -1
  417. package/dist/intersections/internal/tolerance.js +0 -20
  418. package/dist/intersections/intersector.d.ts +0 -6
  419. package/dist/intersections/intersector.d.ts.map +0 -1
  420. package/dist/intersections/intersector.js +0 -1
  421. package/dist/intersections/numeric_x_algorithm.d.ts +0 -10
  422. package/dist/intersections/numeric_x_algorithm.d.ts.map +0 -1
  423. package/dist/intersections/numeric_x_algorithm.js +0 -73
  424. package/dist/intersections/solvers/bspline_self_solver.d.ts +0 -7
  425. package/dist/intersections/solvers/bspline_self_solver.d.ts.map +0 -1
  426. package/dist/intersections/solvers/bspline_self_solver.js +0 -308
  427. package/dist/intersections/solvers/line_line_pair_solver.d.ts +0 -7
  428. package/dist/intersections/solvers/line_line_pair_solver.d.ts.map +0 -1
  429. package/dist/intersections/solvers/line_line_pair_solver.js +0 -35
  430. package/dist/intersections/solvers/pair_solvers.d.ts +0 -94
  431. package/dist/intersections/solvers/pair_solvers.d.ts.map +0 -1
  432. package/dist/intersections/solvers/pair_solvers.js +0 -1078
  433. package/dist/intersections/solvers/polyline_pair_intersector.d.ts +0 -51
  434. package/dist/intersections/solvers/polyline_pair_intersector.d.ts.map +0 -1
  435. package/dist/intersections/solvers/polyline_pair_intersector.js +0 -731
  436. package/dist/intersections/types.d.ts +0 -11
  437. package/dist/intersections/types.d.ts.map +0 -1
  438. package/dist/intersections/types.js +0 -1
  439. package/dist/serialize/dump_types.d.ts +0 -101
  440. package/dist/serialize/dump_types.d.ts.map +0 -1
  441. package/dist/serialize/dump_types.js +0 -5
  442. package/dist/serialize/geom_mgr.d.ts +0 -24
  443. package/dist/serialize/geom_mgr.d.ts.map +0 -1
  444. package/dist/serialize/geom_mgr.js +0 -30
  445. package/dist/types/type_define.d.ts +0 -29
  446. package/dist/types/type_define.d.ts.map +0 -1
  447. package/dist/types/type_define.js +0 -10
  448. package/dist/types/type_guard.d.ts +0 -46
  449. package/dist/types/type_guard.d.ts.map +0 -1
  450. package/dist/types/type_guard.js +0 -5
  451. package/dist/utils/math_error.d.ts +0 -16
  452. package/dist/utils/math_error.d.ts.map +0 -1
  453. package/dist/utils/math_error.js +0 -35
  454. package/dist/utils/math_utils.d.ts +0 -9
  455. package/dist/utils/math_utils.d.ts.map +0 -1
  456. package/dist/utils/math_utils.js +0 -25
  457. package/dist/utils/precision.d.ts +0 -29
  458. package/dist/utils/precision.d.ts.map +0 -1
  459. package/dist/utils/precision.js +0 -44
@@ -1,731 +0,0 @@
1
- import { Interval } from '../../curves/interval';
2
- import { Precision } from '../../utils/precision';
3
- import { certifyOverlapMonotone, certifyParamPair, projectRangeToCurve } from '../internal/certification';
4
- import { collectIntervalClipSeeds } from '../internal/interval_clipping';
5
- import { intersectSegments, lerp, makeSegment, segmentBoxesMayIntersect, segmentDistance } from '../internal/segment';
6
- import { sampleCurveAdaptive } from '../internal/sampling';
7
- import { makeIntersectionTolerance } from '../internal/tolerance';
8
- class SegmentHashIndex {
9
- constructor(segments, pad) {
10
- this.segments = segments;
11
- this.map = new Map();
12
- this.overflow = [];
13
- let minX = Number.POSITIVE_INFINITY;
14
- let minY = Number.POSITIVE_INFINITY;
15
- let maxX = Number.NEGATIVE_INFINITY;
16
- let maxY = Number.NEGATIVE_INFINITY;
17
- for (const s of segments) {
18
- minX = Math.min(minX, s.seg.minX);
19
- minY = Math.min(minY, s.seg.minY);
20
- maxX = Math.max(maxX, s.seg.maxX);
21
- maxY = Math.max(maxY, s.seg.maxY);
22
- }
23
- if (!Number.isFinite(minX) || !Number.isFinite(minY) || !Number.isFinite(maxX) || !Number.isFinite(maxY)) {
24
- minX = minY = 0;
25
- maxX = maxY = 1;
26
- }
27
- const count = Math.max(1, segments.length);
28
- const grid = clampInt(Math.round(Math.sqrt(count)), 8, 64);
29
- const spanX = Math.max(maxX - minX, pad * 2, Precision.CURVE_LENGTH_EPS);
30
- const spanY = Math.max(maxY - minY, pad * 2, Precision.CURVE_LENGTH_EPS);
31
- this.minX = minX - pad;
32
- this.minY = minY - pad;
33
- this.gridX = grid;
34
- this.gridY = grid;
35
- this.cellSizeX = spanX / this.gridX;
36
- this.cellSizeY = spanY / this.gridY;
37
- const maxCellsPerSegment = 64;
38
- for (let i = 0; i < segments.length; i++) {
39
- const seg = segments[i].seg;
40
- const ix0 = this.toX(seg.minX - pad);
41
- const ix1 = this.toX(seg.maxX + pad);
42
- const iy0 = this.toY(seg.minY - pad);
43
- const iy1 = this.toY(seg.maxY + pad);
44
- const cells = (ix1 - ix0 + 1) * (iy1 - iy0 + 1);
45
- if (cells > maxCellsPerSegment) {
46
- this.overflow.push(i);
47
- continue;
48
- }
49
- for (let ix = ix0; ix <= ix1; ix++) {
50
- for (let iy = iy0; iy <= iy1; iy++) {
51
- const key = this.key(ix, iy);
52
- const list = this.map.get(key);
53
- if (list) {
54
- list.push(i);
55
- }
56
- else {
57
- this.map.set(key, [i]);
58
- }
59
- }
60
- }
61
- }
62
- }
63
- query(seg, pad, marks, stamp) {
64
- const ret = [];
65
- const ix0 = this.toX(seg.seg.minX - pad);
66
- const ix1 = this.toX(seg.seg.maxX + pad);
67
- const iy0 = this.toY(seg.seg.minY - pad);
68
- const iy1 = this.toY(seg.seg.maxY + pad);
69
- for (let ix = ix0; ix <= ix1; ix++) {
70
- for (let iy = iy0; iy <= iy1; iy++) {
71
- const list = this.map.get(this.key(ix, iy));
72
- if (!list)
73
- continue;
74
- for (const j of list) {
75
- if (marks[j] === stamp)
76
- continue;
77
- marks[j] = stamp;
78
- ret.push(j);
79
- }
80
- }
81
- }
82
- for (const j of this.overflow) {
83
- if (marks[j] === stamp)
84
- continue;
85
- marks[j] = stamp;
86
- ret.push(j);
87
- }
88
- return ret;
89
- }
90
- toX(x) {
91
- const raw = Math.floor((x - this.minX) / this.cellSizeX);
92
- return clampInt(raw, 0, this.gridX - 1);
93
- }
94
- toY(y) {
95
- const raw = Math.floor((y - this.minY) / this.cellSizeY);
96
- return clampInt(raw, 0, this.gridY - 1);
97
- }
98
- key(ix, iy) {
99
- return `${ix},${iy}`;
100
- }
101
- }
102
- const polylineDiagnostics = {
103
- numericClosestFallbackCount: 0,
104
- analyticClosestFallbackCount: 0,
105
- recursiveNodesVisited: 0,
106
- recursiveAbortCount: 0,
107
- refineFailureCount: 0,
108
- certificationRejectCount: 0,
109
- certificationMissCount: 0,
110
- degenerateRescueCount: 0,
111
- rescuePassCount: 0,
112
- rescueSeedCount: 0,
113
- rescueHitCount: 0,
114
- candidateSeedCount: 0,
115
- certifiedPointCount: 0,
116
- certifiedOverlapCount: 0,
117
- newtonIterationsTotal: 0,
118
- projectionIterationsTotal: 0,
119
- maxResidual: 0,
120
- };
121
- export class PolylinePairIntersector {
122
- static resetDiagnostics() {
123
- polylineDiagnostics.numericClosestFallbackCount = 0;
124
- polylineDiagnostics.analyticClosestFallbackCount = 0;
125
- polylineDiagnostics.recursiveNodesVisited = 0;
126
- polylineDiagnostics.recursiveAbortCount = 0;
127
- polylineDiagnostics.refineFailureCount = 0;
128
- polylineDiagnostics.certificationRejectCount = 0;
129
- polylineDiagnostics.certificationMissCount = 0;
130
- polylineDiagnostics.degenerateRescueCount = 0;
131
- polylineDiagnostics.rescuePassCount = 0;
132
- polylineDiagnostics.rescueSeedCount = 0;
133
- polylineDiagnostics.rescueHitCount = 0;
134
- polylineDiagnostics.candidateSeedCount = 0;
135
- polylineDiagnostics.certifiedPointCount = 0;
136
- polylineDiagnostics.certifiedOverlapCount = 0;
137
- polylineDiagnostics.newtonIterationsTotal = 0;
138
- polylineDiagnostics.projectionIterationsTotal = 0;
139
- polylineDiagnostics.maxResidual = 0;
140
- }
141
- static getDiagnostics() {
142
- return { ...polylineDiagnostics };
143
- }
144
- static recordAnalyticClosestFallback() {
145
- polylineDiagnostics.analyticClosestFallbackCount++;
146
- }
147
- constructor(segmentsPerCurve, maxNewtonIter = Precision.CURVE_MAX_ITER) {
148
- this.segmentsPerCurve = segmentsPerCurve;
149
- this.maxNewtonIter = maxNewtonIter;
150
- this.runPointSeedLimit = 0;
151
- this.runOverlapSeedLimit = 0;
152
- }
153
- intersect(c1, c2) {
154
- const tol = makeIntersectionTolerance(c1, c2);
155
- const pairTol = tol.pointTol;
156
- const hasBSpline = c1.isBSpline() || c2.isBSpline();
157
- // Keep strict certification only for BSpline-BSpline.
158
- // Mixed pairs (Line/Circle/Arc/Ellipse with BSpline) prioritize recall first.
159
- const strictCertify = c1.isBSpline() && c2.isBSpline();
160
- const enableNearMissSeeding = hasBSpline || c1.isEllipseArc() || c2.isEllipseArc();
161
- const nearSeedBudget = Math.max(48, Math.floor(this.segmentsPerCurve * 0.75));
162
- this.runPointSeedLimit = Math.max(320, this.segmentsPerCurve * 2);
163
- this.runOverlapSeedLimit = Math.max(24, Math.ceil(this.segmentsPerCurve / 8));
164
- const s1 = sampleCurveAdaptive(c1, this.segmentsPerCurve, {
165
- chordErrorTol: pairTol * 0.75,
166
- maxSamples: this.segmentsPerCurve * 8,
167
- });
168
- const s2 = sampleCurveAdaptive(c2, this.segmentsPerCurve, {
169
- chordErrorTol: pairTol * 0.75,
170
- maxSamples: this.segmentsPerCurve * 8,
171
- });
172
- if (s1.length < 2 || s2.length < 2)
173
- return [];
174
- const segs1 = this.buildSegments(s1);
175
- const segs2 = this.buildSegments(s2);
176
- const candidates = this.buildPairCandidates(segs1, segs2, pairTol);
177
- const pointSeeds = [];
178
- const overlapSeeds = [];
179
- let minNearDistance = Number.POSITIVE_INFINITY;
180
- let nearSeedCount = 0;
181
- const refineFailureBefore = polylineDiagnostics.refineFailureCount;
182
- const ret = [];
183
- for (const candidate of candidates) {
184
- const sA = segs1[candidate.i];
185
- const sB = segs2[candidate.j];
186
- const hit = intersectSegments(sA.seg, sB.seg);
187
- if (hit.kind === 'none') {
188
- const near = segmentDistance(sA.seg, sB.seg);
189
- minNearDistance = Math.min(minNearDistance, near);
190
- if (enableNearMissSeeding &&
191
- near <= pairTol * 0.8 &&
192
- nearSeedCount < nearSeedBudget &&
193
- pointSeeds.length <= nearSeedBudget * 2) {
194
- this.addNearMissSeeds(pointSeeds, sA, sB, tol.seedParamTol);
195
- nearSeedCount++;
196
- }
197
- continue;
198
- }
199
- minNearDistance = 0;
200
- if (hit.kind === 'point') {
201
- const u1 = lerp(sA.u0, sA.u1, hit.t1);
202
- const u2 = lerp(sB.u0, sB.u1, hit.t2);
203
- this.addPointSeed(pointSeeds, u1, u2, tol.seedParamTol);
204
- continue;
205
- }
206
- const u1s = lerp(sA.u0, sA.u1, hit.t1s);
207
- const u1e = lerp(sA.u0, sA.u1, hit.t1e);
208
- const u2s = lerp(sB.u0, sB.u1, hit.t2s);
209
- const u2e = lerp(sB.u0, sB.u1, hit.t2e);
210
- this.addOverlapSeed(overlapSeeds, {
211
- range1: new Interval(Math.min(u1s, u1e), Math.max(u1s, u1e)),
212
- range2: new Interval(Math.min(u2s, u2e), Math.max(u2s, u2e)),
213
- });
214
- this.addPointSeed(pointSeeds, (u1s + u1e) * 0.5, (u2s + u2e) * 0.5, tol.seedParamTol);
215
- this.addPointSeed(pointSeeds, u1s, u2s, tol.seedParamTol);
216
- this.addPointSeed(pointSeeds, u1e, u2e, tol.seedParamTol);
217
- }
218
- if (pointSeeds.length <= 8 && overlapSeeds.length <= 4) {
219
- const clipped = collectIntervalClipSeeds(c1, c2, {
220
- pointTol: pairTol,
221
- seedParamTol: tol.seedParamTol,
222
- maxDepth: Math.max(8, Math.ceil(Math.log2(Math.max(8, this.segmentsPerCurve))) + 6),
223
- maxNodes: this.recursiveMaxNodes(c1, c2),
224
- pointSeedLimit: Math.max(8, this.runPointSeedLimit - pointSeeds.length),
225
- overlapSeedLimit: Math.max(4, this.runOverlapSeedLimit - overlapSeeds.length),
226
- });
227
- polylineDiagnostics.recursiveNodesVisited += clipped.diagnostics.nodesVisited;
228
- if (clipped.diagnostics.aborted) {
229
- polylineDiagnostics.recursiveAbortCount++;
230
- }
231
- for (const seed of clipped.pointSeeds) {
232
- this.addPointSeed(pointSeeds, seed.u1, seed.u2, tol.seedParamTol);
233
- }
234
- for (const overlap of clipped.overlapSeeds) {
235
- this.addOverlapSeed(overlapSeeds, overlap);
236
- }
237
- }
238
- polylineDiagnostics.candidateSeedCount += pointSeeds.length;
239
- for (const seed of pointSeeds) {
240
- const refined = this.refinePair(c1, c2, seed.u1, seed.u2, pairTol, strictCertify);
241
- if (!refined)
242
- continue;
243
- this.pushUnique(ret, {
244
- point: refined.point,
245
- u1: refined.u1,
246
- u2: refined.u2,
247
- isOverlap: false,
248
- });
249
- polylineDiagnostics.certifiedPointCount++;
250
- }
251
- for (const overlap of overlapSeeds) {
252
- const overlapInfo = this.refineOverlap(c1, c2, overlap, pairTol, tol.paramTol);
253
- if (overlapInfo) {
254
- this.pushUnique(ret, overlapInfo);
255
- if (overlapInfo.isOverlap) {
256
- polylineDiagnostics.certifiedOverlapCount++;
257
- }
258
- else {
259
- polylineDiagnostics.certifiedPointCount++;
260
- }
261
- }
262
- }
263
- const refineFailureDelta = polylineDiagnostics.refineFailureCount - refineFailureBefore;
264
- if (hasBSpline &&
265
- ret.length === 0 &&
266
- (pointSeeds.length > 0 || overlapSeeds.length > 0 || minNearDistance <= pairTol * 2)) {
267
- const rescued = this.runRescuePass(c1, c2, pairTol, tol.seedParamTol, strictCertify);
268
- if (rescued.length > 0) {
269
- for (const hit of rescued) {
270
- this.pushUnique(ret, hit);
271
- }
272
- polylineDiagnostics.rescueHitCount += rescued.length;
273
- }
274
- // For BSpline-BSpline, strict certification can reject true roots on noisy seeds.
275
- // Add a non-strict rescue pass as a recall-oriented fallback.
276
- if (ret.length === 0 && strictCertify) {
277
- const relaxedRescued = this.runRescuePass(c1, c2, pairTol, tol.seedParamTol, false);
278
- if (relaxedRescued.length > 0) {
279
- for (const hit of relaxedRescued) {
280
- this.pushUnique(ret, hit);
281
- }
282
- polylineDiagnostics.rescueHitCount += relaxedRescued.length;
283
- }
284
- }
285
- }
286
- if (hasBSpline && ret.length === 0) {
287
- const relaxed = this.runPolylineRelaxedFallback(c1, c2, pairTol, tol.seedParamTol);
288
- for (const hit of relaxed) {
289
- this.pushUnique(ret, hit);
290
- }
291
- }
292
- if (hasBSpline &&
293
- ret.length === 0 &&
294
- (pointSeeds.length > 0 || overlapSeeds.length > 0) &&
295
- minNearDistance <= pairTol * 0.2 &&
296
- refineFailureDelta >= 3) {
297
- polylineDiagnostics.certificationMissCount++;
298
- }
299
- return ret;
300
- }
301
- runPolylineRelaxedFallback(c1, c2, pointTol, seedParamTol) {
302
- const ret = [];
303
- const dense = Math.min(2048, Math.max(512, this.segmentsPerCurve * 2));
304
- const s1 = sampleCurveAdaptive(c1, dense, {
305
- chordErrorTol: pointTol * 1.5,
306
- maxSamples: dense * 8,
307
- });
308
- const s2 = sampleCurveAdaptive(c2, dense, {
309
- chordErrorTol: pointTol * 1.5,
310
- maxSamples: dense * 8,
311
- });
312
- if (s1.length < 2 || s2.length < 2)
313
- return ret;
314
- const seeds = [];
315
- const segs1 = this.buildSegments(s1);
316
- const segs2 = this.buildSegments(s2);
317
- const candidates = this.buildPairCandidates(segs1, segs2, pointTol * 4);
318
- for (const candidate of candidates) {
319
- const a = segs1[candidate.i];
320
- const b = segs2[candidate.j];
321
- const hit = intersectSegments(a.seg, b.seg);
322
- if (hit.kind === 'none')
323
- continue;
324
- if (hit.kind === 'point') {
325
- this.addPointSeed(seeds, lerp(a.u0, a.u1, hit.t1), lerp(b.u0, b.u1, hit.t2), seedParamTol * 4);
326
- continue;
327
- }
328
- this.addPointSeed(seeds, lerp(a.u0, a.u1, 0.5 * (hit.t1s + hit.t1e)), lerp(b.u0, b.u1, 0.5 * (hit.t2s + hit.t2e)), seedParamTol * 4);
329
- }
330
- for (const seed of seeds) {
331
- const refined = this.refinePair(c1, c2, seed.u1, seed.u2, pointTol, false);
332
- if (!refined)
333
- continue;
334
- this.pushUnique(ret, {
335
- point: refined.point,
336
- u1: refined.u1,
337
- u2: refined.u2,
338
- isOverlap: false,
339
- });
340
- }
341
- return ret;
342
- }
343
- buildSegments(samples) {
344
- const ret = [];
345
- for (let i = 0; i < samples.length - 1; i++) {
346
- const a = samples[i];
347
- const b = samples[i + 1];
348
- ret.push({
349
- u0: a.u,
350
- u1: b.u,
351
- seg: makeSegment(a.p, b.p),
352
- });
353
- }
354
- return ret;
355
- }
356
- addNearMissSeeds(seeds, a, b, paramTol) {
357
- this.addPointSeed(seeds, 0.5 * (a.u0 + a.u1), 0.5 * (b.u0 + b.u1), paramTol);
358
- }
359
- buildPairCandidates(segs1, segs2, pad) {
360
- if (segs1.length === 0 || segs2.length === 0)
361
- return [];
362
- const index = new SegmentHashIndex(segs2, pad);
363
- const marks = new Int32Array(segs2.length);
364
- const ret = [];
365
- let stamp = 1;
366
- for (let i = 0; i < segs1.length; i++) {
367
- const s1 = segs1[i];
368
- const js = index.query(s1, pad, marks, stamp++);
369
- if (stamp >= 0x7fffffff) {
370
- marks.fill(0);
371
- stamp = 1;
372
- }
373
- for (const j of js) {
374
- const s2 = segs2[j];
375
- if (!segmentBoxesMayIntersect(s1.seg, s2.seg, pad))
376
- continue;
377
- ret.push({ i, j });
378
- }
379
- }
380
- return ret;
381
- }
382
- addPointSeed(seeds, u1, u2, paramTol) {
383
- if (this.runPointSeedLimit > 0 && seeds.length >= this.runPointSeedLimit)
384
- return;
385
- for (const seed of seeds) {
386
- if (Math.abs(seed.u1 - u1) <= paramTol &&
387
- Math.abs(seed.u2 - u2) <= paramTol) {
388
- return;
389
- }
390
- }
391
- seeds.push({ u1, u2 });
392
- }
393
- addOverlapSeed(seeds, next) {
394
- for (let i = 0; i < seeds.length; i++) {
395
- const cur = seeds[i];
396
- const overlap1 = next.range1.intersect(cur.range1, Precision.CURVE_PARAM_EPS * 8);
397
- const overlap2 = next.range2.intersect(cur.range2, Precision.CURVE_PARAM_EPS * 8);
398
- if (overlap1.length === 0 || overlap2.length === 0)
399
- continue;
400
- seeds[i] = {
401
- range1: new Interval(Math.min(cur.range1.start, next.range1.start), Math.max(cur.range1.end, next.range1.end)),
402
- range2: new Interval(Math.min(cur.range2.start, next.range2.start), Math.max(cur.range2.end, next.range2.end)),
403
- };
404
- return;
405
- }
406
- if (this.runOverlapSeedLimit > 0 && seeds.length >= this.runOverlapSeedLimit)
407
- return;
408
- seeds.push(next);
409
- }
410
- refinePair(c1, c2, u1Seed, u2Seed, tol, strictCertify = false) {
411
- const newton = this.refineByNewton(c1, c2, u1Seed, u2Seed, tol);
412
- if (newton && newton.residual <= tol * 2) {
413
- if (!strictCertify) {
414
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, newton.residual);
415
- return newton;
416
- }
417
- const certified = certifyParamPair(c1, c2, newton, tol, (curve, p, t) => this.safeClosestPoint(curve, p, t));
418
- if (certified) {
419
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, certified.pair.residual);
420
- if (certified.usedDegenerateRescue)
421
- polylineDiagnostics.degenerateRescueCount++;
422
- return certified.pair;
423
- }
424
- polylineDiagnostics.certificationRejectCount++;
425
- }
426
- const proj = this.refineByProjection(c1, c2, newton?.u1 ?? u1Seed, newton?.u2 ?? u2Seed, tol);
427
- if (proj && proj.residual <= tol * 2) {
428
- if (!strictCertify) {
429
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, proj.residual);
430
- return proj;
431
- }
432
- const certified = certifyParamPair(c1, c2, proj, tol, (curve, p, t) => this.safeClosestPoint(curve, p, t));
433
- if (certified) {
434
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, certified.pair.residual);
435
- if (certified.usedDegenerateRescue)
436
- polylineDiagnostics.degenerateRescueCount++;
437
- return certified.pair;
438
- }
439
- polylineDiagnostics.certificationRejectCount++;
440
- }
441
- const best = this.pickBest(newton, proj);
442
- if (!best || best.residual > tol * 8) {
443
- polylineDiagnostics.refineFailureCount++;
444
- return undefined;
445
- }
446
- if (!strictCertify) {
447
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, best.residual);
448
- return best;
449
- }
450
- const certified = certifyParamPair(c1, c2, best, tol, (curve, p, t) => this.safeClosestPoint(curve, p, t));
451
- if (!certified) {
452
- polylineDiagnostics.certificationRejectCount++;
453
- polylineDiagnostics.refineFailureCount++;
454
- return undefined;
455
- }
456
- polylineDiagnostics.maxResidual = Math.max(polylineDiagnostics.maxResidual, certified.pair.residual);
457
- if (certified.usedDegenerateRescue)
458
- polylineDiagnostics.degenerateRescueCount++;
459
- return certified.pair;
460
- }
461
- refineByNewton(c1, c2, u1Seed, u2Seed, tol) {
462
- const r1 = c1.getRange();
463
- const r2 = c2.getRange();
464
- const span1 = Math.max(r1.length(), Precision.CURVE_PARAM_EPS);
465
- const span2 = Math.max(r2.length(), Precision.CURVE_PARAM_EPS);
466
- let u1 = r1.clamp(u1Seed);
467
- let u2 = r2.clamp(u2Seed);
468
- let best = this.measure(c1, c2, u1, u2);
469
- let lastDelta = Number.POSITIVE_INFINITY;
470
- for (let i = 0; i < this.maxNewtonIter; i++) {
471
- polylineDiagnostics.newtonIterationsTotal++;
472
- const p1 = c1.pointAt(u1);
473
- const p2 = c2.pointAt(u2);
474
- const diff = p1.subtracted(p2);
475
- if (diff.len() <= tol)
476
- return this.measure(c1, c2, u1, u2);
477
- const t1 = c1.tangentAt(u1);
478
- const t2 = c2.tangentAt(u2);
479
- const det = t1.cross(t2);
480
- if (Math.abs(det) <= Precision.CURVE_NEWTON_EPS) {
481
- break;
482
- }
483
- // [t1.x -t2.x; t1.y -t2.y] * [du, dv]^T = -diff
484
- const bx = -diff.x;
485
- const by = -diff.y;
486
- let du = (bx * (-t2.y) - by * (-t2.x)) / det;
487
- let dv = (t1.x * by - t1.y * bx) / det;
488
- if (!Number.isFinite(du) || !Number.isFinite(dv)) {
489
- break;
490
- }
491
- const limit1 = Math.max(span1 * 0.25, Precision.CURVE_PARAM_EPS * 8);
492
- const limit2 = Math.max(span2 * 0.25, Precision.CURVE_PARAM_EPS * 8);
493
- du = clamp(du, -limit1, limit1);
494
- dv = clamp(dv, -limit2, limit2);
495
- let nextU1 = r1.clamp(u1 + du);
496
- let nextU2 = r2.clamp(u2 + dv);
497
- let candidate = this.measure(c1, c2, nextU1, nextU2);
498
- // Damping if raw Newton step does not improve.
499
- if (candidate.residual > best.residual + tol * 0.2) {
500
- let accepted = false;
501
- for (let damp = 0; damp < 4; damp++) {
502
- const f = Math.pow(0.5, damp + 1);
503
- const dU1 = du * f;
504
- const dU2 = dv * f;
505
- nextU1 = r1.clamp(u1 + dU1);
506
- nextU2 = r2.clamp(u2 + dU2);
507
- candidate = this.measure(c1, c2, nextU1, nextU2);
508
- if (candidate.residual <= best.residual + tol * 0.1) {
509
- accepted = true;
510
- break;
511
- }
512
- }
513
- if (!accepted && candidate.residual > best.residual + tol * 0.25) {
514
- break;
515
- }
516
- }
517
- const delta = Math.abs(nextU1 - u1) + Math.abs(nextU2 - u2);
518
- u1 = nextU1;
519
- u2 = nextU2;
520
- if (candidate.residual < best.residual)
521
- best = candidate;
522
- if (delta <= Precision.CURVE_PARAM_EPS * 8) {
523
- break;
524
- }
525
- if (delta >= lastDelta - Precision.CURVE_PARAM_EPS * 8) {
526
- break;
527
- }
528
- lastDelta = delta;
529
- }
530
- const final = this.measure(c1, c2, u1, u2);
531
- return this.pickBest(best, final);
532
- }
533
- refineByProjection(c1, c2, u1Seed, u2Seed, tol) {
534
- const r1 = c1.getRange();
535
- const r2 = c2.getRange();
536
- let u1 = r1.clamp(u1Seed);
537
- let u2 = r2.clamp(u2Seed);
538
- let best = this.measure(c1, c2, u1, u2);
539
- for (let i = 0; i < this.maxNewtonIter; i++) {
540
- polylineDiagnostics.projectionIterationsTotal++;
541
- const p1 = c1.pointAt(u1);
542
- const cp2 = this.safeClosestPoint(c2, p1, tol);
543
- if (!cp2)
544
- break;
545
- const nextU2 = r2.clamp(cp2.param);
546
- const p2 = c2.pointAt(nextU2);
547
- const cp1 = this.safeClosestPoint(c1, p2, tol);
548
- if (!cp1)
549
- break;
550
- const nextU1 = r1.clamp(cp1.param);
551
- const candidate = this.measure(c1, c2, nextU1, nextU2);
552
- if (candidate.residual < best.residual)
553
- best = candidate;
554
- if (candidate.residual <= tol)
555
- return candidate;
556
- const du = Math.abs(nextU1 - u1);
557
- const dv = Math.abs(nextU2 - u2);
558
- u1 = nextU1;
559
- u2 = nextU2;
560
- if (du + dv <= Precision.CURVE_PARAM_EPS * 8)
561
- break;
562
- }
563
- return best;
564
- }
565
- runRescuePass(c1, c2, pointTol, seedParamTol, strictCertify) {
566
- polylineDiagnostics.rescuePassCount++;
567
- const ret = [];
568
- const seeds = [];
569
- const r1 = c1.getRange();
570
- const r2 = c2.getRange();
571
- const baseSamples = Math.max(24, Math.min(96, Math.floor(this.segmentsPerCurve / 2)));
572
- for (let i = 0; i <= baseSamples; i++) {
573
- const t = i / baseSamples;
574
- const u1 = r1.start + (r1.end - r1.start) * t;
575
- const p1 = c1.pointAt(u1);
576
- const cp2 = this.safeClosestPoint(c2, p1, pointTol * 3);
577
- if (!cp2 || cp2.distance > pointTol * 2.5)
578
- continue;
579
- this.addPointSeed(seeds, u1, r2.clamp(cp2.param), seedParamTol);
580
- }
581
- for (let i = 0; i <= baseSamples; i++) {
582
- const t = i / baseSamples;
583
- const u2 = r2.start + (r2.end - r2.start) * t;
584
- const p2 = c2.pointAt(u2);
585
- const cp1 = this.safeClosestPoint(c1, p2, pointTol * 3);
586
- if (!cp1 || cp1.distance > pointTol * 2.5)
587
- continue;
588
- this.addPointSeed(seeds, r1.clamp(cp1.param), u2, seedParamTol);
589
- }
590
- polylineDiagnostics.rescueSeedCount += seeds.length;
591
- for (const seed of seeds) {
592
- const refined = this.refinePair(c1, c2, seed.u1, seed.u2, pointTol, strictCertify);
593
- if (!refined)
594
- continue;
595
- this.pushUnique(ret, {
596
- point: refined.point,
597
- u1: refined.u1,
598
- u2: refined.u2,
599
- isOverlap: false,
600
- });
601
- }
602
- return ret;
603
- }
604
- measure(c1, c2, u1, u2) {
605
- const p1 = c1.pointAt(u1);
606
- const p2 = c2.pointAt(u2);
607
- return {
608
- u1,
609
- u2,
610
- point: p1.added(p2).scale(0.5),
611
- residual: p1.distanceTo(p2),
612
- };
613
- }
614
- refineOverlap(c1, c2, overlap, tol, paramTol) {
615
- const midU1 = 0.5 * (overlap.range1.start + overlap.range1.end);
616
- const midU2 = 0.5 * (overlap.range2.start + overlap.range2.end);
617
- const mid = this.refinePair(c1, c2, midU1, midU2, tol, false);
618
- if (!mid)
619
- return undefined;
620
- const range2 = projectRangeToCurve(c1, c2, overlap.range1, tol, (curve, p, t) => this.safeClosestPoint(curve, p, t));
621
- if (!range2)
622
- return undefined;
623
- if (overlap.range1.length() <= paramTol || range2.length() <= paramTol) {
624
- return {
625
- point: mid.point,
626
- u1: mid.u1,
627
- u2: mid.u2,
628
- isOverlap: false,
629
- };
630
- }
631
- const quality = certifyOverlapMonotone(c1, c2, overlap.range1, tol, paramTol, (curve, p, t) => this.safeClosestPoint(curve, p, t));
632
- if (!quality) {
633
- return {
634
- point: mid.point,
635
- u1: mid.u1,
636
- u2: mid.u2,
637
- isOverlap: false,
638
- };
639
- }
640
- return {
641
- point: mid.point,
642
- u1: mid.u1,
643
- u2: mid.u2,
644
- isOverlap: true,
645
- range1: overlap.range1,
646
- range2,
647
- };
648
- }
649
- safeClosestPoint(curve, p, tol) {
650
- try {
651
- return curve.closestPoint(p, tol);
652
- }
653
- catch {
654
- polylineDiagnostics.numericClosestFallbackCount++;
655
- return this.sampleClosestPoint(curve, p, 48);
656
- }
657
- }
658
- sampleClosestPoint(curve, p, sampleCount) {
659
- const range = curve.getRange();
660
- let bestParam = range.start;
661
- let bestPoint = curve.pointAt(bestParam);
662
- let bestDist = bestPoint.distanceTo(p);
663
- const total = Math.max(8, sampleCount);
664
- for (let i = 1; i <= total; i++) {
665
- const t = i / total;
666
- const u = range.start + (range.end - range.start) * t;
667
- const q = curve.pointAt(u);
668
- const d = q.distanceTo(p);
669
- if (d < bestDist) {
670
- bestDist = d;
671
- bestPoint = q;
672
- bestParam = u;
673
- }
674
- }
675
- // Local Newton refinement around sampled best parameter.
676
- let u = bestParam;
677
- for (let i = 0; i < 12; i++) {
678
- const cp = curve.pointAt(u).subtracted(p);
679
- const d1 = curve.derivativeAt(u, 1);
680
- const d2 = curve.derivativeAt(u, 2);
681
- const f = cp.dot(d1);
682
- const fp = d1.dot(d1) + cp.dot(d2);
683
- if (!Number.isFinite(f) || !Number.isFinite(fp) || Math.abs(fp) <= Precision.CURVE_NEWTON_EPS)
684
- break;
685
- const next = range.clamp(u - f / fp);
686
- if (Math.abs(next - u) <= Precision.CURVE_PARAM_EPS * 4) {
687
- u = next;
688
- break;
689
- }
690
- u = next;
691
- }
692
- bestParam = u;
693
- bestPoint = curve.pointAt(bestParam);
694
- bestDist = bestPoint.distanceTo(p);
695
- return {
696
- point: bestPoint,
697
- param: bestParam,
698
- distance: bestDist,
699
- };
700
- }
701
- pickBest(a, b) {
702
- if (!a)
703
- return b;
704
- if (!b)
705
- return a;
706
- return a.residual <= b.residual ? a : b;
707
- }
708
- pushUnique(out, next) {
709
- for (const item of out) {
710
- if (Math.abs(item.u1 - next.u1) <= Precision.CURVE_PARAM_EPS * 8 &&
711
- Math.abs(item.u2 - next.u2) <= Precision.CURVE_PARAM_EPS * 8 &&
712
- item.point.distanceTo(next.point) <= Precision.CURVE_LENGTH_EPS * 4 &&
713
- item.isOverlap === next.isOverlap) {
714
- return;
715
- }
716
- }
717
- out.push(next);
718
- }
719
- recursiveMaxNodes(c1, c2) {
720
- const heavy = c1.isBSpline() || c2.isBSpline() || c1.isEllipseArc() || c2.isEllipseArc();
721
- return heavy
722
- ? Math.max(5000, this.segmentsPerCurve * 28)
723
- : Math.max(2500, this.segmentsPerCurve * 16);
724
- }
725
- }
726
- function clamp(x, min, max) {
727
- return Math.min(max, Math.max(min, x));
728
- }
729
- function clampInt(x, min, max) {
730
- return Math.min(max, Math.max(min, x | 0));
731
- }