@bitbybit-dev/base 1.5.0-rc.0 → 1.6.0-rc.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 (312) hide show
  1. package/lib/api/GlobalCDNProvider.js +1 -1
  2. package/lib/api/bearings/ansi-bearings.constants.d.ts +2 -0
  3. package/lib/api/bearings/ansi-bearings.constants.js +26 -0
  4. package/lib/api/bearings/ansi-bearings.d.ts +4 -0
  5. package/lib/api/bearings/ansi-bearings.js +14 -0
  6. package/lib/api/bearings/bearing-types.d.ts +25 -0
  7. package/lib/api/bearings/bearing-types.js +1 -0
  8. package/lib/api/bearings/bearings.constants.d.ts +1 -0
  9. package/lib/api/bearings/bearings.constants.js +1 -0
  10. package/lib/api/bearings/iso-bearings.constants.d.ts +2 -0
  11. package/lib/api/bearings/iso-bearings.constants.js +30 -0
  12. package/lib/api/bearings/iso-bearings.d.ts +4 -0
  13. package/lib/api/bearings/iso-bearings.js +14 -0
  14. package/lib/api/color-space.d.ts +2 -0
  15. package/lib/api/color-space.js +5 -8
  16. package/lib/api/fasteners/ansi-fasteners.constants.d.ts +16 -0
  17. package/lib/api/fasteners/ansi-fasteners.constants.js +118 -0
  18. package/lib/api/fasteners/ansi-fasteners.d.ts +8 -0
  19. package/lib/api/fasteners/ansi-fasteners.js +64 -0
  20. package/lib/api/fasteners/fastener-types.d.ts +161 -0
  21. package/lib/api/fasteners/fastener-types.js +1 -0
  22. package/lib/api/fasteners/fasteners.constants.d.ts +5 -0
  23. package/lib/api/fasteners/fasteners.constants.js +5 -0
  24. package/lib/api/fasteners/fasteners.d.ts +2 -0
  25. package/lib/api/fasteners/fasteners.js +9 -0
  26. package/lib/api/fasteners/iso-fasteners.constants.d.ts +23 -0
  27. package/lib/api/fasteners/iso-fasteners.constants.js +110 -0
  28. package/lib/api/fasteners/iso-fasteners.d.ts +9 -0
  29. package/lib/api/fasteners/iso-fasteners.js +61 -0
  30. package/lib/api/gears/bevel-gears.d.ts +6 -0
  31. package/lib/api/gears/bevel-gears.js +69 -0
  32. package/lib/api/gears/gear-checks.d.ts +8 -0
  33. package/lib/api/gears/gear-checks.js +69 -0
  34. package/lib/api/gears/gear-pairs.d.ts +4 -0
  35. package/lib/api/gears/gear-pairs.js +140 -0
  36. package/lib/api/gears/gear-types.d.ts +425 -0
  37. package/lib/api/gears/gear-types.js +1 -0
  38. package/lib/api/gears/gears.constants.d.ts +19 -0
  39. package/lib/api/gears/gears.constants.js +19 -0
  40. package/lib/api/gears/gears.d.ts +10 -0
  41. package/lib/api/gears/gears.js +156 -0
  42. package/lib/api/gears/helical-gears.d.ts +5 -0
  43. package/lib/api/gears/helical-gears.js +33 -0
  44. package/lib/api/gears/involute-flank.d.ts +26 -0
  45. package/lib/api/gears/involute-flank.js +158 -0
  46. package/lib/api/gears/racks.d.ts +3 -0
  47. package/lib/api/gears/racks.js +64 -0
  48. package/lib/api/index.d.ts +10 -1
  49. package/lib/api/index.js +0 -1
  50. package/lib/api/inputs/base-inputs.d.ts +450 -3
  51. package/lib/api/inputs/base-inputs.js +12 -0
  52. package/lib/api/inputs/color-inputs.d.ts +14 -0
  53. package/lib/api/inputs/color-inputs.js +19 -0
  54. package/lib/api/inputs/engineering-inputs.d.ts +1539 -0
  55. package/lib/api/inputs/engineering-inputs.js +2181 -0
  56. package/lib/api/inputs/index.d.ts +2 -0
  57. package/lib/api/inputs/index.js +2 -0
  58. package/lib/api/inputs/io-inputs.d.ts +8 -1
  59. package/lib/api/inputs/io-inputs.js +4 -1
  60. package/lib/api/inputs/math-inputs.d.ts +61 -0
  61. package/lib/api/inputs/math-inputs.js +85 -0
  62. package/lib/api/inputs/mesh-inputs.d.ts +170 -0
  63. package/lib/api/inputs/mesh-inputs.js +206 -0
  64. package/lib/api/inputs/point-inputs.d.ts +4 -4
  65. package/lib/api/inputs/polyline-inputs.d.ts +144 -0
  66. package/lib/api/inputs/polyline-inputs.js +151 -0
  67. package/lib/api/inputs/recipes-inputs.d.ts +76 -0
  68. package/lib/api/inputs/recipes-inputs.js +74 -0
  69. package/lib/api/inputs/transforms-inputs.d.ts +34 -0
  70. package/lib/api/inputs/transforms-inputs.js +35 -0
  71. package/lib/api/keys/ansi-keys.constants.d.ts +3 -0
  72. package/lib/api/keys/ansi-keys.constants.js +16 -0
  73. package/lib/api/keys/ansi-keys.d.ts +3 -0
  74. package/lib/api/keys/ansi-keys.js +14 -0
  75. package/lib/api/keys/din-keys.constants.d.ts +3 -0
  76. package/lib/api/keys/din-keys.constants.js +14 -0
  77. package/lib/api/keys/din-keys.d.ts +3 -0
  78. package/lib/api/keys/din-keys.js +13 -0
  79. package/lib/api/keys/key-types.d.ts +17 -0
  80. package/lib/api/keys/key-types.js +1 -0
  81. package/lib/api/keys/keys.constants.d.ts +1 -0
  82. package/lib/api/keys/keys.constants.js +1 -0
  83. package/lib/api/knurls/ansi-knurls.constants.d.ts +4 -0
  84. package/lib/api/knurls/ansi-knurls.constants.js +8 -0
  85. package/lib/api/knurls/ansi-knurls.d.ts +3 -0
  86. package/lib/api/knurls/ansi-knurls.js +20 -0
  87. package/lib/api/knurls/din-knurls.constants.d.ts +2 -0
  88. package/lib/api/knurls/din-knurls.constants.js +2 -0
  89. package/lib/api/knurls/din-knurls.d.ts +3 -0
  90. package/lib/api/knurls/din-knurls.js +19 -0
  91. package/lib/api/knurls/knurl-types.d.ts +24 -0
  92. package/lib/api/knurls/knurl-types.js +1 -0
  93. package/lib/api/knurls/knurls.constants.d.ts +1 -0
  94. package/lib/api/knurls/knurls.constants.js +1 -0
  95. package/lib/api/knurls/knurls.d.ts +2 -0
  96. package/lib/api/knurls/knurls.js +9 -0
  97. package/lib/api/recipes/checks.d.ts +15 -0
  98. package/lib/api/recipes/checks.js +85 -0
  99. package/lib/api/recipes/limits.constants.d.ts +4 -0
  100. package/lib/api/recipes/limits.constants.js +4 -0
  101. package/lib/api/recipes/sources.d.ts +0 -13
  102. package/lib/api/recipes/sources.js +3 -15
  103. package/lib/api/recipes/surface-mesh.d.ts +0 -14
  104. package/lib/api/recipes/surface-mesh.js +8 -21
  105. package/lib/api/recipes/validate-brep.d.ts +2 -0
  106. package/lib/api/recipes/validate-brep.js +330 -0
  107. package/lib/api/recipes/validate.d.ts +0 -31
  108. package/lib/api/recipes/validate.js +7 -115
  109. package/lib/api/resolved-inputs/index.d.ts +80 -0
  110. package/lib/api/retaining-rings/ansi-retaining-rings.constants.d.ts +4 -0
  111. package/lib/api/retaining-rings/ansi-retaining-rings.constants.js +93 -0
  112. package/lib/api/retaining-rings/ansi-retaining-rings.d.ts +4 -0
  113. package/lib/api/retaining-rings/ansi-retaining-rings.js +20 -0
  114. package/lib/api/retaining-rings/din-retaining-rings.constants.d.ts +3 -0
  115. package/lib/api/retaining-rings/din-retaining-rings.constants.js +115 -0
  116. package/lib/api/retaining-rings/din-retaining-rings.d.ts +4 -0
  117. package/lib/api/retaining-rings/din-retaining-rings.js +20 -0
  118. package/lib/api/retaining-rings/retaining-ring-types.d.ts +30 -0
  119. package/lib/api/retaining-rings/retaining-ring-types.js +1 -0
  120. package/lib/api/retaining-rings/retaining-rings.constants.d.ts +1 -0
  121. package/lib/api/retaining-rings/retaining-rings.constants.js +1 -0
  122. package/lib/api/retaining-rings/retaining-rings.d.ts +2 -0
  123. package/lib/api/retaining-rings/retaining-rings.js +9 -0
  124. package/lib/api/services/base-bitbybit.d.ts +42 -0
  125. package/lib/api/services/base-bitbybit.js +43 -0
  126. package/lib/api/services/color.d.ts +35 -2
  127. package/lib/api/services/color.js +48 -12
  128. package/lib/api/services/engineering/engineering.d.ts +12 -0
  129. package/lib/api/services/engineering/engineering.js +13 -0
  130. package/lib/api/services/engineering/index.d.ts +2 -0
  131. package/lib/api/services/engineering/index.js +2 -0
  132. package/lib/api/services/engineering/mechanical/bearings-ansi.d.ts +40 -0
  133. package/lib/api/services/engineering/mechanical/bearings-ansi.js +47 -0
  134. package/lib/api/services/engineering/mechanical/bearings-iso.d.ts +39 -0
  135. package/lib/api/services/engineering/mechanical/bearings-iso.js +46 -0
  136. package/lib/api/services/engineering/mechanical/bearings.d.ts +14 -0
  137. package/lib/api/services/engineering/mechanical/bearings.js +15 -0
  138. package/lib/api/services/engineering/mechanical/fasteners-ansi.d.ts +109 -0
  139. package/lib/api/services/engineering/mechanical/fasteners-ansi.js +133 -0
  140. package/lib/api/services/engineering/mechanical/fasteners-iso.d.ts +123 -0
  141. package/lib/api/services/engineering/mechanical/fasteners-iso.js +151 -0
  142. package/lib/api/services/engineering/mechanical/fasteners.d.ts +13 -0
  143. package/lib/api/services/engineering/mechanical/fasteners.js +14 -0
  144. package/lib/api/services/engineering/mechanical/gears.d.ts +267 -0
  145. package/lib/api/services/engineering/mechanical/gears.js +318 -0
  146. package/lib/api/services/engineering/mechanical/index.d.ts +24 -0
  147. package/lib/api/services/engineering/mechanical/index.js +24 -0
  148. package/lib/api/services/engineering/mechanical/keys-ansi.d.ts +27 -0
  149. package/lib/api/services/engineering/mechanical/keys-ansi.js +32 -0
  150. package/lib/api/services/engineering/mechanical/keys-din.d.ts +26 -0
  151. package/lib/api/services/engineering/mechanical/keys-din.js +31 -0
  152. package/lib/api/services/engineering/mechanical/keys.d.ts +14 -0
  153. package/lib/api/services/engineering/mechanical/keys.js +15 -0
  154. package/lib/api/services/engineering/mechanical/knurls-ansi.d.ts +26 -0
  155. package/lib/api/services/engineering/mechanical/knurls-ansi.js +31 -0
  156. package/lib/api/services/engineering/mechanical/knurls-din.d.ts +26 -0
  157. package/lib/api/services/engineering/mechanical/knurls-din.js +31 -0
  158. package/lib/api/services/engineering/mechanical/knurls.d.ts +14 -0
  159. package/lib/api/services/engineering/mechanical/knurls.js +15 -0
  160. package/lib/api/services/engineering/mechanical/mechanical.d.ts +29 -0
  161. package/lib/api/services/engineering/mechanical/mechanical.js +30 -0
  162. package/lib/api/services/engineering/mechanical/retaining-rings-ansi.d.ts +43 -0
  163. package/lib/api/services/engineering/mechanical/retaining-rings-ansi.js +51 -0
  164. package/lib/api/services/engineering/mechanical/retaining-rings-din.d.ts +43 -0
  165. package/lib/api/services/engineering/mechanical/retaining-rings-din.js +51 -0
  166. package/lib/api/services/engineering/mechanical/retaining-rings.d.ts +13 -0
  167. package/lib/api/services/engineering/mechanical/retaining-rings.js +14 -0
  168. package/lib/api/services/engineering/mechanical/splines-ansi.d.ts +27 -0
  169. package/lib/api/services/engineering/mechanical/splines-ansi.js +32 -0
  170. package/lib/api/services/engineering/mechanical/splines-din.d.ts +26 -0
  171. package/lib/api/services/engineering/mechanical/splines-din.js +31 -0
  172. package/lib/api/services/engineering/mechanical/splines.d.ts +13 -0
  173. package/lib/api/services/engineering/mechanical/splines.js +14 -0
  174. package/lib/api/services/engineering/mechanical/springs.d.ts +27 -0
  175. package/lib/api/services/engineering/mechanical/springs.js +31 -0
  176. package/lib/api/services/engineering/mechanical/threads-ansi.d.ts +40 -0
  177. package/lib/api/services/engineering/mechanical/threads-ansi.js +48 -0
  178. package/lib/api/services/engineering/mechanical/threads-iso.d.ts +40 -0
  179. package/lib/api/services/engineering/mechanical/threads-iso.js +48 -0
  180. package/lib/api/services/engineering/mechanical/threads.d.ts +13 -0
  181. package/lib/api/services/engineering/mechanical/threads.js +14 -0
  182. package/lib/api/services/frame.js +3 -3
  183. package/lib/api/services/geometry-helper.js +8 -111
  184. package/lib/api/services/helpers/color/color-space.d.ts +2 -0
  185. package/lib/api/services/helpers/color/color-space.js +12 -0
  186. package/lib/api/services/helpers/{nurbs.d.ts → curves/nurbs.d.ts} +1 -1
  187. package/lib/api/services/helpers/{surface-triangulation.d.ts → curves/surface-triangulation.d.ts} +2 -2
  188. package/lib/api/services/helpers/{surface-triangulation.js → curves/surface-triangulation.js} +14 -8
  189. package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.d.ts +2 -1
  190. package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.js +19 -5
  191. package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +4 -0
  192. package/lib/api/services/helpers/files/dxf/dxf.constants.js +4 -0
  193. package/lib/api/services/helpers/{dxf → files/dxf}/dxf.d.ts +1 -1
  194. package/lib/api/services/helpers/{dxf → files/dxf}/dxf.js +2 -2
  195. package/lib/api/services/helpers/files/glb.constants.d.ts +11 -0
  196. package/lib/api/services/helpers/files/glb.constants.js +11 -0
  197. package/lib/api/services/helpers/files/glb.d.ts +1 -0
  198. package/lib/api/services/helpers/files/glb.js +69 -0
  199. package/lib/api/services/helpers/files/gzip.constants.d.ts +11 -0
  200. package/lib/api/services/helpers/files/gzip.constants.js +11 -0
  201. package/lib/api/services/helpers/files/gzip.d.ts +2 -0
  202. package/lib/api/services/helpers/files/gzip.js +52 -0
  203. package/lib/api/services/helpers/{inflate.constants.d.ts → files/inflate.constants.d.ts} +1 -0
  204. package/lib/api/services/helpers/{inflate.constants.js → files/inflate.constants.js} +1 -0
  205. package/lib/api/services/helpers/{inflate.d.ts → files/inflate.d.ts} +1 -1
  206. package/lib/api/services/helpers/{inflate.js → files/inflate.js} +5 -4
  207. package/lib/api/services/helpers/{zip.d.ts → files/zip.d.ts} +1 -1
  208. package/lib/api/services/helpers/geometry/arcs.d.ts +9 -0
  209. package/lib/api/services/helpers/{arcs.js → geometry/arcs.js} +7 -0
  210. package/lib/api/services/helpers/{frame-axes.d.ts → geometry/frame-axes.d.ts} +8 -5
  211. package/lib/api/services/helpers/{frame-axes.js → geometry/frame-axes.js} +21 -9
  212. package/lib/api/services/helpers/geometry/lengths.constants.d.ts +4 -0
  213. package/lib/api/services/helpers/geometry/lengths.constants.js +3 -0
  214. package/lib/api/services/helpers/geometry/lengths.d.ts +7 -0
  215. package/lib/api/services/helpers/geometry/lengths.js +20 -0
  216. package/lib/api/services/helpers/geometry/matrices.constants.d.ts +8 -0
  217. package/lib/api/services/helpers/geometry/matrices.constants.js +7 -0
  218. package/lib/api/services/helpers/geometry/matrices.d.ts +17 -0
  219. package/lib/api/services/helpers/{matrices.js → geometry/matrices.js} +28 -17
  220. package/lib/api/services/helpers/{paths.d.ts → geometry/paths.d.ts} +2 -1
  221. package/lib/api/services/helpers/{paths.js → geometry/paths.js} +36 -30
  222. package/lib/api/services/helpers/{polygons.d.ts → geometry/polygons.d.ts} +1 -1
  223. package/lib/api/services/helpers/geometry/polygons.js +111 -0
  224. package/lib/api/services/helpers/geometry/scalars.d.ts +9 -0
  225. package/lib/api/services/helpers/geometry/scalars.js +34 -0
  226. package/lib/api/services/helpers/{triangulation.js → geometry/triangulation.js} +11 -6
  227. package/lib/api/services/helpers/geometry/vector-grid.d.ts +12 -0
  228. package/lib/api/services/helpers/geometry/vector-grid.js +149 -0
  229. package/lib/api/services/helpers/{vectors.d.ts → geometry/vectors.d.ts} +8 -1
  230. package/lib/api/services/helpers/geometry/vectors.js +43 -0
  231. package/lib/api/services/helpers/helper-types.d.ts +57 -0
  232. package/lib/api/services/helpers/mesh/mesh-normals.d.ts +21 -0
  233. package/lib/api/services/helpers/{mesh-normals.js → mesh/mesh-normals.js} +54 -65
  234. package/lib/api/services/helpers/mesh/mesh-orientation.d.ts +24 -0
  235. package/lib/api/services/helpers/mesh/mesh-orientation.js +104 -0
  236. package/lib/api/services/helpers/{mesh-primitives.d.ts → mesh/mesh-primitives.d.ts} +1 -1
  237. package/lib/api/services/helpers/{mesh-primitives.js → mesh/mesh-primitives.js} +6 -5
  238. package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +7 -0
  239. package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +11 -0
  240. package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +11 -0
  241. package/lib/api/services/helpers/mesh/mesh-proximity.js +382 -0
  242. package/lib/api/services/index.d.ts +3 -0
  243. package/lib/api/services/index.js +3 -0
  244. package/lib/api/services/io.d.ts +1 -1
  245. package/lib/api/services/io.js +1 -1
  246. package/lib/api/services/line.js +2 -3
  247. package/lib/api/services/math.d.ts +47 -0
  248. package/lib/api/services/math.js +77 -10
  249. package/lib/api/services/mesh.d.ts +174 -2
  250. package/lib/api/services/mesh.js +305 -7
  251. package/lib/api/services/point.js +4 -10
  252. package/lib/api/services/polyline-types.d.ts +6 -0
  253. package/lib/api/services/polyline-types.js +1 -0
  254. package/lib/api/services/polyline.d.ts +163 -1
  255. package/lib/api/services/polyline.js +270 -13
  256. package/lib/api/services/recipes.d.ts +80 -0
  257. package/lib/api/services/recipes.js +107 -0
  258. package/lib/api/services/transforms.d.ts +74 -2
  259. package/lib/api/services/transforms.js +100 -3
  260. package/lib/api/services/vector.d.ts +4 -3
  261. package/lib/api/services/vector.js +14 -14
  262. package/lib/api/splines/ansi-splines.constants.d.ts +9 -0
  263. package/lib/api/splines/ansi-splines.constants.js +9 -0
  264. package/lib/api/splines/ansi-splines.d.ts +3 -0
  265. package/lib/api/splines/ansi-splines.js +28 -0
  266. package/lib/api/splines/din-splines.constants.d.ts +12 -0
  267. package/lib/api/splines/din-splines.constants.js +12 -0
  268. package/lib/api/splines/din-splines.d.ts +3 -0
  269. package/lib/api/splines/din-splines.js +38 -0
  270. package/lib/api/splines/spline-types.d.ts +32 -0
  271. package/lib/api/splines/spline-types.js +1 -0
  272. package/lib/api/splines/splines.constants.d.ts +1 -0
  273. package/lib/api/splines/splines.constants.js +1 -0
  274. package/lib/api/springs/spring-types.d.ts +26 -0
  275. package/lib/api/springs/spring-types.js +1 -0
  276. package/lib/api/springs/springs.constants.d.ts +9 -0
  277. package/lib/api/springs/springs.constants.js +9 -0
  278. package/lib/api/springs/springs.d.ts +2 -0
  279. package/lib/api/springs/springs.js +50 -0
  280. package/lib/api/threads/ansi-threads.constants.d.ts +6 -0
  281. package/lib/api/threads/ansi-threads.constants.js +27 -0
  282. package/lib/api/threads/ansi-threads.d.ts +4 -0
  283. package/lib/api/threads/ansi-threads.js +50 -0
  284. package/lib/api/threads/iso-threads.constants.d.ts +5 -0
  285. package/lib/api/threads/iso-threads.constants.js +20 -0
  286. package/lib/api/threads/iso-threads.d.ts +4 -0
  287. package/lib/api/threads/iso-threads.js +32 -0
  288. package/lib/api/threads/thread-profile.constants.d.ts +3 -0
  289. package/lib/api/threads/thread-profile.constants.js +3 -0
  290. package/lib/api/threads/thread-types.d.ts +66 -0
  291. package/lib/api/threads/thread-types.js +1 -0
  292. package/package.json +1 -1
  293. package/lib/api/recipes/index.d.ts +0 -4
  294. package/lib/api/recipes/index.js +0 -3
  295. package/lib/api/services/helpers/arcs.d.ts +0 -6
  296. package/lib/api/services/helpers/matrices.constants.d.ts +0 -2
  297. package/lib/api/services/helpers/matrices.constants.js +0 -2
  298. package/lib/api/services/helpers/matrices.d.ts +0 -25
  299. package/lib/api/services/helpers/mesh-normals.d.ts +0 -11
  300. package/lib/api/services/helpers/polygons.js +0 -59
  301. package/lib/api/services/helpers/vectors.js +0 -17
  302. /package/lib/api/services/helpers/{nurbs.js → curves/nurbs.js} +0 -0
  303. /package/lib/api/services/helpers/{crc32.d.ts → files/crc32.d.ts} +0 -0
  304. /package/lib/api/services/helpers/{crc32.js → files/crc32.js} +0 -0
  305. /package/lib/api/services/helpers/{zip.constants.d.ts → files/zip.constants.d.ts} +0 -0
  306. /package/lib/api/services/helpers/{zip.constants.js → files/zip.constants.js} +0 -0
  307. /package/lib/api/services/helpers/{zip.js → files/zip.js} +0 -0
  308. /package/lib/api/services/helpers/{triangulation.d.ts → geometry/triangulation.d.ts} +0 -0
  309. /package/lib/api/services/helpers/{mesh-measures.d.ts → mesh/mesh-measures.d.ts} +0 -0
  310. /package/lib/api/services/helpers/{mesh-measures.js → mesh/mesh-measures.js} +0 -0
  311. /package/lib/api/services/helpers/{mesh-primitives.constants.d.ts → mesh/mesh-primitives.constants.d.ts} +0 -0
  312. /package/lib/api/services/helpers/{mesh-primitives.constants.js → mesh/mesh-primitives.constants.js} +0 -0
