@bitbybit-dev/base 1.5.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
@@ -4,8 +4,10 @@ import type { Vector } from "./vector";
4
4
  /**
5
5
  * Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods
6
6
  * here work out the plane of a triangle, the distance from a point to a plane, and where two meshes
7
- * cut through each other, as segments, as polylines or as point lists. They need no CAD kernel, so
8
- * they run on any triangulated data.
7
+ * cut through each other, as segments, as polylines or as point lists, measure the volume a closed
8
+ * mesh holds, and build simple meshes (an icosphere, a frustum). Indexed meshes, which store each
9
+ * point once, convert to and from triangle lists and take smooth or creased normals and consistent
10
+ * winding. They need no CAD kernel, so they run on any triangulated data.
9
11
  */
10
12
  export declare class MeshBitByBit {
11
13
  private readonly vector;
@@ -152,4 +154,174 @@ export declare class MeshBitByBit {
152
154
  * ```
153
155
  */
154
156
  signedVolume(inputs: Inputs.Mesh.MeshDto): number;
157
+ /**
158
+ * Tells whether two triangle meshes come within a distance of each other, touching and
159
+ * crossing included, as a quick collision test.
160
+ *
161
+ * It stops at the first triangles close enough; a mesh, or any separate piece of one, wholly
162
+ * inside a closed one counts too.
163
+ * Example: two unit cubes half a unit apart, distance 0.6 -> true; distance 0.4 -> false
164
+ * @param inputs - The two meshes and the distance
165
+ * @returns True when the meshes come within the distance
166
+ * @group measure
167
+ * @shortname meshes within
168
+ * @drawable false
169
+ * @example
170
+ * ```typescript
171
+ * const close = bitbybit.mesh.meshesWithin({ mesh1: bracket, mesh2: bolt, distance: 0.5 });
172
+ * ```
173
+ */
174
+ meshesWithin(inputs: Inputs.Mesh.MeshesWithinDto): boolean;
175
+ /**
176
+ * Tells whether a point lies inside a closed triangle mesh.
177
+ *
178
+ * Rays from the point in three directions count the triangles they cross; an odd count for
179
+ * most of them means inside. A mesh that is not closed has no inside, and the answer means
180
+ * nothing. Example: [0.5, 0.5, 0.5] in a unit cube -> true
181
+ * @param inputs - The closed mesh and the point
182
+ * @returns True when the point is inside the mesh
183
+ * @group measure
184
+ * @shortname is point inside
185
+ * @drawable false
186
+ * @example
187
+ * ```typescript
188
+ * const inside = bitbybit.mesh.isPointInside({ mesh: housing, point: [0, 0, 5] });
189
+ * ```
190
+ */
191
+ isPointInside(inputs: Inputs.Mesh.MeshPointDto): boolean;
192
+ /**
193
+ * Makes a sphere as an evenly triangulated mesh, the icosahedron split `detail` times.
194
+ *
195
+ * Its triangles are close to equal in size everywhere, unlike a sphere made of latitude and
196
+ * longitude bands, and each faces outward. Each level of detail has four times the triangles.
197
+ * Example: detail 0 -> 20 triangles, detail 2 -> 320
198
+ * @param inputs - The center, the radius and the detail
199
+ * @returns The sphere's triangles
200
+ * @group primitives
201
+ * @shortname icosphere
202
+ * @drawable true
203
+ * @example
204
+ * ```typescript
205
+ * const sphere = bitbybit.mesh.icosphere({ center: [0, 0, 0], radius: 5, detail: 3 });
206
+ * ```
207
+ */
208
+ icosphere(inputs: Inputs.Mesh.IcosphereDto): Inputs.Base.Mesh3;
209
+ /**
210
+ * Makes a cone, a cylinder or a cone with its tip cut off, as a closed triangulated mesh.
211
+ *
212
+ * It stands on `center` and rises along `direction` by `height`, with flat ends and `sides`
213
+ * flat faces around. Equal radii make a cylinder.
214
+ * Example: top radius 0, height 2 -> a cone 2 units tall
215
+ * @param inputs - The bottom center, the direction, the radii, the height and the sides
216
+ * @returns The shape's triangles
217
+ * @group primitives
218
+ * @shortname frustum
219
+ * @drawable true
220
+ * @example
221
+ * ```typescript
222
+ * const cone = bitbybit.mesh.frustum({ center: [0, 0, 0], bottomRadius: 2, topRadius: 0, height: 4, sides: 32 });
223
+ * ```
224
+ */
225
+ frustum(inputs: Inputs.Mesh.FrustumDto): Inputs.Base.Mesh3;
226
+ /**
227
+ * Turns a list of triangles into an indexed mesh, which stores each point once.
228
+ *
229
+ * Corners that agree within `tolerance` in every coordinate become one point, kept where it first
230
+ * appears, so triangles that meet share their corners and the mesh knows its neighbours.
231
+ * Example: two triangles that share an edge -> 4 points and 6 indices
232
+ * @param inputs - The triangles and the tolerance
233
+ * @returns The indexed mesh
234
+ * @group indexed
235
+ * @shortname to indexed
236
+ * @drawable false
237
+ * @example
238
+ * ```typescript
239
+ * const indexed = bitbybit.mesh.toIndexed({ mesh: bitbybit.mesh.icosphere({ radius: 1, detail: 1 }) });
240
+ * ```
241
+ */
242
+ toIndexed(inputs: Inputs.Mesh.MeshToIndexedDto): Inputs.Base.IndexedMesh;
243
+ /**
244
+ * Turns an indexed mesh back into a list of triangles, each written out as its three points.
245
+ *
246
+ * Normals the mesh carries are left out, since a triangle list has no place for them.
247
+ * Example: 4 points and indices [0, 1, 2, 1, 3, 2] -> 2 triangles
248
+ * @param inputs - The indexed mesh
249
+ * @returns The triangles
250
+ * @group indexed
251
+ * @shortname from indexed
252
+ * @drawable true
253
+ * @example
254
+ * ```typescript
255
+ * const triangles = bitbybit.mesh.fromIndexed({ mesh: { positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], indices: [0, 1, 2] } });
256
+ * ```
257
+ */
258
+ fromIndexed(inputs: Inputs.Mesh.IndexedMeshDto): Inputs.Base.Mesh3;
259
+ /**
260
+ * Gives an indexed mesh smooth normals, one per point, so it shades without visible facets.
261
+ *
262
+ * Each point's normal sums those of the triangles around it, a large triangle counting for more
263
+ * than a sliver. The points and triangles stay as they are.
264
+ * Example: a welded cube -> 2 corner normals on diagonals, 6 tipped 19.47 degrees
265
+ * @param inputs - The indexed mesh
266
+ * @returns The mesh with `normals` filled in
267
+ * @group indexed
268
+ * @shortname smooth normals
269
+ * @drawable false
270
+ * @example
271
+ * ```typescript
272
+ * const smooth = bitbybit.mesh.smoothNormals({ mesh: bitbybit.mesh.toIndexed({ mesh: bitbybit.mesh.icosphere({ radius: 1, detail: 2 }) }) });
273
+ * ```
274
+ */
275
+ smoothNormals(inputs: Inputs.Mesh.IndexedMeshDto): Inputs.Base.IndexedMesh;
276
+ /**
277
+ * Gives an indexed mesh normals that keep its sharp edges sharp and smooth the rest.
278
+ *
279
+ * Where triangles turn from each other by more than `angle`, the point between them is split,
280
+ * one copy per side, so a cube keeps hard edges while a cylinder's side shades smoothly.
281
+ * Example: a welded cube, angle 30 -> 24 points, 4 per face
282
+ * @param inputs - The indexed mesh and the angle of its sharp edges
283
+ * @returns The mesh with its points split at sharp edges and `normals` filled in
284
+ * @group indexed
285
+ * @shortname creased normals
286
+ * @drawable false
287
+ * @example
288
+ * ```typescript
289
+ * const shaded = bitbybit.mesh.creasedNormals({ mesh: indexed, angle: 30 });
290
+ * ```
291
+ */
292
+ creasedNormals(inputs: Inputs.Mesh.CreasedNormalsDto): Inputs.Base.IndexedMesh;
293
+ /**
294
+ * Splits an indexed mesh into its connected pieces and finds the triangles that wind against
295
+ * the first triangle of their piece.
296
+ *
297
+ * Triangles that share an edge belong to one piece; an edge more than two share is not followed.
298
+ * Example: two separate triangles -> count 2, nothing to turn over
299
+ * @param inputs - The indexed mesh
300
+ * @returns Per triangle, whether to turn it over and its piece, and the number of pieces
301
+ * @group indexed
302
+ * @shortname winding pieces
303
+ * @drawable false
304
+ * @example
305
+ * ```typescript
306
+ * const { count, pieces } = bitbybit.mesh.windingPieces({ mesh: indexed });
307
+ * ```
308
+ */
309
+ windingPieces(inputs: Inputs.Mesh.IndexedMeshDto): Inputs.Base.MeshWindingPieces;
310
+ /**
311
+ * Turns over the triangles of an indexed mesh that wind against the rest of their piece.
312
+ *
313
+ * Each connected piece keeps the winding most of its area has, so a few triangles written inside
314
+ * out are mended and a piece wound inward on purpose stays.
315
+ * Example: a cube with one face inside out -> every face outward
316
+ * @param inputs - The indexed mesh
317
+ * @returns The mesh with those triangles turned over; normals are left out
318
+ * @group indexed
319
+ * @shortname orient consistently
320
+ * @drawable false
321
+ * @example
322
+ * ```typescript
323
+ * const mended = bitbybit.mesh.orientConsistently({ mesh: indexed });
324
+ * ```
325
+ */
326
+ orientConsistently(inputs: Inputs.Mesh.IndexedMeshDto): Inputs.Base.IndexedMesh;
155
327
  }
@@ -1,13 +1,61 @@
1
1
  import * as Inputs from "../inputs";
2
- import { resolveDto } from "../kernel-calls";
3
- import { signedVolumeOf } from "./helpers/mesh-measures";
4
- import { triangulateFace } from "./helpers/triangulation";
2
+ import { InputError, resolveDto } from "../kernel-calls";
3
+ import { signedVolumeOf } from "./helpers/mesh/mesh-measures";
4
+ import { pointInTree, treesNested, treesWithin, triangleTree } from "./helpers/mesh/mesh-proximity";
5
+ import { triangulateFace } from "./helpers/geometry/triangulation";
6
+ import { frustum, icosphere } from "./helpers/mesh/mesh-primitives";
7
+ import { axesAlong, isTriple, pointToWorld } from "./helpers/geometry/frame-axes";
8
+ import { add3, scale3 } from "./helpers/geometry/vectors";
9
+ import { computeVertexNormals, creasedVertices } from "./helpers/mesh/mesh-normals";
10
+ import { windingComponents, windingRepairs } from "./helpers/mesh/mesh-orientation";
11
+ import { uniqueVectors } from "./helpers/geometry/vector-grid";
5
12
  const TRIANGLE_CORNERS = 3;
13
+ const MAX_ICOSPHERE_DETAIL = 6;
14
+ const MIN_FRUSTUM_SIDES = 3;
15
+ const POINT_SIZE = 3;
16
+ const MAX_CREASE_ANGLE = 180;
17
+ function arraysOf(mesh) {
18
+ const positions = mesh.flat(2);
19
+ return { positions, indices: Array.from({ length: positions.length / TRIANGLE_CORNERS }, (_, at) => at) };
20
+ }
21
+ function trianglesOf({ positions, indices }, place) {
22
+ const corner = (index) => place([positions[index * TRIANGLE_CORNERS], positions[index * TRIANGLE_CORNERS + 1], positions[index * TRIANGLE_CORNERS + 2]]);
23
+ return Array.from({ length: indices.length / TRIANGLE_CORNERS }, (_, at) => [corner(indices[at * TRIANGLE_CORNERS]), corner(indices[at * TRIANGLE_CORNERS + 1]), corner(indices[at * TRIANGLE_CORNERS + 2])]);
24
+ }
25
+ function centerOf(center) {
26
+ if (!isTriple(center)) {
27
+ throw new InputError("`center` is not a point of three finite numbers.", "center");
28
+ }
29
+ return center;
30
+ }
31
+ function cornersOf(mesh, property) {
32
+ if (!Array.isArray(mesh) || !mesh.every(triangle => Array.isArray(triangle) && triangle.length === TRIANGLE_CORNERS && triangle.every(isTriple))) {
33
+ throw new InputError(`\`${property}\` is not a list of triangles of three points each, every point three finite numbers.`, property);
34
+ }
35
+ return mesh.flat();
36
+ }
37
+ function indexedOf(mesh) {
38
+ const { positions, indices } = (typeof mesh === "object" && mesh !== null ? mesh : {});
39
+ if (!Array.isArray(positions) || positions.length % POINT_SIZE !== 0 || !positions.every(Number.isFinite)) {
40
+ throw new InputError("`mesh` does not hold `positions` as finite numbers, three for each point.", "mesh");
41
+ }
42
+ const pointCount = positions.length / POINT_SIZE;
43
+ if (!Array.isArray(indices) || indices.length % TRIANGLE_CORNERS !== 0 || !indices.every(index => Number.isInteger(index) && index >= 0 && index < pointCount)) {
44
+ throw new InputError("`mesh` does not hold `indices` as point numbers from 0 to one less than its point count, three for each triangle.", "mesh");
45
+ }
46
+ return { positions: positions, indices: indices };
47
+ }
48
+ function treeOf(mesh, property) {
49
+ const corners = cornersOf(mesh, property);
50
+ return triangleTree(corners.flat(), Array.from({ length: corners.length }, (_, at) => at));
51
+ }
6
52
  /**
7
53
  * Geometry on plain triangle meshes: a mesh is a list of triangles, each three points. The methods
8
54
  * here work out the plane of a triangle, the distance from a point to a plane, and where two meshes
9
- * cut through each other, as segments, as polylines or as point lists. They need no CAD kernel, so
10
- * they run on any triangulated data.
55
+ * cut through each other, as segments, as polylines or as point lists, measure the volume a closed
56
+ * mesh holds, and build simple meshes (an icosphere, a frustum). Indexed meshes, which store each
57
+ * point once, convert to and from triangle lists and take smooth or creased normals and consistent
58
+ * winding. They need no CAD kernel, so they run on any triangulated data.
11
59
  */
