@faicad/faijs 0.16.0 → 0.17.0

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 (490) hide show
  1. package/LICENSE +4 -5
  2. package/NOTICE +5 -6
  3. package/dist/api/api-namespace.d.ts.map +1 -1
  4. package/dist/api/api-namespace.js +19 -1
  5. package/dist/api/api-namespace.js.map +1 -1
  6. package/dist/api/assembly/entities.d.ts +1 -1
  7. package/dist/api/assembly/entities.d.ts.map +1 -1
  8. package/dist/api/assembly/entities.js.map +1 -1
  9. package/dist/api/assembly/joints.d.ts +2 -2
  10. package/dist/api/assembly/joints.d.ts.map +1 -1
  11. package/dist/api/assembly/joints.js +2 -2
  12. package/dist/api/assembly/joints.js.map +1 -1
  13. package/dist/api/assembly/lower.d.ts +1 -1
  14. package/dist/api/assembly/lower.d.ts.map +1 -1
  15. package/dist/api/assembly/lower.js.map +1 -1
  16. package/dist/api/assembly/pose.d.ts +3 -3
  17. package/dist/api/assembly/pose.d.ts.map +1 -1
  18. package/dist/api/assembly/pose.js +1 -1
  19. package/dist/api/assembly/pose.js.map +1 -1
  20. package/dist/api/assembly/preview.d.ts +1 -1
  21. package/dist/api/assembly/preview.d.ts.map +1 -1
  22. package/dist/api/assembly/preview.js +1 -1
  23. package/dist/api/assembly/preview.js.map +1 -1
  24. package/dist/api/assembly/solve.d.ts.map +1 -1
  25. package/dist/api/assembly/solve.js +3 -3
  26. package/dist/api/assembly/solve.js.map +1 -1
  27. package/dist/api/assembly/solvers/assembly-tree.d.ts +98 -0
  28. package/dist/api/assembly/solvers/assembly-tree.d.ts.map +1 -0
  29. package/dist/api/assembly/solvers/assembly-tree.js +130 -0
  30. package/dist/api/assembly/solvers/assembly-tree.js.map +1 -0
  31. package/dist/api/assembly/solvers/chain-solver.d.ts +27 -0
  32. package/dist/api/assembly/solvers/chain-solver.d.ts.map +1 -0
  33. package/dist/api/assembly/solvers/chain-solver.js +330 -0
  34. package/dist/api/assembly/solvers/chain-solver.js.map +1 -0
  35. package/dist/api/assembly/solvers/global-solver.js +2 -2
  36. package/dist/api/assembly/solvers/global-solver.js.map +1 -1
  37. package/dist/api/assembly/solvers/joints-kinematics.d.ts +308 -0
  38. package/dist/api/assembly/solvers/joints-kinematics.d.ts.map +1 -0
  39. package/dist/api/assembly/solvers/joints-kinematics.js +643 -0
  40. package/dist/api/assembly/solvers/joints-kinematics.js.map +1 -0
  41. package/dist/api/assembly/solvers/quat.d.ts +35 -0
  42. package/dist/api/assembly/solvers/quat.d.ts.map +1 -0
  43. package/dist/api/assembly/solvers/quat.js +84 -0
  44. package/dist/api/assembly/solvers/quat.js.map +1 -0
  45. package/dist/api/assembly/solvers/types.d.ts +33 -0
  46. package/dist/api/assembly/solvers/types.d.ts.map +1 -1
  47. package/dist/api/assembly/solvers/types.js.map +1 -1
  48. package/dist/api/boolean.d.ts.map +1 -1
  49. package/dist/api/boolean.js +3 -4
  50. package/dist/api/boolean.js.map +1 -1
  51. package/dist/api/brep-mirror/booleanFns.d.ts +40 -0
  52. package/dist/api/brep-mirror/booleanFns.d.ts.map +1 -0
  53. package/dist/api/brep-mirror/booleanFns.js +99 -0
  54. package/dist/api/brep-mirror/booleanFns.js.map +1 -0
  55. package/dist/api/brep-mirror/brepHelpers.d.ts +55 -0
  56. package/dist/api/brep-mirror/brepHelpers.d.ts.map +1 -0
  57. package/dist/api/brep-mirror/brepHelpers.js +131 -0
  58. package/dist/api/brep-mirror/brepHelpers.js.map +1 -0
  59. package/dist/api/brep-mirror/compoundFns.d.ts +47 -0
  60. package/dist/api/brep-mirror/compoundFns.d.ts.map +1 -0
  61. package/dist/api/brep-mirror/compoundFns.js +300 -0
  62. package/dist/api/brep-mirror/compoundFns.js.map +1 -0
  63. package/dist/api/brep-mirror/healingFns.d.ts +78 -0
  64. package/dist/api/brep-mirror/healingFns.d.ts.map +1 -0
  65. package/dist/api/brep-mirror/healingFns.js +294 -0
  66. package/dist/api/brep-mirror/healingFns.js.map +1 -0
  67. package/dist/api/brep-mirror/hullFns.d.ts +20 -0
  68. package/dist/api/brep-mirror/hullFns.d.ts.map +1 -0
  69. package/dist/api/brep-mirror/hullFns.js +46 -0
  70. package/dist/api/brep-mirror/hullFns.js.map +1 -0
  71. package/dist/api/brep-mirror/patternFns.d.ts +43 -0
  72. package/dist/api/brep-mirror/patternFns.d.ts.map +1 -0
  73. package/dist/api/brep-mirror/patternFns.js +178 -0
  74. package/dist/api/brep-mirror/patternFns.js.map +1 -0
  75. package/dist/api/brep-mirror/primitiveFns.d.ts +42 -0
  76. package/dist/api/brep-mirror/primitiveFns.d.ts.map +1 -0
  77. package/dist/api/brep-mirror/primitiveFns.js +104 -0
  78. package/dist/api/brep-mirror/primitiveFns.js.map +1 -0
  79. package/dist/api/brep-mirror/roofFns.d.ts +24 -0
  80. package/dist/api/brep-mirror/roofFns.d.ts.map +1 -0
  81. package/dist/api/brep-mirror/roofFns.js +229 -0
  82. package/dist/api/brep-mirror/roofFns.js.map +1 -0
  83. package/dist/api/brep-mirror/straightSkeleton.d.ts +36 -0
  84. package/dist/api/brep-mirror/straightSkeleton.d.ts.map +1 -0
  85. package/dist/api/brep-mirror/straightSkeleton.js +443 -0
  86. package/dist/api/brep-mirror/straightSkeleton.js.map +1 -0
  87. package/dist/api/brep-mirror/sweepFns.d.ts +55 -0
  88. package/dist/api/brep-mirror/sweepFns.d.ts.map +1 -0
  89. package/dist/api/brep-mirror/sweepFns.js +200 -0
  90. package/dist/api/brep-mirror/sweepFns.js.map +1 -0
  91. package/dist/api/brep-mirror/threadFns.d.ts +15 -0
  92. package/dist/api/brep-mirror/threadFns.d.ts.map +1 -1
  93. package/dist/api/brep-mirror/threadFns.js +37 -2
  94. package/dist/api/brep-mirror/threadFns.js.map +1 -1
  95. package/dist/api/brep-mirror/topologyFns.d.ts +74 -0
  96. package/dist/api/brep-mirror/topologyFns.d.ts.map +1 -0
  97. package/dist/api/brep-mirror/topologyFns.js +273 -0
  98. package/dist/api/brep-mirror/topologyFns.js.map +1 -0
  99. package/dist/api/brep-topology.d.ts +190 -0
  100. package/dist/api/brep-topology.d.ts.map +1 -0
  101. package/dist/api/brep-topology.js +337 -0
  102. package/dist/api/brep-topology.js.map +1 -0
  103. package/dist/api/brepjs-compat/constants.d.ts +11 -0
  104. package/dist/api/brepjs-compat/constants.d.ts.map +1 -0
  105. package/dist/api/brepjs-compat/constants.js +11 -0
  106. package/dist/api/brepjs-compat/constants.js.map +1 -0
  107. package/dist/api/brepjs-compat/index.d.ts +19 -232
  108. package/dist/api/brepjs-compat/index.d.ts.map +1 -1
  109. package/dist/api/brepjs-compat/index.js +19 -286
  110. package/dist/api/brepjs-compat/index.js.map +1 -1
  111. package/dist/api/brepjs-compat/planeOps.d.ts +98 -0
  112. package/dist/api/brepjs-compat/planeOps.d.ts.map +1 -0
  113. package/dist/api/brepjs-compat/planeOps.js +170 -0
  114. package/dist/api/brepjs-compat/planeOps.js.map +1 -0
  115. package/dist/api/brepjs-compat/planeTypes.d.ts +24 -0
  116. package/dist/api/brepjs-compat/planeTypes.d.ts.map +1 -0
  117. package/dist/api/brepjs-compat/planeTypes.js +8 -0
  118. package/dist/api/brepjs-compat/planeTypes.js.map +1 -0
  119. package/dist/api/brepjs-compat/types.d.ts +64 -0
  120. package/dist/api/brepjs-compat/types.d.ts.map +1 -0
  121. package/dist/api/brepjs-compat/types.js +48 -0
  122. package/dist/api/brepjs-compat/types.js.map +1 -0
  123. package/dist/api/brepjs-compat/vecOps.d.ts +124 -0
  124. package/dist/api/brepjs-compat/vecOps.d.ts.map +1 -0
  125. package/dist/api/brepjs-compat/vecOps.js +202 -0
  126. package/dist/api/brepjs-compat/vecOps.js.map +1 -0
  127. package/dist/api/chamfer.d.ts +5 -0
  128. package/dist/api/chamfer.d.ts.map +1 -1
  129. package/dist/api/chamfer.js +13 -8
  130. package/dist/api/chamfer.js.map +1 -1
  131. package/dist/api/compound-geom.d.ts.map +1 -1
  132. package/dist/api/compound-geom.js +8 -2
  133. package/dist/api/compound-geom.js.map +1 -1
  134. package/dist/api/draft.d.ts +69 -0
  135. package/dist/api/draft.d.ts.map +1 -0
  136. package/dist/api/draft.js +109 -0
  137. package/dist/api/draft.js.map +1 -0
  138. package/dist/api/edge-ref.d.ts.map +1 -1
  139. package/dist/api/edge-ref.js +2 -2
  140. package/dist/api/edge-ref.js.map +1 -1
  141. package/dist/api/engrave.d.ts.map +1 -1
  142. package/dist/api/engrave.js +2 -3
  143. package/dist/api/engrave.js.map +1 -1
  144. package/dist/api/extrude.d.ts.map +1 -1
  145. package/dist/api/extrude.js +28 -13
  146. package/dist/api/extrude.js.map +1 -1
  147. package/dist/api/face-ref.d.ts.map +1 -1
  148. package/dist/api/face-ref.js +2 -2
  149. package/dist/api/face-ref.js.map +1 -1
  150. package/dist/api/feature-repair.d.ts +137 -0
  151. package/dist/api/feature-repair.d.ts.map +1 -0
  152. package/dist/api/feature-repair.js +221 -0
  153. package/dist/api/feature-repair.js.map +1 -0
  154. package/dist/api/fillet-variable.d.ts +35 -0
  155. package/dist/api/fillet-variable.d.ts.map +1 -0
  156. package/dist/api/fillet-variable.js +71 -0
  157. package/dist/api/fillet-variable.js.map +1 -0
  158. package/dist/api/fillet.d.ts +3 -0
  159. package/dist/api/fillet.d.ts.map +1 -1
  160. package/dist/api/fillet.js +7 -4
  161. package/dist/api/fillet.js.map +1 -1
  162. package/dist/api/generated/2d.d.ts +1 -13
  163. package/dist/api/generated/2d.d.ts.map +1 -1
  164. package/dist/api/generated/2d.js +6 -1
  165. package/dist/api/generated/2d.js.map +1 -1
  166. package/dist/api/generated/brepjs/index.d.ts +298 -298
  167. package/dist/api/generated/brepjs/index.d.ts.map +1 -1
  168. package/dist/api/generated/brepjs/index.js +183 -183
  169. package/dist/api/generated/brepjs/index.js.map +1 -1
  170. package/dist/api/generated/core.d.ts +3 -123
  171. package/dist/api/generated/core.d.ts.map +1 -1
  172. package/dist/api/generated/core.js +2 -81
  173. package/dist/api/generated/core.js.map +1 -1
  174. package/dist/api/generated/gear.d.ts +1 -15
  175. package/dist/api/generated/gear.d.ts.map +1 -1
  176. package/dist/api/generated/gear.js +6 -3
  177. package/dist/api/generated/gear.js.map +1 -1
  178. package/dist/api/generated/io.d.ts +1 -13
  179. package/dist/api/generated/io.d.ts.map +1 -1
  180. package/dist/api/generated/io.js +6 -1
  181. package/dist/api/generated/io.js.map +1 -1
  182. package/dist/api/generated/kernel.d.ts +1 -39
  183. package/dist/api/generated/kernel.d.ts.map +1 -1
  184. package/dist/api/generated/kernel.js +6 -4
  185. package/dist/api/generated/kernel.js.map +1 -1
  186. package/dist/api/generated/measurement.d.ts +53 -97
  187. package/dist/api/generated/measurement.d.ts.map +1 -1
  188. package/dist/api/generated/measurement.js +48 -143
  189. package/dist/api/generated/measurement.js.map +1 -1
  190. package/dist/api/generated/ns.d.ts +1 -10
  191. package/dist/api/generated/ns.d.ts.map +1 -1
  192. package/dist/api/generated/ns.js +2 -10
  193. package/dist/api/generated/ns.js.map +1 -1
  194. package/dist/api/generated/operations.d.ts +65 -110
  195. package/dist/api/generated/operations.d.ts.map +1 -1
  196. package/dist/api/generated/operations.js +132 -80
  197. package/dist/api/generated/operations.js.map +1 -1
  198. package/dist/api/generated/projection.d.ts +1 -8
  199. package/dist/api/generated/projection.d.ts.map +1 -1
  200. package/dist/api/generated/projection.js +6 -4
  201. package/dist/api/generated/projection.js.map +1 -1
  202. package/dist/api/generated/query.d.ts +1 -9
  203. package/dist/api/generated/query.d.ts.map +1 -1
  204. package/dist/api/generated/query.js +6 -1
  205. package/dist/api/generated/query.js.map +1 -1
  206. package/dist/api/generated/script-face-manifest.d.ts +2 -0
  207. package/dist/api/generated/script-face-manifest.d.ts.map +1 -1
  208. package/dist/api/generated/script-face-manifest.js +34 -22
  209. package/dist/api/generated/script-face-manifest.js.map +1 -1
  210. package/dist/api/generated/script-face.d.ts +52 -27
  211. package/dist/api/generated/script-face.d.ts.map +1 -1
  212. package/dist/api/generated/script-face.js +18 -4
  213. package/dist/api/generated/script-face.js.map +1 -1
  214. package/dist/api/generated/sketching.d.ts +4 -7
  215. package/dist/api/generated/sketching.d.ts.map +1 -1
  216. package/dist/api/generated/sketching.js +10 -8
  217. package/dist/api/generated/sketching.js.map +1 -1
  218. package/dist/api/generated/text.d.ts +1 -6
  219. package/dist/api/generated/text.d.ts.map +1 -1
  220. package/dist/api/generated/text.js +6 -3
  221. package/dist/api/generated/text.js.map +1 -1
  222. package/dist/api/generated/topology.d.ts +77 -175
  223. package/dist/api/generated/topology.d.ts.map +1 -1
  224. package/dist/api/generated/topology.js +172 -131
  225. package/dist/api/generated/topology.js.map +1 -1
  226. package/dist/api/geom.d.ts.map +1 -1
  227. package/dist/api/geom.js +2 -2
  228. package/dist/api/geom.js.map +1 -1
  229. package/dist/api/helix.d.ts +51 -0
  230. package/dist/api/helix.d.ts.map +1 -0
  231. package/dist/api/helix.js +63 -0
  232. package/dist/api/helix.js.map +1 -0
  233. package/dist/api/import-step.d.ts.map +1 -1
  234. package/dist/api/import-step.js +6 -2
  235. package/dist/api/import-step.js.map +1 -1
  236. package/dist/api/index.d.ts +18 -5
  237. package/dist/api/index.d.ts.map +1 -1
  238. package/dist/api/index.js +29 -12
  239. package/dist/api/index.js.map +1 -1
  240. package/dist/api/internal/compat-op.d.ts +10 -0
  241. package/dist/api/internal/compat-op.d.ts.map +1 -1
  242. package/dist/api/internal/compat-op.js +9 -3
  243. package/dist/api/internal/compat-op.js.map +1 -1
  244. package/dist/api/internal/compat-projection.d.ts +4 -4
  245. package/dist/api/internal/compat-projection.js +7 -7
  246. package/dist/api/internal/compat-projection.js.map +1 -1
  247. package/dist/api/internal/l3-bridge.d.ts +75 -42
  248. package/dist/api/internal/l3-bridge.d.ts.map +1 -1
  249. package/dist/api/internal/l3-bridge.js +105 -50
  250. package/dist/api/internal/l3-bridge.js.map +1 -1
  251. package/dist/api/internal/profile-wire.d.ts +31 -0
  252. package/dist/api/internal/profile-wire.d.ts.map +1 -0
  253. package/dist/api/internal/profile-wire.js +37 -0
  254. package/dist/api/internal/profile-wire.js.map +1 -0
  255. package/dist/api/internal/replica-role-table.js +2 -2
  256. package/dist/api/internal/replica-role-table.js.map +1 -1
  257. package/dist/api/loft.d.ts +66 -0
  258. package/dist/api/loft.d.ts.map +1 -0
  259. package/dist/api/loft.js +111 -0
  260. package/dist/api/loft.js.map +1 -0
  261. package/dist/api/measurement/index.d.ts +51 -0
  262. package/dist/api/measurement/index.d.ts.map +1 -0
  263. package/dist/api/measurement/index.js +71 -0
  264. package/dist/api/measurement/index.js.map +1 -0
  265. package/dist/api/occt-kernel-bridge.d.ts +5 -8
  266. package/dist/api/occt-kernel-bridge.d.ts.map +1 -1
  267. package/dist/api/occt-kernel-bridge.js +18 -14
  268. package/dist/api/occt-kernel-bridge.js.map +1 -1
  269. package/dist/api/pattern.d.ts.map +1 -1
  270. package/dist/api/pattern.js +3 -4
  271. package/dist/api/pattern.js.map +1 -1
  272. package/dist/api/place.d.ts.map +1 -1
  273. package/dist/api/place.js +2 -4
  274. package/dist/api/place.js.map +1 -1
  275. package/dist/api/primitives.d.ts.map +1 -1
  276. package/dist/api/primitives.js +3 -4
  277. package/dist/api/primitives.js.map +1 -1
  278. package/dist/api/replicate.d.ts +28 -1
  279. package/dist/api/replicate.d.ts.map +1 -1
  280. package/dist/api/replicate.js +29 -19
  281. package/dist/api/replicate.js.map +1 -1
  282. package/dist/api/result.d.ts +6 -11
  283. package/dist/api/result.d.ts.map +1 -1
  284. package/dist/api/result.js +6 -11
  285. package/dist/api/result.js.map +1 -1
  286. package/dist/api/revolve.d.ts.map +1 -1
  287. package/dist/api/revolve.js +15 -14
  288. package/dist/api/revolve.js.map +1 -1
  289. package/dist/api/screw.d.ts +3 -0
  290. package/dist/api/screw.d.ts.map +1 -1
  291. package/dist/api/screw.js +9 -4
  292. package/dist/api/screw.js.map +1 -1
  293. package/dist/api/sdf.d.ts +1 -1
  294. package/dist/api/section-by-plane.d.ts +42 -0
  295. package/dist/api/section-by-plane.d.ts.map +1 -0
  296. package/dist/api/section-by-plane.js +61 -0
  297. package/dist/api/section-by-plane.js.map +1 -0
  298. package/dist/api/shell.d.ts +45 -0
  299. package/dist/api/shell.d.ts.map +1 -0
  300. package/dist/api/shell.js +73 -0
  301. package/dist/api/shell.js.map +1 -0
  302. package/dist/api/sketch.d.ts +8 -1
  303. package/dist/api/sketch.d.ts.map +1 -1
  304. package/dist/api/sketch.js +12 -7
  305. package/dist/api/sketch.js.map +1 -1
  306. package/dist/api/split-by-plane.d.ts +41 -0
  307. package/dist/api/split-by-plane.d.ts.map +1 -0
  308. package/dist/api/split-by-plane.js +60 -0
  309. package/dist/api/split-by-plane.js.map +1 -0
  310. package/dist/api/split.d.ts +6 -1
  311. package/dist/api/split.d.ts.map +1 -1
  312. package/dist/api/split.js +23 -9
  313. package/dist/api/split.js.map +1 -1
  314. package/dist/api/surface/arg-spec.d.ts +22 -0
  315. package/dist/api/surface/arg-spec.d.ts.map +1 -1
  316. package/dist/api/surface/arg-spec.js +723 -476
  317. package/dist/api/surface/arg-spec.js.map +1 -1
  318. package/dist/api/sweep.d.ts +55 -0
  319. package/dist/api/sweep.d.ts.map +1 -0
  320. package/dist/api/sweep.js +86 -0
  321. package/dist/api/sweep.js.map +1 -0
  322. package/dist/api/thicken.d.ts +36 -0
  323. package/dist/api/thicken.d.ts.map +1 -0
  324. package/dist/api/thicken.js +55 -0
  325. package/dist/api/thicken.js.map +1 -0
  326. package/dist/api/transform.d.ts +8 -0
  327. package/dist/api/transform.d.ts.map +1 -1
  328. package/dist/api/transform.js +15 -4
  329. package/dist/api/transform.js.map +1 -1
  330. package/dist/api/view/cameraFns.d.ts +48 -0
  331. package/dist/api/view/cameraFns.d.ts.map +1 -0
  332. package/dist/api/view/cameraFns.js +75 -0
  333. package/dist/api/view/cameraFns.js.map +1 -0
  334. package/dist/api/view/projectionPlanes.d.ts +25 -0
  335. package/dist/api/view/projectionPlanes.d.ts.map +1 -0
  336. package/dist/api/view/projectionPlanes.js +30 -0
  337. package/dist/api/view/projectionPlanes.js.map +1 -0
  338. package/dist/api/view/view-camera.d.ts +2 -2
  339. package/dist/api/view/view-camera.d.ts.map +1 -1
  340. package/dist/api/view/view-camera.js +3 -3
  341. package/dist/api/view/view-camera.js.map +1 -1
  342. package/dist/api/view/view-projection.d.ts +9 -6
  343. package/dist/api/view/view-projection.d.ts.map +1 -1
  344. package/dist/api/view/view-projection.js +132 -65
  345. package/dist/api/view/view-projection.js.map +1 -1
  346. package/dist/api/wire.d.ts +45 -0
  347. package/dist/api/wire.d.ts.map +1 -0
  348. package/dist/api/wire.js +96 -0
  349. package/dist/api/wire.js.map +1 -0
  350. package/dist/boolean/creased-normals.d.ts +50 -0
  351. package/dist/boolean/creased-normals.d.ts.map +1 -0
  352. package/dist/boolean/creased-normals.js +114 -0
  353. package/dist/boolean/creased-normals.js.map +1 -0
  354. package/dist/boolean/deriveNormals.d.ts +4 -1
  355. package/dist/boolean/deriveNormals.d.ts.map +1 -1
  356. package/dist/boolean/deriveNormals.js +5 -2
  357. package/dist/boolean/deriveNormals.js.map +1 -1
  358. package/dist/brep/brep-ops.d.ts +6 -0
  359. package/dist/brep/brep-ops.d.ts.map +1 -1
  360. package/dist/brep/brep-ops.js +11 -2
  361. package/dist/brep/brep-ops.js.map +1 -1
  362. package/dist/brep/brep-topology.d.ts +4 -0
  363. package/dist/brep/brep-topology.d.ts.map +1 -1
  364. package/dist/brep/brep-topology.js +4 -0
  365. package/dist/brep/brep-topology.js.map +1 -1
  366. package/dist/brep/engine/adapters/brep-mock.d.ts.map +1 -1
  367. package/dist/brep/engine/adapters/brep-mock.js +79 -59
  368. package/dist/brep/engine/adapters/brep-mock.js.map +1 -1
  369. package/dist/brep/engine/adapters/brepkit.d.ts.map +1 -1
  370. package/dist/brep/engine/adapters/brepkit.js +7 -1
  371. package/dist/brep/engine/adapters/brepkit.js.map +1 -1
  372. package/dist/brep/engine/adapters/occt.d.ts +15 -7
  373. package/dist/brep/engine/adapters/occt.d.ts.map +1 -1
  374. package/dist/brep/engine/adapters/occt.js +52 -167
  375. package/dist/brep/engine/adapters/occt.js.map +1 -1
  376. package/dist/brep/engine/primitives.d.ts +93 -130
  377. package/dist/brep/engine/primitives.d.ts.map +1 -1
  378. package/dist/brep/engine/primitives.js +9 -7
  379. package/dist/brep/engine/primitives.js.map +1 -1
  380. package/dist/brep/engine/types.d.ts +14 -1
  381. package/dist/brep/engine/types.d.ts.map +1 -1
  382. package/dist/brep/engine/types.js +11 -1
  383. package/dist/brep/engine/types.js.map +1 -1
  384. package/dist/brep/export/step.d.ts +3 -0
  385. package/dist/brep/export/step.d.ts.map +1 -1
  386. package/dist/brep/export/step.js +7 -1
  387. package/dist/brep/export/step.js.map +1 -1
  388. package/dist/brep/face-evolution.d.ts +8 -0
  389. package/dist/brep/face-evolution.d.ts.map +1 -1
  390. package/dist/brep/face-evolution.js +15 -3
  391. package/dist/brep/face-evolution.js.map +1 -1
  392. package/dist/brep/handle-bridge.d.ts +20 -2
  393. package/dist/brep/handle-bridge.d.ts.map +1 -1
  394. package/dist/brep/handle-bridge.js +25 -2
  395. package/dist/brep/handle-bridge.js.map +1 -1
  396. package/dist/brepkit-kernel/brepkitKernel.d.ts +25 -5
  397. package/dist/brepkit-kernel/brepkitKernel.d.ts.map +1 -1
  398. package/dist/brepkit-kernel/brepkitKernel.js +336 -144
  399. package/dist/brepkit-kernel/brepkitKernel.js.map +1 -1
  400. package/dist/cad-runtime/admit-compat-lib.d.ts +6 -1
  401. package/dist/cad-runtime/admit-compat-lib.d.ts.map +1 -1
  402. package/dist/cad-runtime/admit-compat-lib.js +5 -1
  403. package/dist/cad-runtime/admit-compat-lib.js.map +1 -1
  404. package/dist/cad-runtime/backend-dispatch.d.ts +9 -3
  405. package/dist/cad-runtime/backend-dispatch.d.ts.map +1 -1
  406. package/dist/cad-runtime/backend-dispatch.js +32 -2
  407. package/dist/cad-runtime/backend-dispatch.js.map +1 -1
  408. package/dist/cad-runtime/direct-executor.d.ts.map +1 -1
  409. package/dist/cad-runtime/direct-executor.js +8 -2
  410. package/dist/cad-runtime/direct-executor.js.map +1 -1
  411. package/dist/cad-runtime/runtime.d.ts +3 -0
  412. package/dist/cad-runtime/runtime.d.ts.map +1 -1
  413. package/dist/cad-runtime/runtime.js +3 -1
  414. package/dist/cad-runtime/runtime.js.map +1 -1
  415. package/dist/define-op.d.ts +18 -2
  416. package/dist/define-op.d.ts.map +1 -1
  417. package/dist/define-op.js +29 -1
  418. package/dist/define-op.js.map +1 -1
  419. package/dist/env-agnostic.d.ts +3 -0
  420. package/dist/env-agnostic.d.ts.map +1 -1
  421. package/dist/env-agnostic.js +7 -0
  422. package/dist/env-agnostic.js.map +1 -1
  423. package/dist/index.d.ts.map +1 -1
  424. package/dist/index.js +3 -4
  425. package/dist/index.js.map +1 -1
  426. package/dist/lang/symbol-table.generated.d.ts +28 -0
  427. package/dist/lang/symbol-table.generated.d.ts.map +1 -1
  428. package/dist/lang/symbol-table.generated.js +29 -1
  429. package/dist/lang/symbol-table.generated.js.map +1 -1
  430. package/dist/occt-kernel/highLevelApi.d.ts.map +1 -1
  431. package/dist/occt-kernel/highLevelApi.js +6 -3
  432. package/dist/occt-kernel/highLevelApi.js.map +1 -1
  433. package/dist/occt-kernel/hullGeometry.d.ts +31 -0
  434. package/dist/occt-kernel/hullGeometry.d.ts.map +1 -0
  435. package/dist/occt-kernel/hullGeometry.js +319 -0
  436. package/dist/occt-kernel/hullGeometry.js.map +1 -0
  437. package/dist/occt-kernel/hullOps.d.ts +24 -0
  438. package/dist/occt-kernel/hullOps.d.ts.map +1 -0
  439. package/dist/occt-kernel/hullOps.js +52 -0
  440. package/dist/occt-kernel/hullOps.js.map +1 -0
  441. package/dist/occt-kernel/occt-primitives.d.ts +14 -0
  442. package/dist/occt-kernel/occt-primitives.d.ts.map +1 -0
  443. package/dist/occt-kernel/occt-primitives.js +351 -0
  444. package/dist/occt-kernel/occt-primitives.js.map +1 -0
  445. package/dist/occt-kernel/occtKernel.d.ts +14 -6
  446. package/dist/occt-kernel/occtKernel.d.ts.map +1 -1
  447. package/dist/occt-kernel/occtKernel.js +11 -3
  448. package/dist/occt-kernel/occtKernel.js.map +1 -1
  449. package/dist/occt-kernel/topologyExt.js +2 -2
  450. package/dist/occt-kernel/topologyExt.js.map +1 -1
  451. package/dist/primitives/brep-primitives.d.ts +4 -0
  452. package/dist/primitives/brep-primitives.d.ts.map +1 -1
  453. package/dist/primitives/brep-primitives.js +4 -0
  454. package/dist/primitives/brep-primitives.js.map +1 -1
  455. package/dist/result/bug.d.ts +22 -0
  456. package/dist/result/bug.d.ts.map +1 -0
  457. package/dist/result/bug.js +28 -0
  458. package/dist/result/bug.js.map +1 -0
  459. package/dist/result/errors.d.ts +270 -0
  460. package/dist/result/errors.d.ts.map +1 -0
  461. package/dist/result/errors.js +317 -0
  462. package/dist/result/errors.js.map +1 -0
  463. package/dist/result/kernelErrorTranslation.d.ts +21 -0
  464. package/dist/result/kernelErrorTranslation.d.ts.map +1 -0
  465. package/dist/result/kernelErrorTranslation.js +102 -0
  466. package/dist/result/kernelErrorTranslation.js.map +1 -0
  467. package/dist/result/result.d.ts +213 -0
  468. package/dist/result/result.d.ts.map +1 -0
  469. package/dist/result/result.js +336 -0
  470. package/dist/result/result.js.map +1 -0
  471. package/dist/result/vec3.d.ts +12 -0
  472. package/dist/result/vec3.d.ts.map +1 -0
  473. package/dist/result/vec3.js +14 -0
  474. package/dist/result/vec3.js.map +1 -0
  475. package/dist/runtime-state.d.ts +9 -0
  476. package/dist/runtime-state.d.ts.map +1 -1
  477. package/dist/runtime-state.js.map +1 -1
  478. package/dist/sdk.d.ts +3 -1
  479. package/dist/sdk.d.ts.map +1 -1
  480. package/dist/sdk.js +2 -1
  481. package/dist/sdk.js.map +1 -1
  482. package/dist/shape.d.ts +43 -1
  483. package/dist/shape.d.ts.map +1 -1
  484. package/dist/shape.js +57 -1
  485. package/dist/shape.js.map +1 -1
  486. package/dist/topology/naming/geom-hint.js +1 -1
  487. package/dist/topology/naming/geom-hint.js.map +1 -1
  488. package/dist/topology/naming/score.js +1 -1
  489. package/dist/topology/naming/score.js.map +1 -1
  490. package/package.json +6 -16