@@ -7,7 +7,9 @@ import type { Line } from "./line";
7
7
  * Polylines: chains of straight segments through a list of points, held as plain objects of the
8
8
  * form `{ points, isClosed }`. A closed polyline joins its last point back to its first. The
9
9
  * methods here measure a polyline, convert it to segments or lines, find where polylines cross,
10
- * sort loose segments into chains and size fillets for its corners. Lengths are in model units.
10
+ * sort loose segments into chains and size fillets for its corners. They also measure, orient and
11
+ * round 2D outlines, and frame a sweep along a polyline: the frames or matrices that carry a profile
12
+ * along it without twisting. Lengths are in model units.
11
13
  */
12
14
  export declare class Polyline {
13
15
  private readonly vector;
@@ -271,5 +273,165 @@ export declare class Polyline {
271
273
  * ```
272
274
  */
273
275
  polygonArea(inputs: Inputs.Polyline.PolylineDto): number;
276
+ /**
277
+ * Measures the area of a flat outline, signed by the way it runs.
278
+ *
279
+ * The area is positive when the outline runs counter-clockwise and negative when it runs
280
+ * clockwise, so the sign tells which way an outline turns.
281
+ * Example: [[0,0], [4,0], [4,4], [0,4]] -> 16; the same corners reversed -> -16
282
+ * @param inputs - The outline's corners
283
+ * @returns The signed area in square model units
284
+ * @group polygon 2d
285
+ * @shortname signed area 2d
286
+ * @drawable false
287
+ * @example
288
+ * ```typescript
289
+ * const area = bitbybit.polyline.signedArea2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]] });
290
+ * ```
291
+ */
292
+ signedArea2d(inputs: Inputs.Polyline.Polygon2Dto): number;
293
+ /**
294
+ * Measures the length around a flat outline, its closing side included.
295
+ *
296
+ * Example: [[0,0], [3,0], [3,4]] -> 12
297
+ * @param inputs - The outline's corners
298
+ * @returns The perimeter in model units
299
+ * @group polygon 2d
300
+ * @shortname perimeter 2d
301
+ * @drawable false
302
+ * @example
303
+ * ```typescript
304
+ * const around = bitbybit.polyline.perimeter2d({ points: [[0, 0], [3, 0], [3, 4]] });
305
+ * ```
306
+ */
307
+ perimeter2d(inputs: Inputs.Polyline.Polygon2Dto): number;
308
+ /**
309
+ * Tells whether a point lies inside a flat outline.
310
+ *
311
+ * It counts the outline's sides a ray from the point crosses, so it holds for outlines that are
312
+ * not convex; a point exactly on a side may fall either way.
313
+ * Example: [2,2] in [[0,0], [4,0], [4,4], [0,4]] -> true
314
+ * @param inputs - The outline's corners and the point
315
+ * @returns True when the point is inside
316
+ * @group polygon 2d
317
+ * @shortname is point inside 2d
318
+ * @drawable false
319
+ * @example
320
+ * ```typescript
321
+ * const inside = bitbybit.polyline.isPointInside2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]], point: [2, 2] });
322
+ * ```
323
+ */
324
+ isPointInside2d(inputs: Inputs.Polyline.PointInPolygon2Dto): boolean;
325
+ /**
326
+ * Makes a flat outline run counter-clockwise, or clockwise.
327
+ *
328
+ * An outline already running that way comes back as it was; otherwise its corners are reversed.
329
+ * Example: [[0,0], [0,4], [4,4], [4,0]], counter-clockwise -> [[4,0], [4,4], [0,4], [0,0]]
330
+ * @param inputs - The outline's corners and the way it should run
331
+ * @returns The corners, running the asked way
332
+ * @group polygon 2d
333
+ * @shortname orient 2d
334
+ * @drawable false
335
+ * @example
336
+ * ```typescript
337
+ * const ccw = bitbybit.polyline.orient2d({ points: [[0, 0], [0, 4], [4, 4], [4, 0]], counterClockwise: true });
338
+ * ```
339
+ */
340
+ orient2d(inputs: Inputs.Polyline.OrientPolygon2Dto): Inputs.Base.Point2[];
341
+ /**
342
+ * Rounds the corners of a flat outline with arcs, drawn as short straight pieces.
343
+ *
344
+ * Every corner takes `radius`, or its own entry of `radiusList`; a radius of 0 leaves it sharp.
345
+ * A radius too large for the sides beside its corner is refused.
346
+ * Example: a 10 by 10 square, radius 2 -> four quarter arcs at the corners
347
+ * @param inputs - The outline, the radius or radii and the pieces per quarter turn
348
+ * @returns The rounded outline's points
349
+ * @group polygon 2d
350
+ * @shortname round corners 2d
351
+ * @drawable false
352
+ * @example
353
+ * ```typescript
354
+ * const rounded = bitbybit.polyline.roundCorners2d({ points: [[0, 0], [10, 0], [10, 10], [0, 10]], radius: 2, segments: 8 });
355
+ * ```
356
+ */
357
+ roundCorners2d(inputs: Inputs.Polyline.RoundPolygon2Dto): Inputs.Base.Point2[];
358
+ /**
359
+ * Finds the direction a path heads in at each of its points.
360
+ *
361
+ * At an inner point it bisects the segments either side; at the ends it follows the end
362
+ * segments, unless `startTangent` or `endTangent` is given. Every direction has length 1. A
363
+ * closed polyline is refused.
364
+ * Example: [[0,0,0], [1,0,0], [1,1,0]] -> [[1,0,0], [0.707,0.707,0], [0,1,0]]
365
+ * @param inputs - The path and, optionally, its end directions
366
+ * @returns One unit direction per point
367
+ * @group sweep
368
+ * @shortname tangents
369
+ * @drawable false
370
+ * @example
371
+ * ```typescript
372
+ * const directions = bitbybit.polyline.tangents({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]] } });
373
+ * ```
374
+ */
375
+ tangents(inputs: Inputs.Polyline.PolylineTangentsDto): Inputs.Base.Vector3[];
376
+ /**
377
+ * Places a frame at each point of a path, facing along it without twisting.
378
+ *
379
+ * Each normal is the path's direction there. Each direction, the profile's X axis, turns by the
380
+ * smallest angle between points, so a swept profile does not spin. `firstDirection` sets it at
381
+ * the start.
382
+ * Example: a straight path along X -> frames that differ only in origin
383
+ * @param inputs - The path and the first X direction
384
+ * @returns One frame per point
385
+ * @group sweep
386
+ * @shortname sweep frames
387
+ * @drawable true
388
+ * @example
389
+ * ```typescript
390
+ * const frames = bitbybit.polyline.sweepFrames({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] }, firstDirection: [1, 0, 0] });
391
+ * ```
392
+ */
393
+ sweepFrames(inputs: Inputs.Polyline.PolylineSweepDto): Inputs.Base.Frame[];
394
+ /**
395
+ * Builds a matrix per point of a path that places a flat profile there, for sweeping it.
396
+ *
397
+ * Each puts the XY plane on that point's `sweepFrames` frame, Z along the path, and stretches it
398
+ * across a bend so the pieces either side meet.
399
+ * Example: a straight path along Z -> matrices that only move up it
400
+ * @param inputs - The path and the first X direction
401
+ * @returns One placement matrix per point
402
+ * @group sweep
403
+ * @shortname sweep placements
404
+ * @drawable false
405
+ * @example
406
+ * ```typescript
407
+ * const placements = bitbybit.polyline.sweepPlacements({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] } });
408
+ * const ring = bitbybit.point.transformPoints({ points: [[1, 0, 0], [0, 1, 0], [-1, 0, 0]], transformation: [placements[1]] });
409
+ * ```
410
+ */
411
+ sweepPlacements(inputs: Inputs.Polyline.PolylineSweepDto): Inputs.Base.TransformMatrix[];
412
+ /**
413
+ * Rounds the corners of a path in space with arcs, drawn as short straight pieces.
414
+ *
415
+ * Where the segments beside a corner are too short for `radius`, it gets the largest arc that
416
+ * fits half of each. The ends stay; a closed polyline is refused.
417
+ * Example: [[0,0,0], [10,0,0], [10,10,0]], radius 2 -> one quarter arc at the corner
418
+ * @param inputs - The path, the radius and the pieces per quarter turn
419
+ * @returns The rounded path
420
+ * @group sweep
421
+ * @shortname round corners
422
+ * @drawable true
423
+ * @example
424
+ * ```typescript
425
+ * const rounded = bitbybit.polyline.roundCorners({ polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0]] }, radius: 2, segments: 8 });
426
+ * ```
427
+ */
428
+ roundCorners(inputs: Inputs.Polyline.RoundPolylineDto): Inputs.Polyline.PolylinePropertiesDto;
274
429
  private newellOf;
430
+ private sweepOf;
431
+ private pathOf;
432
+ private outlineOf;
433
+ private pointOf;
434
+ private isPoint2;
435
+ private directionOf;
436
+ private segmentsFor;
275
437
  }
@@ -1,12 +1,20 @@
1
1
  import * as Inputs from "../inputs";
2
- import { resolveDto } from "../kernel-calls";
3
- import { unitOf } from "./helpers/frame-axes";
4
- import { newellNormal } from "./helpers/triangulation";
2
+ import { InputError, resolveDto } from "../kernel-calls";
3
+ import { isTriple, unitOf } from "./helpers/geometry/frame-axes";
4
+ import { pathLength3, pathTangents, roundedPath3, sweepMatrices, transportedAxes } from "./helpers/geometry/paths";
5
+ import { isInsidePolygon2, perimeter2, roundedCorners2, signedArea2, wound2 } from "./helpers/geometry/polygons";
6
+ import { distance2, distance3, length3 } from "./helpers/geometry/vectors";
7
+ import { newellNormal } from "./helpers/geometry/triangulation";
8
+ const MIN_OUTLINE_POINTS = 3;
9
+ const QUARTER_TURN = Math.PI / 2;
10
+ const SEGMENT_SLACK = 1e-9;
5
11
  /**
6
12
  * Polylines: chains of straight segments through a list of points, held as plain objects of the
7
13
  * form `{ points, isClosed }`. A closed polyline joins its last point back to its first. The
8
14
  * methods here measure a polyline, convert it to segments or lines, find where polylines cross,
9
- * sort loose segments into chains and size fillets for its corners. Lengths are in model units.
15
+ * sort loose segments into chains and size fillets for its corners. They also measure, orient and
16
+ * round 2D outlines, and frame a sweep along a polyline: the frames or matrices that carry a profile
17
+ * along it without twisting. Lengths are in model units.
10
18
  */
11
19
  export class Polyline {
12
20
  constructor(vector, point, line, geometryHelper) {
@@ -31,13 +39,7 @@ export class Polyline {
31
39
  * ```