12
60
  export class MeshBitByBit {
13
61
  constructor(vector, polyline) {
@@ -328,7 +376,257 @@ export class MeshBitByBit {
328
376
  * ```
329
377
  */
330
378
  signedVolume(inputs) {
331
- const positions = inputs.mesh.flat(2);
332
- return signedVolumeOf(positions, Array.from({ length: positions.length / TRIANGLE_CORNERS }, (_, at) => at));
379
+ const { positions, indices } = arraysOf(inputs.mesh);
380
+ return signedVolumeOf(positions, indices);
381
+ }
382
+ /**
383
+ * Tells whether two triangle meshes come within a distance of each other, touching and
384
+ * crossing included, as a quick collision test.
385
+ *
386
+ * It stops at the first triangles close enough; a mesh, or any separate piece of one, wholly
387
+ * inside a closed one counts too.
388
+ * Example: two unit cubes half a unit apart, distance 0.6 -> true; distance 0.4 -> false
389
+ * @param inputs - The two meshes and the distance
390
+ * @returns True when the meshes come within the distance
391
+ * @group measure
392
+ * @shortname meshes within
393
+ * @drawable false
394
+ * @example
395
+ * ```typescript
396
+ * const close = bitbybit.mesh.meshesWithin({ mesh1: bracket, mesh2: bolt, distance: 0.5 });
397
+ * ```
398
+ */
399
+ meshesWithin(inputs) {
400
+ const resolved = resolveDto(Inputs.Mesh.MeshesWithinDto, inputs);
401
+ if (!(resolved.distance >= 0)) {
402
+ throw new InputError(`\`distance\` is ${resolved.distance}; it must be a number from 0.`, "distance");
403
+ }
404
+ const first = treeOf(resolved.mesh1, "mesh1");
405
+ const second = treeOf(resolved.mesh2, "mesh2");
406
+ return treesWithin(first, second, resolved.distance) || treesNested(first, second);
407
+ }
408
+ /**
409
+ * Tells whether a point lies inside a closed triangle mesh.
410
+ *
411
+ * Rays from the point in three directions count the triangles they cross; an odd count for
412
+ * most of them means inside. A mesh that is not closed has no inside, and the answer means
413
+ * nothing. Example: [0.5, 0.5, 0.5] in a unit cube -> true
414
+ * @param inputs - The closed mesh and the point
415
+ * @returns True when the point is inside the mesh
416
+ * @group measure
417
+ * @shortname is point inside
418
+ * @drawable false
419
+ * @example
420
+ * ```typescript
421
+ * const inside = bitbybit.mesh.isPointInside({ mesh: housing, point: [0, 0, 5] });
422
+ * ```
423
+ */
424
+ isPointInside(inputs) {
425
+ const point = inputs.point;
426
+ if (!isTriple(point)) {
427
+ throw new InputError("`point` is not a point of three finite numbers.", "point");
428
+ }
429
+ return pointInTree(treeOf(inputs.mesh, "mesh"), point);
430
+ }
431
+ /**
432
+ * Makes a sphere as an evenly triangulated mesh, the icosahedron split `detail` times.
433
+ *
434
+ * Its triangles are close to equal in size everywhere, unlike a sphere made of latitude and
435
+ * longitude bands, and each faces outward. Each level of detail has four times the triangles.
436
+ * Example: detail 0 -> 20 triangles, detail 2 -> 320
437
+ * @param inputs - The center, the radius and the detail
438
+ * @returns The sphere's triangles
439
+ * @group primitives
440
+ * @shortname icosphere
441
+ * @drawable true
442
+ * @example
443
+ * ```typescript
444
+ * const sphere = bitbybit.mesh.icosphere({ center: [0, 0, 0], radius: 5, detail: 3 });
445
+ * ```
446
+ */
447
+ icosphere(inputs) {
448
+ const resolved = resolveDto(Inputs.Mesh.IcosphereDto, inputs);
449
+ if (!(resolved.radius > 0 && resolved.radius < Infinity)) {
450
+ throw new InputError("`radius` is not a number above 0.", "radius");
451
+ }
452
+ if (!Number.isInteger(resolved.detail) || resolved.detail < 0 || resolved.detail > MAX_ICOSPHERE_DETAIL) {
453
+ throw new InputError(`\`detail\` is not a whole number from 0 to ${MAX_ICOSPHERE_DETAIL}.`, "detail");
454
+ }
455
+ const center = centerOf(resolved.center);
456
+ return trianglesOf(icosphere(resolved.detail), position => add3(center, scale3(position, resolved.radius)));
457
+ }
458
+ /**
459
+ * Makes a cone, a cylinder or a cone with its tip cut off, as a closed triangulated mesh.
460
+ *
461
+ * It stands on `center` and rises along `direction` by `height`, with flat ends and `sides`
462
+ * flat faces around. Equal radii make a cylinder.
463
+ * Example: top radius 0, height 2 -> a cone 2 units tall
464
+ * @param inputs - The bottom center, the direction, the radii, the height and the sides
465
+ * @returns The shape's triangles
466
+ * @group primitives
467
+ * @shortname frustum
468
+ * @drawable true
469
+ * @example
470
+ * ```typescript
471
+ * const cone = bitbybit.mesh.frustum({ center: [0, 0, 0], bottomRadius: 2, topRadius: 0, height: 4, sides: 32 });
472
+ * ```
473
+ */
474
+ frustum(inputs) {
475
+ const resolved = resolveDto(Inputs.Mesh.FrustumDto, inputs);
476
+ if (!(resolved.bottomRadius >= 0 && resolved.topRadius >= 0 && resolved.bottomRadius + resolved.topRadius > 0)) {
477
+ throw new InputError("`bottomRadius` and `topRadius` are not numbers of 0 or more with at least one above 0.", resolved.bottomRadius >= 0 ? "topRadius" : "bottomRadius");
478
+ }
479
+ if (!(resolved.height > 0 && resolved.height < Infinity)) {
480
+ throw new InputError("`height` is not a number above 0.", "height");
481
+ }
482
+ if (!Number.isInteger(resolved.sides) || resolved.sides < MIN_FRUSTUM_SIDES) {
483
+ throw new InputError(`\`sides\` is not a whole number of at least ${MIN_FRUSTUM_SIDES}.`, "sides");
484
+ }
485
+ const center = centerOf(resolved.center);
486
+ const axes = isTriple(resolved.direction) ? axesAlong(center, resolved.direction) : undefined;
487
+ if (axes === undefined) {
488
+ throw new InputError("`direction` is not a vector of three finite numbers with a length.", "direction");
489
+ }
490
+ return trianglesOf(frustum(resolved.sides, resolved.bottomRadius, resolved.topRadius, resolved.height), position => pointToWorld(axes, position));
491
+ }
492
+ /**
493
+ * Turns a list of triangles into an indexed mesh, which stores each point once.
494
+ *
495
+ * Corners that agree within `tolerance` in every coordinate become one point, kept where it first
496
+ * appears, so triangles that meet share their corners and the mesh knows its neighbours.
497
+ * Example: two triangles that share an edge -> 4 points and 6 indices
498
+ * @param inputs - The triangles and the tolerance
499
+ * @returns The indexed mesh
500
+ * @group indexed
501
+ * @shortname to indexed
502
+ * @drawable false
503
+ * @example
504
+ * ```typescript
505
+ * const indexed = bitbybit.mesh.toIndexed({ mesh: bitbybit.mesh.icosphere({ radius: 1, detail: 1 }) });
506
+ * ```
507
+ */
508
+ toIndexed(inputs) {
509
+ const resolved = resolveDto(Inputs.Mesh.MeshToIndexedDto, inputs);
510
+ if (!(resolved.tolerance >= 0)) {
511
+ throw new InputError("`tolerance` is not a number of 0 or more.", "tolerance");
512
+ }
513
+ const { kept, indexes } = uniqueVectors(cornersOf(resolved.mesh, "mesh"), resolved.tolerance);
514
+ return { positions: kept.flat(), indices: indexes };
515
+ }
516
+ /**
517
+ * Turns an indexed mesh back into a list of triangles, each written out as its three points.
518
+ *
519
+ * Normals the mesh carries are left out, since a triangle list has no place for them.
520
+ * Example: 4 points and indices [0, 1, 2, 1, 3, 2] -> 2 triangles
521
+ * @param inputs - The indexed mesh
522
+ * @returns The triangles
523
+ * @group indexed
524
+ * @shortname from indexed
525
+ * @drawable true
526
+ * @example
527
+ * ```typescript
528
+ * const triangles = bitbybit.mesh.fromIndexed({ mesh: { positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], indices: [0, 1, 2] } });
529
+ * ```
530
+ */
531
+ fromIndexed(inputs) {
532
+ return trianglesOf(indexedOf(inputs.mesh), position => position);
533
+ }
534
+ /**
535
+ * Gives an indexed mesh smooth normals, one per point, so it shades without visible facets.
536
+ *
537
+ * Each point's normal sums those of the triangles around it, a large triangle counting for more
538
+ * than a sliver. The points and triangles stay as they are.
539
+ * Example: a welded cube -> 2 corner normals on diagonals, 6 tipped 19.47 degrees
540
+ * @param inputs - The indexed mesh
541
+ * @returns The mesh with `normals` filled in
542
+ * @group indexed
543
+ * @shortname smooth normals
544
+ * @drawable false
545
+ * @example
546
+ * ```typescript
547
+ * const smooth = bitbybit.mesh.smoothNormals({ mesh: bitbybit.mesh.toIndexed({ mesh: bitbybit.mesh.icosphere({ radius: 1, detail: 2 }) }) });
548
+ * ```
549
+ */
550
+ smoothNormals(inputs) {
551
+ const { positions, indices } = indexedOf(inputs.mesh);
552
+ return { positions: positions.slice(), indices: indices.slice(), normals: computeVertexNormals(positions, indices) };
553
+ }
554
+ /**
555
+ * Gives an indexed mesh normals that keep its sharp edges sharp and smooth the rest.
556
+ *
557
+ * Where triangles turn from each other by more than `angle`, the point between them is split,
558
+ * one copy per side, so a cube keeps hard edges while a cylinder's side shades smoothly.
559
+ * Example: a welded cube, angle 30 -> 24 points, 4 per face
560
+ * @param inputs - The indexed mesh and the angle of its sharp edges
561
+ * @returns The mesh with its points split at sharp edges and `normals` filled in
562
+ * @group indexed
563
+ * @shortname creased normals
564
+ * @drawable false
565
+ * @example
566
+ * ```typescript
567
+ * const shaded = bitbybit.mesh.creasedNormals({ mesh: indexed, angle: 30 });
568
+ * ```
569
+ */
570
+ creasedNormals(inputs) {
571
+ const resolved = resolveDto(Inputs.Mesh.CreasedNormalsDto, inputs);
572
+ const { positions, indices } = indexedOf(resolved.mesh);
573
+ if (!(resolved.angle >= 0 && resolved.angle <= MAX_CREASE_ANGLE)) {
574
+ throw new InputError(`\`angle\` is not a number of degrees from 0 to ${MAX_CREASE_ANGLE}.`, "angle");
575
+ }
576
+ const creased = creasedVertices(positions, indices, resolved.angle);
577
+ return {
578
+ positions: Array.from(creased.sources).flatMap(source => positions.slice(source * POINT_SIZE, source * POINT_SIZE + POINT_SIZE)),
579
+ indices: Array.from(creased.indices),
580
+ normals: Array.from(creased.normals),
581
+ };
582
+ }
583
+ /**
584
+ * Splits an indexed mesh into its connected pieces and finds the triangles that wind against
585
+ * the first triangle of their piece.
586
+ *
587
+ * Triangles that share an edge belong to one piece; an edge more than two share is not followed.
588
+ * Example: two separate triangles -> count 2, nothing to turn over
589
+ * @param inputs - The indexed mesh
590
+ * @returns Per triangle, whether to turn it over and its piece, and the number of pieces
591
+ * @group indexed
592
+ * @shortname winding pieces
593
+ * @drawable false
594
+ * @example
595
+ * ```typescript
596
+ * const { count, pieces } = bitbybit.mesh.windingPieces({ mesh: indexed });
597
+ * ```
598
+ */
599
+ windingPieces(inputs) {
600
+ const { indices } = indexedOf(inputs.mesh);
601
+ const { flips, component, count } = windingComponents(indices);
602
+ return { turnOver: Array.from(flips, flip => flip === 1), pieces: Array.from(component), count };
603
+ }
604
+ /**
605
+ * Turns over the triangles of an indexed mesh that wind against the rest of their piece.
606
+ *
607
+ * Each connected piece keeps the winding most of its area has, so a few triangles written inside
608
+ * out are mended and a piece wound inward on purpose stays.
609
+ * Example: a cube with one face inside out -> every face outward
610
+ * @param inputs - The indexed mesh
611
+ * @returns The mesh with those triangles turned over; normals are left out
612
+ * @group indexed
613
+ * @shortname orient consistently
614
+ * @drawable false
615
+ * @example
616
+ * ```typescript
617
+ * const mended = bitbybit.mesh.orientConsistently({ mesh: indexed });
618
+ * ```
619
+ */
620
+ orientConsistently(inputs) {
621
+ const { positions, indices } = indexedOf(inputs.mesh);
622
+ const repairs = windingRepairs(positions, indices);
623
+ const turned = indices.slice();
624
+ repairs.forEach((repair, triangle) => {
625
+ if (repair === 1) {
626
+ turned[triangle * TRIANGLE_CORNERS + 1] = indices[triangle * TRIANGLE_CORNERS + 2];
627
+ turned[triangle * TRIANGLE_CORNERS + 2] = indices[triangle * TRIANGLE_CORNERS + 1];
628
+ }
629
+ });
630
+ return { positions: positions.slice(), indices: turned };
333
631
  }