@@ -0,0 +1,643 @@
1
+ /**
2
+ * Kinematic joints + IK — core 自有实现(§5.6.3 移植:vendored jointFns + ikFns 逐字对齐)。
3
+ *
4
+ * 移植来源:packages/brepjs/src/operations/{jointFns,ikFns}.ts(纯算法零 kernel 依赖,
5
+ * 仅用 quat 与 assembly-tree;Phase 5 随 brepjs 包删除前已做 parity 对拍)。
6
+ */
7
+ import { quatFromAxisAngle, quatRotate, quatMultiply } from './quat.js';
8
+ import { walkAssembly } from './assembly-tree.js';
9
+ const DEG2RAD = Math.PI / 180;
10
+ // ---------------------------------------------------------------------------
11
+ // Construction
12
+ // ---------------------------------------------------------------------------
13
+ function clamp(value, min, max) {
14
+ return Math.min(max, Math.max(min, value));
15
+ }
16
+ function unit(v) {
17
+ const l = Math.hypot(v[0], v[1], v[2]) || 1;
18
+ return [v[0] / l, v[1] / l, v[2] / l];
19
+ }
20
+ function cross(a, b) {
21
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
22
+ }
23
+ /** A unit vector perpendicular to `v` (for the unspecified-reference case). */
24
+ function anyPerpendicular(v) {
25
+ const ref = Math.abs(v[0]) < 0.9 ? [1, 0, 0] : [0, 1, 0];
26
+ return unit(cross(v, ref));
27
+ }
28
+ /** Build one DOF, normalizing an inverted range and clamping the initial value. */
29
+ function makeDof(kind, axis, opts, defMin, defMax) {
30
+ // Normalize the range so an inverted (min > max) input can't break the
31
+ // "value is always within [min, max]" invariant.
32
+ const a = opts.min ?? defMin;
33
+ const b = opts.max ?? defMax;
34
+ const min = Math.min(a, b);
35
+ const max = Math.max(a, b);
36
+ return { kind, axis: unit(axis), min, max, value: clamp(opts.value ?? 0, min, max) };
37
+ }
38
+ /** Assemble a Joint from its DOFs, mirroring the primary DOF into the top level. */
39
+ function buildJoint(type, parent, child, axis, dofs) {
40
+ const primary = dofs[0] ?? { kind: 'rotation', axis: [0, 0, 1], min: 0, max: 0, value: 0 };
41
+ return {
42
+ type,
43
+ parent,
44
+ child,
45
+ axis: { origin: axis.origin, direction: unit(axis.direction) },
46
+ min: primary.min,
47
+ max: primary.max,
48
+ value: primary.value,
49
+ dofs,
50
+ };
51
+ }
52
+ /** A revolute (hinge) joint — the child rotates about `axis` by `value` degrees.
53
+ * @param parent - Name of the reference (parent) body.
54
+ * @param child - Name of the body moved by the joint.
55
+ * @param axis - Joint axis: anchor point and direction.
56
+ * @param opts - Optional range bounds and initial value.
57
+ * @returns The newly created revolute joint.
58
+ */
59
+ export function revoluteJoint(parent, child, axis, opts = {}) {
60
+ return buildJoint('revolute', parent, child, axis, [
61
+ makeDof('rotation', axis.direction, opts, -180, 180),
62
+ ]);
63
+ }
64
+ /**
65
+ * A prismatic (slider) joint — the child translates along `axis` by `value`
66
+ * units. Only `axis.direction` is used; `axis.origin` is ignored (a pure
67
+ * translation has no anchor point), unlike a revolute joint which rotates about
68
+ * the axis line through `origin`.
69
+ * @param parent - Name of the reference (parent) body.
70
+ * @param child - Name of the body moved by the joint.
71
+ * @param axis - Slide axis; only `direction` is used.
72
+ * @param opts - Optional range bounds and initial value.
73
+ * @returns The newly created prismatic joint.
74
+ */
75
+ export function prismaticJoint(parent, child, axis, opts = {}) {
76
+ return buildJoint('prismatic', parent, child, axis, [
77
+ makeDof('translation', axis.direction, opts, 0, 100),
78
+ ]);
79
+ }
80
+ /**
81
+ * A cylindrical joint — the child both rotates about and slides along a single
82
+ * `axis` (2 DOF). DOF order: `[rotation, translation]`. The two motions share
83
+ * the axis, so they commute; rotation pivots about `axis.origin`.
84
+ * @param parent - Name of the reference (parent) body.
85
+ * @param child - Name of the body moved by the joint.
86
+ * @param axis - Joint axis: anchor point and direction.
87
+ * @param opts - Optional per-DOF ranges and initial values.
88
+ * @returns The newly created cylindrical joint.
89
+ */
90
+ export function cylindricalJoint(parent, child, axis, opts = {}) {
91
+ return buildJoint('cylindrical', parent, child, axis, [
92
+ makeDof('rotation', axis.direction, opts.rotation ?? {}, -180, 180),
93
+ makeDof('translation', axis.direction, opts.translation ?? {}, 0, 100),
94
+ ]);
95
+ }
96
+ /**
97
+ * A planar joint — the child translates within a plane and rotates about its
98
+ * normal (3 DOF). `plane.direction` is the normal; `plane.origin` the rotation
99
+ * anchor. DOF order: `[u-translation, v-translation, rotation]`, where the
100
+ * translations are applied in the plane frame (independent of the rotation).
101
+ * @param parent - Name of the reference (parent) body.
102
+ * @param child - Name of the body moved by the joint.
103
+ * @param plane - Plane definition; `direction` is the normal, `origin` the anchor.
104
+ * @param opts - Optional per-DOF ranges, initial values, and in-plane axes.
105
+ * @returns The newly created planar joint.
106
+ */
107
+ export function planarJoint(parent, child, plane, opts = {}) {
108
+ const normal = unit(plane.direction);
109
+ // Project a requested u-direction onto the plane; fall back to an arbitrary
110
+ // in-plane axis. v completes a right-handed in-plane basis.
111
+ let u;
112
+ if (opts.uDirection) {
113
+ const d = opts.uDirection;
114
+ const proj = d[0] * normal[0] + d[1] * normal[1] + d[2] * normal[2];
115
+ const inPlane = [
116
+ d[0] - proj * normal[0],
117
+ d[1] - proj * normal[1],
118
+ d[2] - proj * normal[2],
119
+ ];
120
+ u =
121
+ Math.hypot(inPlane[0], inPlane[1], inPlane[2]) < 1e-9
122
+ ? anyPerpendicular(normal)
123
+ : unit(inPlane);
124
+ }
125
+ else {
126
+ u = anyPerpendicular(normal);
127
+ }
128
+ const v = unit(cross(normal, u));
129
+ return buildJoint('planar', parent, child, { origin: plane.origin, direction: normal }, [
130
+ makeDof('translation', u, opts.u ?? {}, -100, 100),
131
+ makeDof('translation', v, opts.v ?? {}, -100, 100),
132
+ makeDof('rotation', normal, opts.rotation ?? {}, -180, 180),
133
+ ]);
134
+ }
135
+ /**
136
+ * A spherical (ball) joint — the child rotates freely about a pivot point
137
+ * (3 DOF). DOF order: `[x, y, z]` rotations about the local axes through
138
+ * `pivot`, composed as `Rx · Ry · Rz`.
139
+ * @param parent - Name of the reference (parent) body.
140
+ * @param child - Name of the body moved by the joint.
141
+ * @param pivot - Pivot point all rotations pass through.
142
+ * @param opts - Optional per-axis ranges and initial values.
143
+ * @returns The newly created spherical joint.
144
+ */
145
+ export function sphericalJoint(parent, child, pivot, opts = {}) {
146
+ return buildJoint('spherical', parent, child, { origin: pivot, direction: [0, 0, 1] }, [
147
+ makeDof('rotation', [1, 0, 0], opts.x ?? {}, -180, 180),
148
+ makeDof('rotation', [0, 1, 0], opts.y ?? {}, -180, 180),
149
+ makeDof('rotation', [0, 0, 1], opts.z ?? {}, -180, 180),
150
+ ]);
151
+ }
152
+ /**
153
+ * Return a copy of `joint` with per-DOF values set (each clamped to its range).
154
+ * Values are positional, matching `joint.dofs`; omitted entries keep their
155
+ * stored value. The primary mirror (`value`) is kept in sync with `dofs[0]`.
156
+ * @param joint - The joint to update.
157
+ * @param values - Positional per-DOF values; omitted entries keep their value.
158
+ * @returns A new joint with the values set.
159
+ */
160
+ export function setJointValues(joint, values) {
161
+ const dofs = joint.dofs.map((d, i) => {
162
+ const v = values[i];
163
+ return v === undefined ? d : { ...d, value: clamp(v, d.min, d.max) };
164
+ });
165
+ const primary = dofs[0];
166
+ return primary ? { ...joint, dofs, value: primary.value } : { ...joint, dofs };
167
+ }
168
+ /** Return a copy of `joint` with its primary DOF set (clamped to range).
169
+ * @param joint - The joint to update.
170
+ * @param value - New primary-DOF value.
171
+ * @returns A new joint with the primary value set.
172
+ */
173
+ export function setJointValue(joint, value) {
174
+ return setJointValues(joint, [value]);
175
+ }
176
+ // ---------------------------------------------------------------------------
177
+ // Kinematics
178
+ // ---------------------------------------------------------------------------
179
+ /** The local rigid transform contributed by a single DOF at `value`. */
180
+ function dofPose(origin, dof, value) {
181
+ if (dof.kind === 'translation') {
182
+ // `origin` is intentionally unused: a pure translation has no pivot.
183
+ return {
184
+ position: [dof.axis[0] * value, dof.axis[1] * value, dof.axis[2] * value],
185
+ rotation: [1, 0, 0, 0],
186
+ };
187
+ }
188
+ // Rotation about the axis line through `origin`: p ↦ R·p + (origin − R·origin).
189
+ const rotation = quatFromAxisAngle(dof.axis, value * DEG2RAD);
190
+ const ro = quatRotate(rotation, origin);
191
+ return { position: [origin[0] - ro[0], origin[1] - ro[1], origin[2] - ro[2]], rotation };
192
+ }
193
+ /**
194
+ * The child's local rigid transform (relative to the parent) for given DOF
195
+ * values. Defaults to each DOF's stored value. A single `number` overrides only
196
+ * the primary DOF (single-DOF ergonomics); an array overrides positionally,
197
+ * with omitted entries keeping their stored value. Each value is clamped to its
198
+ * DOF range.
199
+ *
200
+ * DOFs are folded in array order via frame composition. For same-anchor
201
+ * rotations (e.g. spherical) this composes to a single rotation about the pivot;
202
+ * for a cylindrical axis the rotation and slide commute.
203
+ * @param joint - The joint to evaluate.
204
+ * @param value - Primary-DOF override (number) or positional per-DOF overrides.
205
+ * @returns The child's local pose relative to the parent.
206
+ */
207
+ export function jointTransform(joint, value = joint.value) {
208
+ const overrides = Array.isArray(value) ? value : undefined;
209
+ const primary = overrides ? undefined : value;
210
+ const origin = joint.axis.origin;
211
+ let pose = IDENTITY_POSE;
212
+ for (let i = 0; i < joint.dofs.length; i++) {
213
+ const dof = joint.dofs[i];
214
+ if (!dof)
215
+ continue;
216
+ const raw = overrides
217
+ ? (overrides[i] ?? dof.value)
218
+ : i === 0
219
+ ? (primary ?? dof.value)
220
+ : dof.value;
221
+ pose = composePose(pose, dofPose(origin, dof, clamp(raw, dof.min, dof.max)));
222
+ }
223
+ return pose;
224
+ }
225
+ // ---------------------------------------------------------------------------
226
+ // Assembly integration
227
+ // ---------------------------------------------------------------------------
228
+ /** Attach a joint to an assembly node. Returns a new node (immutable).
229
+ * @param assembly - The assembly node to attach the joint to.
230
+ * @param joint - The joint to attach.
231
+ * @returns A new node with the joint added.
232
+ */
233
+ export function addJoint(assembly, joint) {
234
+ const existing = (assembly.joints ?? []);
235
+ return { ...assembly, joints: [...existing, joint] };
236
+ }
237
+ // ---------------------------------------------------------------------------
238
+ // Forward kinematics
239
+ // ---------------------------------------------------------------------------
240
+ const IDENTITY_POSE = { position: [0, 0, 0], rotation: [1, 0, 0, 0] };
241
+ /** Compose two poses: the result applies `b` in `a`'s frame (`a ∘ b`). */
242
+ function composePose(a, b) {
243
+ const rb = quatRotate(a.rotation, b.position);
244
+ return {
245
+ position: [a.position[0] + rb[0], a.position[1] + rb[1], a.position[2] + rb[2]],
246
+ rotation: quatMultiply(a.rotation, b.rotation),
247
+ };
248
+ }
249
+ /** Collect every joint attached anywhere in the assembly tree. */
250
+ function collectJoints(assembly) {
251
+ const joints = [];
252
+ walkAssembly(assembly, (node) => {
253
+ if (node.joints)
254
+ joints.push(...node.joints);
255
+ });
256
+ return joints;
257
+ }
258
+ /**
259
+ * Forward kinematics: set joint values and propagate world poses down the
260
+ * kinematic chain. Each joint's axis is interpreted in its **parent's** frame,
261
+ * so a child's world pose is `parentWorld ∘ jointTransform(joint, value)`.
262
+ *
263
+ * Bodies not driven by a joint (chain roots) start at the origin. `jointValues`
264
+ * overrides a joint's stored value, keyed by the **child** node name; omitted
265
+ * joints use `joint.value`. Resolution is topological (reuses the Phase-0
266
+ * ordering), so chains of any depth compose. Returns a world pose for every node.
267
+ * @param assembly - The assembly to solve.
268
+ * @param jointValues - Optional value overrides keyed by child node name.
269
+ * @returns A world pose for every node in the assembly.
270
+ */
271
+ export function forwardKinematics(assembly, jointValues = {}) {
272
+ // Single pass: gather joints and node names together.
273
+ const joints = [];
274
+ const names = new Set();
275
+ walkAssembly(assembly, (node) => {
276
+ names.add(node.name);
277
+ if (node.joints)
278
+ joints.push(...node.joints);
279
+ });
280
+ const byChild = new Map();
281
+ for (const j of joints) {
282
+ byChild.set(j.child, j);
283
+ names.add(j.parent);
284
+ names.add(j.child);
285
+ }
286
+ const poses = new Map();
287
+ // Roots: any node not driven by a joint sits at the origin.
288
+ for (const name of names)
289
+ if (!byChild.has(name))
290
+ poses.set(name, IDENTITY_POSE);
291
+ // Propagate down the joint graph: a joint resolves once its parent is placed.
292
+ const pending = [...joints];
293
+ let progress = true;
294
+ while (progress && pending.length > 0) {
295
+ progress = false;
296
+ for (let i = pending.length - 1; i >= 0; i--) {
297
+ const j = pending[i];
298
+ if (!j)
299
+ continue;
300
+ const parentPose = poses.get(j.parent);
301
+ if (!parentPose)
302
+ continue; // parent not placed yet — defer
303
+ pending.splice(i, 1);
304
+ progress = true;
305
+ if (poses.has(j.child))
306
+ continue; // already placed (duplicate/cycle) — skip
307
+ const value = jointValues[j.child] ?? j.value;
308
+ const local = j.offset
309
+ ? composePose(jointTransform(j, value), j.offset)
310
+ : jointTransform(j, value);
311
+ poses.set(j.child, composePose(parentPose, local));
312
+ }
313
+ }
314
+ // A joint whose parent never resolved (cycle/dangling) still gets an entry so
315
+ // the map covers every node.
316
+ for (const j of pending)
317
+ if (!poses.has(j.child))
318
+ poses.set(j.child, IDENTITY_POSE);
319
+ return poses;
320
+ }
321
+ /**
322
+ * Open-chain mobility — the number of independent degrees of freedom, summing
323
+ * each joint's DOF count (revolute/prismatic 1, cylindrical 2, planar/spherical
324
+ * 3). For a serial chain this equals the total DOF. (Closed-loop
325
+ * Grübler/Kutzbach analysis is future work.)
326
+ * @param assembly - The assembly to analyze.
327
+ * @returns Total number of independent degrees of freedom.
328
+ */
329
+ export function mechanismDOF(assembly) {
330
+ return collectJoints(assembly).reduce((sum, j) => sum + j.dofs.length, 0);
331
+ }
332
+ // ---------------------------------------------------------------------------
333
+ // Small vector / quaternion helpers
334
+ // ---------------------------------------------------------------------------
335
+ const IK_IDENTITY_POSE = { position: [0, 0, 0], rotation: [1, 0, 0, 0] };
336
+ function applyPose(pose, p) {
337
+ const r = quatRotate(pose.rotation, p);
338
+ return [r[0] + pose.position[0], r[1] + pose.position[1], r[2] + pose.position[2]];
339
+ }
340
+ function quatConjugate(q) {
341
+ return [q[0], -q[1], -q[2], -q[3]];
342
+ }
343
+ /**
344
+ * The rotation vector (axis · angle) taking orientation `from` to `to`, i.e. the
345
+ * angular error that drives `from` toward `to`. Returns the zero vector when the
346
+ * orientations coincide.
347
+ */
348
+ function rotationError(from, to) {
349
+ const d = quatMultiply(to, quatConjugate(from));
350
+ let [w, x, y, z] = d;
351
+ const norm = Math.hypot(w, x, y, z) || 1;
352
+ w /= norm;
353
+ x /= norm;
354
+ y /= norm;
355
+ z /= norm;
356
+ if (w < 0) {
357
+ // Shortest path: q and -q represent the same rotation.
358
+ w = -w;
359
+ x = -x;
360
+ y = -y;
361
+ z = -z;
362
+ }
363
+ const s = Math.hypot(x, y, z);
364
+ if (s < 1e-12)
365
+ return [0, 0, 0];
366
+ const angle = 2 * Math.atan2(s, w);
367
+ const k = angle / s;
368
+ return [x * k, y * k, z * k];
369
+ }
370
+ // ---------------------------------------------------------------------------
371
+ // Chain extraction
372
+ // ---------------------------------------------------------------------------
373
+ /** Joints from the root down to `endEffector`, in root→leaf order. */
374
+ function chainTo(assembly, endEffector) {
375
+ const joints = [];
376
+ walkAssembly(assembly, (n) => {
377
+ if (n.joints)
378
+ joints.push(...n.joints);
379
+ });
380
+ const byChild = new Map();
381
+ for (const j of joints)
382
+ byChild.set(j.child, j);
383
+ const chain = [];
384
+ const seen = new Set();
385
+ let cur = endEffector;
386
+ while (cur && byChild.has(cur) && !seen.has(cur)) {
387
+ seen.add(cur);
388
+ const j = byChild.get(cur);
389
+ if (!j)
390
+ break;
391
+ chain.push(j);
392
+ cur = j.parent;
393
+ }
394
+ return chain.reverse();
395
+ }
396
+ // ---------------------------------------------------------------------------
397
+ // Linear algebra (small dense systems, Float64Array to avoid index-undefined)
398
+ // ---------------------------------------------------------------------------
399
+ /** Read a Float64Array element as a definite number (dense matrices are full). */
400
+ function el(a, i) {
401
+ return a[i] ?? 0;
402
+ }
403
+ /** Solve `A x = b` for an `n×n` system by Gauss-Jordan with partial pivoting. */
404
+ function solveLinear(A, b, n) {
405
+ const w = n + 1;
406
+ const M = new Float64Array(n * w);
407
+ for (let r = 0; r < n; r++) {
408
+ for (let c = 0; c < n; c++)
409
+ M[r * w + c] = el(A, r * n + c);
410
+ M[r * w + n] = el(b, r);
411
+ }
412
+ for (let col = 0; col < n; col++) {
413
+ let piv = col;
414
+ for (let r = col + 1; r < n; r++) {
415
+ if (Math.abs(el(M, r * w + col)) > Math.abs(el(M, piv * w + col)))
416
+ piv = r;
417
+ }
418
+ if (Math.abs(el(M, piv * w + col)) < 1e-12)
419
+ return null;
420
+ if (piv !== col) {
421
+ for (let k = col; k < w; k++) {
422
+ const tmp = el(M, col * w + k);
423
+ M[col * w + k] = el(M, piv * w + k);
424
+ M[piv * w + k] = tmp;
425
+ }
426
+ }
427
+ const d = el(M, col * w + col);
428
+ for (let k = col; k < w; k++)
429
+ M[col * w + k] = el(M, col * w + k) / d;
430
+ for (let r = 0; r < n; r++) {
431
+ if (r === col)
432
+ continue;
433
+ const f = el(M, r * w + col);
434
+ if (f === 0)
435
+ continue;
436
+ for (let k = col; k < w; k++)
437
+ M[r * w + k] = el(M, r * w + k) - f * el(M, col * w + k);
438
+ }
439
+ }
440
+ const x = new Float64Array(n);
441
+ for (let r = 0; r < n; r++)
442
+ x[r] = el(M, r * w + n);
443
+ return x;
444
+ }
445
+ /** Flatten a chain's DOFs into a parameter vector with bounds, applying the seed. */
446
+ function flattenChain(chain, seed) {
447
+ const segments = [];
448
+ const q = [];
449
+ const lo = [];
450
+ const hi = [];
451
+ for (const j of chain) {
452
+ const s = seed?.[j.child];
453
+ segments.push({ child: j.child, count: j.dofs.length });
454
+ j.dofs.forEach((dof, i) => {
455
+ const seeded = Array.isArray(s) ? s[i] : i === 0 ? s : undefined;
456
+ const v = seeded ?? dof.value;
457
+ q.push(Math.min(dof.max, Math.max(dof.min, v)));
458
+ lo.push(dof.min);
459
+ hi.push(dof.max);
460
+ });
461
+ }
462
+ return {
463
+ segments,
464
+ q: Float64Array.from(q),
465
+ lo: Float64Array.from(lo),
466
+ hi: Float64Array.from(hi),
467
+ };
468
+ }
469
+ /** Slice a parameter vector back into per-joint value arrays keyed by child. */
470
+ function overridesOf(segments, q) {
471
+ const out = {};
472
+ let i = 0;
473
+ for (const seg of segments) {
474
+ const vals = [];
475
+ for (let k = 0; k < seg.count; k++)
476
+ vals.push(el(q, i++));
477
+ out[seg.child] = vals;
478
+ }
479
+ return out;
480
+ }
481
+ /** Residual twist `e` (target − current) for a pose; returns its norm. */
482
+ function residualTwist(out, pose, target, tip, m) {
483
+ const pos = applyPose(pose, tip);
484
+ out[0] = target.position[0] - pos[0];
485
+ out[1] = target.position[1] - pos[1];
486
+ out[2] = target.position[2] - pos[2];
487
+ if (m === 6 && target.rotation) {
488
+ const r = rotationError(pose.rotation, target.rotation);
489
+ out[3] = r[0];
490
+ out[4] = r[1];
491
+ out[5] = r[2];
492
+ }
493
+ let s = 0;
494
+ for (let i = 0; i < m; i++)
495
+ s += el(out, i) ** 2;
496
+ return Math.sqrt(s);
497
+ }
498
+ /**
499
+ * Finite-difference Jacobian: column `j` is the end-effector twist from δq[j].
500
+ * The probe steps *inward* from a bound — `forwardKinematics` clamps each DOF to
501
+ * its range, so a forward `+eps` at the upper limit would yield a zero column and
502
+ * trap the solver at the ceiling. Stepping `-eps` there (and dividing by the
503
+ * signed step) keeps every column a true one-sided derivative.
504
+ */
505
+ function fillJacobian(J, q, n, m, lo, hi, base, tip, eps, tipPose) {
506
+ const basePos = applyPose(base, tip);
507
+ for (let j = 0; j < n; j++) {
508
+ const saved = el(q, j);
509
+ // Step away from whichever bound we're against so the perturbation isn't
510
+ // clamped to a no-op; default forward.
511
+ const h = saved + eps > el(hi, j) && saved - eps >= el(lo, j) ? -eps : eps;
512
+ q[j] = saved + h;
513
+ const p2 = tipPose(q);
514
+ q[j] = saved;
515
+ const pos2 = applyPose(p2, tip);
516
+ J[j] = (pos2[0] - basePos[0]) / h;
517
+ J[n + j] = (pos2[1] - basePos[1]) / h;
518
+ J[2 * n + j] = (pos2[2] - basePos[2]) / h;
519
+ if (m === 6) {
520
+ const dr = rotationError(base.rotation, p2.rotation);
521
+ J[3 * n + j] = dr[0] / h;
522
+ J[4 * n + j] = dr[1] / h;
523
+ J[5 * n + j] = dr[2] / h;
524
+ }
525
+ }
526
+ }
527
+ /** One damped-least-squares step: `Δq = Jᵀ(JJᵀ + λ²I)⁻¹ e`. */
528
+ function dlsStep(J, e, n, m, lambda) {
529
+ const A = new Float64Array(m * m);
530
+ const lam2 = lambda * lambda;
531
+ for (let r = 0; r < m; r++) {
532
+ for (let c = 0; c < m; c++) {
533
+ let s = 0;
534
+ for (let k = 0; k < n; k++)
535
+ s += el(J, r * n + k) * el(J, c * n + k);
536
+ A[r * m + c] = s + (r === c ? lam2 : 0);
537
+ }
538
+ }
539
+ const y = solveLinear(A, e, m);
540
+ if (!y)
541
+ return null;
542
+ const dq = new Float64Array(n);
543
+ for (let j = 0; j < n; j++) {
544
+ let v = 0;
545
+ for (let r = 0; r < m; r++)
546
+ v += el(J, r * n + j) * el(y, r);
547
+ dq[j] = v;
548
+ }
549
+ return dq;
550
+ }
551
+ /**
552
+ * Solve for the joint values that place `endEffector` (offset by `tip`) at
553
+ * `target`, by damped-least-squares descent on a numerical Jacobian. Joint
554
+ * ranges are honored: every iterate is clamped to each DOF's `[min, max]`.
555
+ *
556
+ * Returns the solved per-DOF values keyed by child node (ready to pass to
557
+ * `forwardKinematics`), whether it converged, the iteration count, and the final
558
+ * residual norm. An end-effector with no driving joints, or an unreachable
559
+ * target, returns `converged: false` with the best configuration found.
560
+ * @param assembly - The assembly containing the kinematic chain.
561
+ * @param endEffector - Name of the end-effector node.
562
+ * @param target - Target world pose for the end-effector.
563
+ * @param options - Optional solver settings (iterations, tolerance, damping, seed, tip).
564
+ * @returns The solved joint values and convergence diagnostics.
565
+ */
566
+ export function inverseKinematics(assembly, endEffector, target, options = {}) {
567
+ const maxIterations = options.maxIterations ?? 200;
568
+ const tolerance = options.tolerance ?? 1e-5;
569
+ const lambda = options.damping ?? 0.05;
570
+ const tip = options.tip ?? [0, 0, 0];
571
+ const m = target.rotation !== undefined ? 6 : 3;
572
+ const eps = 1e-6;
573
+ const { segments, q, lo, hi } = flattenChain(chainTo(assembly, endEffector), options.seed);
574
+ const n = q.length;
575
+ const tipPose = (state) => forwardKinematics(assembly, overridesOf(segments, state)).get(endEffector) ?? IK_IDENTITY_POSE;
576
+ const e = new Float64Array(m);
577
+ const J = new Float64Array(m * n);
578
+ let pose = tipPose(q);
579
+ let err = residualTwist(e, pose, target, tip, m);
580
+ let iter = 0;
581
+ for (; iter < maxIterations && n > 0 && err > tolerance; iter++) {
582
+ fillJacobian(J, q, n, m, lo, hi, pose, tip, eps, tipPose);
583
+ const dq = dlsStep(J, e, n, m, lambda);
584
+ if (!dq)
585
+ break;
586
+ for (let j = 0; j < n; j++) {
587
+ const next = el(q, j) + el(dq, j);
588
+ q[j] = Math.min(el(hi, j), Math.max(el(lo, j), next));
589
+ }
590
+ pose = tipPose(q);
591
+ err = residualTwist(e, pose, target, tip, m);
592
+ }
593
+ return {
594
+ values: overridesOf(segments, q),
595
+ converged: err <= tolerance,
596
+ iterations: iter,
597
+ error: err,
598
+ };
599
+ }
600
+ /** Resolve a value spec (number, array, or absent) to a per-DOF array. */
601
+ function valuesOf(joint, spec) {
602
+ return joint.dofs.map((dof, i) => {
603
+ const raw = Array.isArray(spec) ? spec[i] : i === 0 ? spec : undefined;
604
+ const v = raw ?? dof.value;
605
+ return Math.min(dof.max, Math.max(dof.min, v));
606
+ });
607
+ }
608
+ /**
609
+ * Sample a straight-line path in joint space from `from` to `to` over `steps`
610
+ * segments, yielding `steps + 1` samples (inclusive of both endpoints). Each
611
+ * sample carries the interpolated per-DOF values (clamped to range) and the
612
+ * forward-kinematics poses of every node. Joints absent from `from`/`to` hold
613
+ * their stored value at both ends.
614
+ * @param assembly - The assembly to pose at each sample.
615
+ * @param from - Starting joint values keyed by child node name.
616
+ * @param to - Ending joint values keyed by child node name.
617
+ * @param steps - Number of path segments (samples are `steps + 1`).
618
+ * @returns The trajectory samples with interpolated values and poses.
619
+ */
620
+ export function jointTrajectory(assembly, from, to, steps) {
621
+ const joints = [];
622
+ walkAssembly(assembly, (n) => {
623
+ if (n.joints)
624
+ joints.push(...n.joints);
625
+ });
626
+ const ends = joints.map((j) => ({
627
+ child: j.child,
628
+ a: valuesOf(j, from[j.child]),
629
+ b: valuesOf(j, to[j.child]),
630
+ }));
631
+ const count = Math.max(1, Math.floor(steps));
632
+ const samples = [];
633
+ for (let s = 0; s <= count; s++) {
634
+ const t = s / count;
635
+ const values = {};
636
+ for (const end of ends) {
637
+ values[end.child] = end.a.map((a, i) => a + ((end.b[i] ?? a) - a) * t);
638
+ }
639
+ samples.push({ t, values, poses: forwardKinematics(assembly, values) });
640
+ }
641
+ return samples;
642
+ }
643
+ //# sourceMappingURL=joints-kinematics.js.map