32
40
  */
33
41
  length(inputs) {
34
- let distanceOfPolyline = 0;
35
- for (let i = 1; i < inputs.polyline.points.length; i++) {
36
- const previousPoint = inputs.polyline.points[i - 1];
37
- const currentPoint = inputs.polyline.points[i];
38
- distanceOfPolyline += this.point.distance({ startPoint: previousPoint, endPoint: currentPoint });
39
- }
40
- return distanceOfPolyline;
42
+ return pathLength3(inputs.polyline.points);
41
43
  }
42
44
  /**
43
45
  * Counts the points of the polyline.
@@ -552,10 +554,265 @@ export class Polyline {
552
554
  * ```
553
555
  */
554
556
  polygonArea(inputs) {
555
- const [x, y, z] = this.newellOf(inputs.polyline.points);
556
- return Math.hypot(x, y, z) / 2;
557
+ return length3(this.newellOf(inputs.polyline.points)) / 2;
558
+ }
559
+ /**
560
+ * Measures the area of a flat outline, signed by the way it runs.
561
+ *
562
+ * The area is positive when the outline runs counter-clockwise and negative when it runs
563
+ * clockwise, so the sign tells which way an outline turns.
564
+ * Example: [[0,0], [4,0], [4,4], [0,4]] -> 16; the same corners reversed -> -16
565
+ * @param inputs - The outline's corners
566
+ * @returns The signed area in square model units
567
+ * @group polygon 2d
568
+ * @shortname signed area 2d
569
+ * @drawable false
570
+ * @example
571
+ * ```typescript
572
+ * const area = bitbybit.polyline.signedArea2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]] });
573
+ * ```
574
+ */
575
+ signedArea2d(inputs) {
576
+ return signedArea2(this.outlineOf(inputs.points));
577
+ }
578
+ /**
579
+ * Measures the length around a flat outline, its closing side included.
580
+ *
581
+ * Example: [[0,0], [3,0], [3,4]] -> 12
582
+ * @param inputs - The outline's corners
583
+ * @returns The perimeter in model units
584
+ * @group polygon 2d
585
+ * @shortname perimeter 2d
586
+ * @drawable false
587
+ * @example
588
+ * ```typescript
589
+ * const around = bitbybit.polyline.perimeter2d({ points: [[0, 0], [3, 0], [3, 4]] });
590
+ * ```
591
+ */
592
+ perimeter2d(inputs) {
593
+ return perimeter2(this.outlineOf(inputs.points));
594
+ }
595
+ /**
596
+ * Tells whether a point lies inside a flat outline.
597
+ *
598
+ * It counts the outline's sides a ray from the point crosses, so it holds for outlines that are
599
+ * not convex; a point exactly on a side may fall either way.
600
+ * Example: [2,2] in [[0,0], [4,0], [4,4], [0,4]] -> true
601
+ * @param inputs - The outline's corners and the point
602
+ * @returns True when the point is inside
603
+ * @group polygon 2d
604
+ * @shortname is point inside 2d
605
+ * @drawable false
606
+ * @example
607
+ * ```typescript
608
+ * const inside = bitbybit.polyline.isPointInside2d({ points: [[0, 0], [4, 0], [4, 4], [0, 4]], point: [2, 2] });
609
+ * ```
610
+ */
611
+ isPointInside2d(inputs) {
612
+ return isInsidePolygon2(this.pointOf(inputs.point, "point"), this.outlineOf(inputs.points));
613
+ }
614
+ /**
615
+ * Makes a flat outline run counter-clockwise, or clockwise.
616
+ *
617
+ * An outline already running that way comes back as it was; otherwise its corners are reversed.
618
+ * Example: [[0,0], [0,4], [4,4], [4,0]], counter-clockwise -> [[4,0], [4,4], [0,4], [0,0]]
619
+ * @param inputs - The outline's corners and the way it should run
620
+ * @returns The corners, running the asked way
621
+ * @group polygon 2d
622
+ * @shortname orient 2d
623
+ * @drawable false
624
+ * @example
625
+ * ```typescript
626
+ * const ccw = bitbybit.polyline.orient2d({ points: [[0, 0], [0, 4], [4, 4], [4, 0]], counterClockwise: true });
627
+ * ```
628
+ */
629
+ orient2d(inputs) {
630
+ const resolved = resolveDto(Inputs.Polyline.OrientPolygon2Dto, inputs);
631
+ return wound2(this.outlineOf(resolved.points), resolved.counterClockwise);
632
+ }
633
+ /**
634
+ * Rounds the corners of a flat outline with arcs, drawn as short straight pieces.
635
+ *
636
+ * Every corner takes `radius`, or its own entry of `radiusList`; a radius of 0 leaves it sharp.
637
+ * A radius too large for the sides beside its corner is refused.
638
+ * Example: a 10 by 10 square, radius 2 -> four quarter arcs at the corners
639
+ * @param inputs - The outline, the radius or radii and the pieces per quarter turn
640
+ * @returns The rounded outline's points
641
+ * @group polygon 2d
642
+ * @shortname round corners 2d
643
+ * @drawable false
644
+ * @example
645
+ * ```typescript
646
+ * const rounded = bitbybit.polyline.roundCorners2d({ points: [[0, 0], [10, 0], [10, 10], [0, 10]], radius: 2, segments: 8 });
647
+ * ```
648
+ */
649
+ roundCorners2d(inputs) {
650
+ var _a;
651
+ const resolved = resolveDto(Inputs.Polyline.RoundPolygon2Dto, inputs);
652
+ const points = this.outlineOf(resolved.points);
653
+ if (resolved.radiusList === undefined && !(resolved.radius >= 0)) {
654
+ throw new InputError("`radius` is not a number of 0 or more.", "radius");
655
+ }
656
+ const radii = (_a = resolved.radiusList) !== null && _a !== void 0 ? _a : points.map(() => resolved.radius);
657
+ if (radii.length !== points.length || !radii.every(radius => radius >= 0)) {
658
+ throw new InputError("`radiusList` does not hold one radius of 0 or more for each point.", "radiusList");
659
+ }
660
+ const repeated = points.findIndex((point, at) => distance2(point, points[(at + 1) % points.length]) === 0);
661
+ if (repeated >= 0) {
662
+ throw new InputError(`\`points\` holds the same point at positions ${repeated} and ${(repeated + 1) % points.length}, so the corner between them has no sides: remove one of them.`, "points");
663
+ }
664
+ const segmentsFor = this.segmentsFor(resolved.segments);
665
+ try {
666
+ return roundedCorners2(points, radii, segmentsFor);
667
+ }
668
+ catch (error) {
669
+ if (!(error instanceof InputError)) {
670
+ throw error;
671
+ }
672
+ const property = resolved.radiusList === undefined ? "radius" : "radiusList";
673
+ throw new InputError(`\`${property}\` is too large for a corner: ${error.message}.`, property);
674
+ }
675
+ }
676
+ /**
677
+ * Finds the direction a path heads in at each of its points.
678
+ *
679
+ * At an inner point it bisects the segments either side; at the ends it follows the end
680
+ * segments, unless `startTangent` or `endTangent` is given. Every direction has length 1. A
681
+ * closed polyline is refused.
682
+ * Example: [[0,0,0], [1,0,0], [1,1,0]] -> [[1,0,0], [0.707,0.707,0], [0,1,0]]
683
+ * @param inputs - The path and, optionally, its end directions
684
+ * @returns One unit direction per point
685
+ * @group sweep
686
+ * @shortname tangents
687
+ * @drawable false
688
+ * @example
689
+ * ```typescript
690
+ * const directions = bitbybit.polyline.tangents({ polyline: { points: [[0, 0, 0], [1, 0, 0], [1, 1, 0]] } });
691
+ * ```
692
+ */
693
+ tangents(inputs) {
694
+ const points = this.pathOf(inputs.polyline);
695
+ return pathTangents(points, this.directionOf(inputs.startTangent, "startTangent"), this.directionOf(inputs.endTangent, "endTangent"));
696
+ }
697
+ /**
698
+ * Places a frame at each point of a path, facing along it without twisting.
699
+ *
700
+ * Each normal is the path's direction there. Each direction, the profile's X axis, turns by the
701
+ * smallest angle between points, so a swept profile does not spin. `firstDirection` sets it at
702
+ * the start.
703
+ * Example: a straight path along X -> frames that differ only in origin
704
+ * @param inputs - The path and the first X direction
705
+ * @returns One frame per point
706
+ * @group sweep
707
+ * @shortname sweep frames
708
+ * @drawable true
709
+ * @example
710
+ * ```typescript
711
+ * const frames = bitbybit.polyline.sweepFrames({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] }, firstDirection: [1, 0, 0] });
712
+ * ```
713
+ */
714
+ sweepFrames(inputs) {
715
+ const resolved = resolveDto(Inputs.Polyline.PolylineSweepDto, inputs);
716
+ const { points, tangents, axes } = this.sweepOf(resolved);
717
+ return points.map((origin, at) => ({ origin, normal: tangents[at], direction: axes[at] }));
718
+ }
719
+ /**
720
+ * Builds a matrix per point of a path that places a flat profile there, for sweeping it.
721
+ *
722
+ * Each puts the XY plane on that point's `sweepFrames` frame, Z along the path, and stretches it
723
+ * across a bend so the pieces either side meet.
724
+ * Example: a straight path along Z -> matrices that only move up it
725
+ * @param inputs - The path and the first X direction
726
+ * @returns One placement matrix per point
727
+ * @group sweep
728
+ * @shortname sweep placements
729
+ * @drawable false
730
+ * @example
731
+ * ```typescript
732
+ * const placements = bitbybit.polyline.sweepPlacements({ polyline: { points: [[0, 0, 0], [0, 0, 5], [5, 0, 10]] } });
733
+ * const ring = bitbybit.point.transformPoints({ points: [[1, 0, 0], [0, 1, 0], [-1, 0, 0]], transformation: [placements[1]] });
734
+ * ```
735
+ */
736
+ sweepPlacements(inputs) {
737
+ const resolved = resolveDto(Inputs.Polyline.PolylineSweepDto, inputs);
738
+ const { points, tangents, axes } = this.sweepOf(resolved);
739
+ return sweepMatrices(points, tangents, axes);
740
+ }
741
+ /**
742
+ * Rounds the corners of a path in space with arcs, drawn as short straight pieces.
743
+ *
744
+ * Where the segments beside a corner are too short for `radius`, it gets the largest arc that
745
+ * fits half of each. The ends stay; a closed polyline is refused.
746
+ * Example: [[0,0,0], [10,0,0], [10,10,0]], radius 2 -> one quarter arc at the corner
747
+ * @param inputs - The path, the radius and the pieces per quarter turn
748
+ * @returns The rounded path
749
+ * @group sweep
750
+ * @shortname round corners
751
+ * @drawable true
752
+ * @example
753
+ * ```typescript
754
+ * const rounded = bitbybit.polyline.roundCorners({ polyline: { points: [[0, 0, 0], [10, 0, 0], [10, 10, 0]] }, radius: 2, segments: 8 });
755
+ * ```
756
+ */
757
+ roundCorners(inputs) {
758
+ const resolved = resolveDto(Inputs.Polyline.RoundPolylineDto, inputs);
759
+ const points = this.pathOf(resolved.polyline);
760
+ if (!(resolved.radius >= 0)) {
761
+ throw new InputError("`radius` is not a number of 0 or more.", "radius");
762
+ }
763
+ return { points: roundedPath3(points, resolved.radius, this.segmentsFor(resolved.segments)), isClosed: false };
557
764
  }