334
632
  }
@@ -1,6 +1,7 @@
1
1
  import * as Inputs from "../inputs";
2
2
  import { InputError, resolveDto } from "../kernel-calls";
3
- import { arcThroughThreePoints, pointsOnArc } from "./helpers/arcs";
3
+ import { arcThroughThreePoints, pointsOnArc } from "./helpers/geometry/arcs";
4
+ import { add3, length3, scale3, subtract3 } from "./helpers/geometry/vectors";
4
5
  /**
5
6
  * Points as plain number arrays. A point is `[x, y, z]` with Y pointing up, the same shape as a
6
7
  * vector, so the two can be passed to each other's methods; a 2D point is `[x, y]`. Every method
@@ -248,11 +249,7 @@ export class Point {
248
249
  });
249
250
  const min = [Math.min(...xVals), Math.min(...yVals), Math.min(...zVals)];
250
251
  const max = [Math.max(...xVals), Math.max(...yVals), Math.max(...zVals)];
251
- const center = [
252
- (min[0] + max[0]) / 2,
253
- (min[1] + max[1]) / 2,
254
- (min[2] + max[2]) / 2,
255
- ];
252
+ const center = scale3(add3(min, max), 1 / 2);
256
253
  const width = max[0] - min[0];
257
254
  const height = max[1] - min[1];
258
255
  const length = max[2] - min[2];
@@ -331,10 +328,7 @@ export class Point {
331
328
  * ```
332
329
  */
333
330
  distance(inputs) {
334
- const x = inputs.endPoint[0] - inputs.startPoint[0];
335
- const y = inputs.endPoint[1] - inputs.startPoint[1];
336
- const z = inputs.endPoint[2] - inputs.startPoint[2];
337
- return Math.sqrt(x * x + y * y + z * z);
331
+ return length3(subtract3(inputs.endPoint, inputs.startPoint));
338
332
  }
339
333
  /**
340
334
  * Measures the distance from one point to each point in a list.
@@ -0,0 +1,6 @@
1
+ import type * as Inputs from "../inputs";
2
+ export interface SweepPath {
3
+ readonly points: Inputs.Base.Point3[];
4
+ readonly tangents: Inputs.Base.Vector3[];
5
+ readonly axes: Inputs.Base.Vector3[];
6
+ }
@@ -0,0 +1 @@
1
+ export {};