558
765
  newellOf(points) {
559
766
  return newellNormal(points.flat(), points.map((_, at) => at));
560
767
  }
768
+ sweepOf(resolved) {
769
+ var _a;
770
+ const points = this.pathOf(resolved.polyline);
771
+ const tangents = pathTangents(points);
772
+ return { points, tangents, axes: transportedAxes(points, tangents, (_a = this.directionOf(resolved.firstDirection, "firstDirection")) !== null && _a !== void 0 ? _a : [1, 0, 0]) };
773
+ }
774
+ pathOf(polyline) {
775
+ const points = polyline === null || polyline === void 0 ? void 0 : polyline.points;
776
+ if (!Array.isArray(points) || points.length < 2 || !points.every(isTriple)) {
777
+ throw new InputError("`polyline` does not hold a path of at least two points of three finite numbers.", "polyline");
778
+ }
779
+ if ((polyline === null || polyline === void 0 ? void 0 : polyline.isClosed) === true) {
780
+ throw new InputError("`polyline` is closed; give it as an open path, repeating its first point at the end to follow it all the way round.", "polyline");
781
+ }
782
+ const repeated = points.findIndex((point, at) => at > 0 && distance3(point, points[at - 1]) === 0);
783
+ if (repeated > 0) {
784
+ throw new InputError(`\`polyline\` has two points in one place, at positions ${repeated - 1} and ${repeated}.`, "polyline");
785
+ }
786
+ return points;
787
+ }
788
+ outlineOf(points) {
789
+ if (!Array.isArray(points) || points.length < MIN_OUTLINE_POINTS || !points.every(point => this.isPoint2(point))) {
790
+ throw new InputError("`points` does not hold an outline of at least three points of two finite numbers.", "points");
791
+ }
792
+ return points;
793
+ }
794
+ pointOf(point, property) {
795
+ if (!this.isPoint2(point)) {
796
+ throw new InputError(`\`${property}\` is not a point of two finite numbers.`, property);
797
+ }
798
+ return point;
799
+ }
800
+ isPoint2(value) {
801
+ return Array.isArray(value) && value.length === 2 && value.every(part => typeof part === "number" && Number.isFinite(part));
802
+ }
803
+ directionOf(direction, property) {
804
+ if (direction === undefined) {
805
+ return undefined;
806
+ }
807
+ if (!isTriple(direction) || unitOf(direction) === undefined) {
808
+ throw new InputError(`\`${property}\` is not a direction of three finite numbers with some length.`, property);
809
+ }
810
+ return direction;
811
+ }
812
+ segmentsFor(segments) {
813
+ if (!Number.isInteger(segments) || segments < 1) {
814
+ throw new InputError("`segments` is not a whole number of at least 1.", "segments");
815
+ }
816
+ return (sweep) => Math.max(1, Math.ceil(segments * sweep / QUARTER_TURN - SEGMENT_SLACK));
817
+ }
561
818
  }
@@ -0,0 +1,80 @@
1
+ import * as Inputs from "../inputs";
2
+ import type { RecipeIssue, RecipeSource, RecipeSurfaceMesh } from "../recipes/recipe-types";
3
+ /**
4
+ * Recipes with no CAD kernel needed: solids described as a list of steps that `occt.recipes` and
5
+ * `manifold.recipes` build and the `ifc` package writes, so a pipeline can hand geometry to any
6
+ * kernel as data. Check one before a kernel runs it, read one from JSON, draw its roots made of
7
+ * triangles, and find what a root places. Experimental: the recipe format may still change.
8
+ * @beta
9
+ */
10
+ export declare class Recipes {
11
+ /**
12
+ * Checks a value against the recipe format and lists what is wrong with it: steps that refer
13
+ * forward or out of range, ranges outside their buffers, coordinates that are not finite or
14
+ * too large, matrices that flatten, lists past their limits.
15
+ *
16
+ * Run it on a recipe from a file, another thread or a caller before a kernel builds it.
17
+ * @param inputs - The recipe
18
+ * @returns What is wrong, at most a hundred issues, each a path such as `nodes[3].depth` and a sentence; empty when nothing is
19
+ * @group check
20
+ * @shortname check recipe
21
+ * @drawable false
22
+ * @example
23
+ * ```typescript
24
+ * const issues = bitbybit.recipes.check({ recipe });
25
+ * const buildable = issues.length === 0;
26
+ * ```
27
+ */
28
+ check(inputs: Inputs.Recipes.RecipeDto): RecipeIssue[];
29
+ /**
30
+ * Reads a recipe whose buffers may be lists of numbers, as JSON holds them, into the typed
31
+ * arrays the format keeps, and refuses one `check` finds anything wrong with.
32
+ *
33
+ * The value given is left as it was.
34
+ * @param inputs - The recipe
35
+ * @returns The recipe with typed buffers
36
+ * @group read
37
+ * @shortname read recipe
38
+ * @drawable false
39
+ * @example
40
+ * ```typescript
41
+ * const recipe = bitbybit.recipes.read({ recipe: JSON.parse(text) });
42
+ * ```
43
+ */
44
+ read(inputs: Inputs.Recipes.RecipeDto): Inputs.Base.Recipe;
45
+ /**
46
+ * Gives the triangle meshes of the roots built from triangle nodes alone, through transforms,
47
+ * compounds and unions, placed by their matrices, so an open mesh no solid kernel accepts can
48
+ * still be drawn.
49
+ *
50
+ * A root holding any other step, such as an extrusion, gives undefined.
51
+ * @param inputs - The recipe, the roots to read and whether Z turns into Y
52
+ * @returns One mesh per root asked for, in that order: positions three numbers a vertex, indices three a triangle
53
+ * @group read
54
+ * @shortname surface meshes
55
+ * @drawable false
56
+ * @example
57
+ * ```typescript
58
+ * const [mesh] = bitbybit.recipes.surfaceMeshes({ recipe, roots: [0] });
59
+ * ```
60
+ */
61
+ surfaceMeshes(inputs: Inputs.Recipes.RecipeSurfaceMeshesDto): (RecipeSurfaceMesh | undefined)[];
62
+ /**
63
+ * Follows a node through the transforms that only turn and move to the step it places, folding
64
+ * them into the matrix, so roots that place one step through different moves share it, as an
65
+ * instanced drawing or an assembly wants.
66
+ *
67
+ * A transform that mirrors, scales or stretches stays a step of its own.
68
+ * @param inputs - The recipe, the node and what places it
69
+ * @returns The step reached and the matrix placing it
70
+ * @group read
71
+ * @shortname source of node
72
+ * @drawable false
73
+ * @example
74
+ * ```typescript
75
+ * const root = recipe.roots[0];
76
+ * const { node, matrix } = bitbybit.recipes.sourceOf({ recipe, node: root.node, matrix: root.matrix });
77
+ * ```
78
+ */
79
+ sourceOf(inputs: Inputs.Recipes.RecipeSourceDto): RecipeSource;
80
+ }
@@ -0,0 +1,107 @@
1
+ import * as Inputs from "../inputs";
2
+ import { InputError, resolveDto } from "../kernel-calls";
3
+ import { checkRecipe, toRecipe } from "../recipes/validate";
4
+ import { recipeSurfaceMeshes } from "../recipes/surface-mesh";
5
+ import { recipeSourceOf } from "../recipes/sources";
6
+ import { isIndexBelow } from "../recipes/checks";
7
+ import { isTransformMatrix } from "./helpers/geometry/matrices";
8
+ /**
9
+ * Recipes with no CAD kernel needed: solids described as a list of steps that `occt.recipes` and
10
+ * `manifold.recipes` build and the `ifc` package writes, so a pipeline can hand geometry to any
11
+ * kernel as data. Check one before a kernel runs it, read one from JSON, draw its roots made of
12
+ * triangles, and find what a root places. Experimental: the recipe format may still change.
13
+ * @beta
14
+ */
15
+ export class Recipes {
16
+ /**
17
+ * Checks a value against the recipe format and lists what is wrong with it: steps that refer
18
+ * forward or out of range, ranges outside their buffers, coordinates that are not finite or
19
+ * too large, matrices that flatten, lists past their limits.
20
+ *
21
+ * Run it on a recipe from a file, another thread or a caller before a kernel builds it.
22
+ * @param inputs - The recipe
23
+ * @returns What is wrong, at most a hundred issues, each a path such as `nodes[3].depth` and a sentence; empty when nothing is
24
+ * @group check
25
+ * @shortname check recipe
26
+ * @drawable false
27
+ * @example
28
+ * ```typescript
29
+ * const issues = bitbybit.recipes.check({ recipe });
30
+ * const buildable = issues.length === 0;
31
+ * ```
32
+ */
33
+ check(inputs) {
34
+ const resolved = resolveDto(Inputs.Recipes.RecipeDto, inputs);
35
+ return checkRecipe(resolved.recipe);
36
+ }
37
+ /**
38
+ * Reads a recipe whose buffers may be lists of numbers, as JSON holds them, into the typed
39
+ * arrays the format keeps, and refuses one `check` finds anything wrong with.
40
+ *
41
+ * The value given is left as it was.
42
+ * @param inputs - The recipe
43
+ * @returns The recipe with typed buffers
44
+ * @group read
45
+ * @shortname read recipe
46
+ * @drawable false
47
+ * @example
48
+ * ```typescript
49
+ * const recipe = bitbybit.recipes.read({ recipe: JSON.parse(text) });
50
+ * ```
51
+ */
52
+ read(inputs) {
53
+ const resolved = resolveDto(Inputs.Recipes.RecipeDto, inputs);
54
+ return toRecipe(resolved.recipe);
55
+ }
56
+ /**
57
+ * Gives the triangle meshes of the roots built from triangle nodes alone, through transforms,
58
+ * compounds and unions, placed by their matrices, so an open mesh no solid kernel accepts can
59
+ * still be drawn.
60
+ *
61
+ * A root holding any other step, such as an extrusion, gives undefined.
62
+ * @param inputs - The recipe, the roots to read and whether Z turns into Y
63
+ * @returns One mesh per root asked for, in that order: positions three numbers a vertex, indices three a triangle
64
+ * @group read
65
+ * @shortname surface meshes
66
+ * @drawable false
67
+ * @example
68
+ * ```typescript
69
+ * const [mesh] = bitbybit.recipes.surfaceMeshes({ recipe, roots: [0] });
70
+ * ```
71
+ */
72
+ surfaceMeshes(inputs) {
73
+ const resolved = resolveDto(Inputs.Recipes.RecipeSurfaceMeshesDto, inputs);
74
+ return recipeSurfaceMeshes(resolved.recipe, resolved.roots, resolved.adjustZtoY);
75
+ }
76
+ /**
77
+ * Follows a node through the transforms that only turn and move to the step it places, folding
78
+ * them into the matrix, so roots that place one step through different moves share it, as an
79
+ * instanced drawing or an assembly wants.
80
+ *
81
+ * A transform that mirrors, scales or stretches stays a step of its own.
82
+ * @param inputs - The recipe, the node and what places it
83
+ * @returns The step reached and the matrix placing it
84
+ * @group read
85
+ * @shortname source of node
86
+ * @drawable false
87
+ * @example
88
+ * ```typescript
89
+ * const root = recipe.roots[0];
90
+ * const { node, matrix } = bitbybit.recipes.sourceOf({ recipe, node: root.node, matrix: root.matrix });
91
+ * ```
92
+ */
93
+ sourceOf(inputs) {
94
+ const resolved = resolveDto(Inputs.Recipes.RecipeSourceDto, inputs);
95
+ const recipe = resolved.recipe;
96
+ if (typeof recipe !== "object" || recipe === null || !Array.isArray(recipe.nodes)) {
97
+ throw new InputError("`recipe` is not a recipe with a list of `nodes`.", "recipe");
98
+ }
99
+ if (!isTransformMatrix(resolved.matrix)) {
100
+ throw new InputError("`matrix` is not a matrix of 16 finite numbers.", "matrix");
101
+ }
102
+ if (!isIndexBelow(resolved.node, resolved.recipe.nodes.length)) {
103
+ throw new InputError(`\`node\` is not one of the recipe's ${String(resolved.recipe.nodes.length)} nodes.`, "node");
104
+ }
105
+ return recipeSourceOf(resolved.recipe, resolved.node, resolved.matrix);
106
+ }
107
+ }