@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
@@ -0,0 +1,12 @@
1
+ import type { UniqueVectors } from "../helper-types";
2
+ /**
3
+ * Keeps the first of every group of vectors that agree within `tolerance` in each component, and
4
+ * says for every vector given which kept one it matched: the first in order, as a plain scan finds.
5
+ * Kept vectors are filed in a grid of cells a few tolerances wide, so a vector is compared only with
6
+ * those in the cells it could match. The grid only narrows the candidates; every one is still
7
+ * compared component by component. A vector the grid cannot place (a component not finite, a
8
+ * tolerance that is not positive and finite, a magnitude where the cell arithmetic stops being exact)
9
+ * is compared with every kept vector instead, and kept ones of that kind are held apart, where the
10
+ * grid path looks too.
11
+ */
12
+ export declare const uniqueVectors: (vectors: readonly number[][], tolerance: number) => UniqueVectors;
@@ -0,0 +1,149 @@
1
+ const CELL_KEY_DIMENSIONS = 6;
2
+ const CELL_SIZE_IN_TOLERANCES = 8;
3
+ const CELL_PROBE_MARGIN_IN_TOLERANCES = 1.5;
4
+ const EXACT_CELL_BITS = 50;
5
+ const CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE = Math.pow(2, EXACT_CELL_BITS);
6
+ const CELL_HASH_WORD = 4294967296;
7
+ const HASH_SEED = 0x9E3779B1;
8
+ const HASH_MIX_LOW = 0x85EBCA6B;
9
+ const HASH_MIX_HIGH = 0xC2B2AE35;
10
+ const HASH_FOLD_SHIFT = 15;
11
+ const hashCells = (vectorLength, cells) => {
12
+ let hash = Math.imul(vectorLength + 1, HASH_SEED);
13
+ for (let i = 0; i < cells.length; i++) {
14
+ const cell = cells[i];
15
+ const lowWord = cell % CELL_HASH_WORD;
16
+ const highWord = (cell - lowWord) / CELL_HASH_WORD;
17
+ hash = Math.imul(hash ^ lowWord, HASH_MIX_LOW);
18
+ hash = Math.imul(hash ^ highWord, HASH_MIX_HIGH);
19
+ hash ^= hash >>> HASH_FOLD_SHIFT;
20
+ }
21
+ return hash;
22
+ };
23
+ const neverMatchesAnyVector = (vector, tolerance) => {
24
+ for (let i = 0; i < vector.length; i++) {
25
+ if (!Number.isFinite(vector[i])) {
26
+ return true;
27
+ }
28
+ }
29
+ return vector.length > 0 && !(tolerance > 0);
30
+ };
31
+ const sameWithin = (vector, other, tolerance) => {
32
+ if (vector.length !== other.length) {
33
+ return false;
34
+ }
35
+ for (let i = 0; i < vector.length; i++) {
36
+ if (!(Math.abs(vector[i] - other[i]) < tolerance)) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ };
42
+ const vectorCellRange = (vector, tolerance) => {
43
+ const keyDimensions = Math.min(vector.length, CELL_KEY_DIMENSIONS);
44
+ if (keyDimensions > 0 && !Number.isFinite(tolerance)) {
45
+ return undefined;
46
+ }
47
+ const cellSize = tolerance * CELL_SIZE_IN_TOLERANCES;
48
+ const probeMargin = tolerance * CELL_PROBE_MARGIN_IN_TOLERANCES;
49
+ const center = [];
50
+ const lowest = [];
51
+ const highest = [];
52
+ for (let i = 0; i < keyDimensions; i++) {
53
+ const component = vector[i];
54
+ if (Math.abs(component) / tolerance >= CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE) {
55
+ return undefined;
56
+ }
57
+ const lowestCell = Math.floor((component - probeMargin) / cellSize);
58
+ const highestCell = Math.floor((component + probeMargin) / cellSize);
59
+ const cellsToProbe = highestCell - lowestCell + 1;
60
+ if (!Number.isInteger(lowestCell) || !Number.isInteger(highestCell) || cellsToProbe < 1 || cellsToProbe > 2) {
61
+ return undefined;
62
+ }
63
+ center.push(Math.floor(component / cellSize));
64
+ lowest.push(lowestCell);
65
+ highest.push(highestCell);
66
+ }
67
+ return { center, lowest, highest };
68
+ };
69
+ const firstMatchInCells = (keptByCell, vectorLength, cellRange, matches) => {
70
+ var _a;
71
+ const { lowest, highest } = cellRange;
72
+ const probe = lowest.slice();
73
+ let first;
74
+ for (;;) {
75
+ for (const index of (_a = keptByCell.get(hashCells(vectorLength, probe))) !== null && _a !== void 0 ? _a : []) {
76
+ if ((first === undefined || index < first) && matches(index)) {
77
+ first = index;
78
+ }
79
+ }
80
+ let dimension = probe.length - 1;
81
+ while (dimension >= 0 && probe[dimension] === highest[dimension]) {
82
+ probe[dimension] = lowest[dimension];
83
+ dimension--;
84
+ }
85
+ if (dimension < 0) {
86
+ return first;
87
+ }
88
+ probe[dimension] = probe[dimension] + 1;
89
+ }
90
+ };
91
+ const addToCell = (keptByCell, vectorLength, cellRange, index) => {
92
+ const cellKey = hashCells(vectorLength, cellRange.center);
93
+ const cell = keptByCell.get(cellKey);
94
+ if (cell === undefined) {
95
+ keptByCell.set(cellKey, [index]);
96
+ }
97
+ else {
98
+ cell.push(index);
99
+ }
100
+ };
101
+ /**
102
+ * Keeps the first of every group of vectors that agree within `tolerance` in each component, and
103
+ * says for every vector given which kept one it matched: the first in order, as a plain scan finds.
104
+ * Kept vectors are filed in a grid of cells a few tolerances wide, so a vector is compared only with
105
+ * those in the cells it could match. The grid only narrows the candidates; every one is still
106
+ * compared component by component. A vector the grid cannot place (a component not finite, a
107
+ * tolerance that is not positive and finite, a magnitude where the cell arithmetic stops being exact)
108
+ * is compared with every kept vector instead, and kept ones of that kind are held apart, where the
109
+ * grid path looks too.
110
+ */
111
+ export const uniqueVectors = (vectors, tolerance) => {
112
+ const kept = [];
113
+ const indexes = [];
114
+ const keptByCell = new Map();
115
+ const keptOutsideCells = [];
116
+ const keep = (vector) => kept.push(vector) - 1;
117
+ for (const vector of vectors) {
118
+ if (neverMatchesAnyVector(vector, tolerance)) {
119
+ indexes.push(keep(vector));
120
+ continue;
121
+ }
122
+ const matches = (index) => sameWithin(vector, kept[index], tolerance);
123
+ const cellRange = vectorCellRange(vector, tolerance);
124
+ if (cellRange === undefined) {
125
+ const found = kept.findIndex((_, index) => matches(index));
126
+ if (found >= 0) {
127
+ indexes.push(found);
128
+ }
129
+ else {
130
+ const index = keep(vector);
131
+ keptOutsideCells.push(index);
132
+ indexes.push(index);
133
+ }
134
+ continue;
135
+ }
136
+ const inCells = firstMatchInCells(keptByCell, vector.length, cellRange, matches);
137
+ const outside = keptOutsideCells.find(matches);
138
+ const found = inCells === undefined ? outside : outside === undefined ? inCells : Math.min(inCells, outside);
139
+ if (found === undefined) {
140
+ const index = keep(vector);
141
+ addToCell(keptByCell, vector.length, cellRange, index);
142
+ indexes.push(index);
143
+ }
144
+ else {
145
+ indexes.push(found);
146
+ }
147
+ }
148
+ return { kept, indexes };
149
+ };
@@ -1,4 +1,4 @@
1
- import type * as Inputs from "../../inputs";
1
+ import type * as Inputs from "../../../inputs";
2
2
  type Vec2 = Inputs.Base.Vector2;
3
3
  type Vec3 = Inputs.Base.Vector3;
4
4
  export declare const add2: (a: Vec2, b: Vec2) => Vec2;
@@ -7,12 +7,19 @@ export declare const scale2: (a: Vec2, factor: number) => Vec2;
7
7
  export declare const dot2: (a: Vec2, b: Vec2) => number;
8
8
  export declare const cross2: (a: Vec2, b: Vec2) => number;
9
9
  export declare const length2: (a: Vec2) => number;
10
+ export declare const distance2: (a: Vec2, b: Vec2) => number;
10
11
  export declare const leftOf2: (a: Vec2) => Vec2;
12
+ export declare const between2: (a: Vec2, b: Vec2, share: number) => Vec2;
13
+ export declare const polar2: (radius: number, angle: number) => Vec2;
14
+ export declare const rotated2: (a: Vec2, angle: number) => Vec2;
11
15
  export declare const unit2Of: (a: Vec2) => Vec2 | undefined;
16
+ export declare const unitVectorOf: (vector: readonly number[]) => number[] | undefined;
12
17
  export declare const add3: (a: Vec3, b: Vec3) => Vec3;
13
18
  export declare const subtract3: (a: Vec3, b: Vec3) => Vec3;
14
19
  export declare const scale3: (a: Vec3, factor: number) => Vec3;
15
20
  export declare const dot3: (a: Vec3, b: Vec3) => number;
16
21
  export declare const cross3: (a: Vec3, b: Vec3) => Vec3;
17
22
  export declare const length3: (a: Vec3) => number;
23
+ export declare const between3: (a: Vec3, b: Vec3, share: number) => Vec3;
24
+ export declare const distance3: (a: Vec3, b: Vec3) => number;
18
25
  export {};
@@ -0,0 +1,43 @@
1
+ const PLANE_Z = 0;
2
+ export const add2 = (a, b) => [a[0] + b[0], a[1] + b[1]];
3
+ export const subtract2 = (a, b) => [a[0] - b[0], a[1] - b[1]];
4
+ export const scale2 = (a, factor) => [a[0] * factor, a[1] * factor];
5
+ export const dot2 = (a, b) => a[0] * b[0] + a[1] * b[1];
6
+ export const cross2 = (a, b) => a[0] * b[1] - a[1] * b[0];
7
+ export const length2 = (a) => Math.sqrt(a[0] * a[0] + a[1] * a[1]);
8
+ export const distance2 = (a, b) => length2(subtract2(a, b));
9
+ export const leftOf2 = (a) => [-a[1], a[0]];
10
+ export const between2 = (a, b, share) => [a[0] + (b[0] - a[0]) * share, a[1] + (b[1] - a[1]) * share];
11
+ export const polar2 = (radius, angle) => [radius * Math.cos(angle), radius * Math.sin(angle)];
12
+ export const rotated2 = (a, angle) => {
13
+ const cos = Math.cos(angle);
14
+ const sin = Math.sin(angle);
15
+ return [a[0] * cos - a[1] * sin, a[0] * sin + a[1] * cos];
16
+ };
17
+ export const unit2Of = (a) => {
18
+ const largest = Math.max(Math.abs(a[0]), Math.abs(a[1]));
19
+ if (!(largest > 0 && largest < Infinity)) {
20
+ return undefined;
21
+ }
22
+ const x = a[0] / largest;
23
+ const y = a[1] / largest;
24
+ const length = Math.hypot(x, y, PLANE_Z);
25
+ return [x / length, y / length];
26
+ };
27
+ export const unitVectorOf = (vector) => {
28
+ const largest = Math.max(...vector.map(Math.abs));
29
+ if (!(largest > 0 && largest < Infinity)) {
30
+ return undefined;
31
+ }
32
+ const scaled = vector.map(value => value / largest);
33
+ const length = Math.hypot(...scaled);
34
+ return scaled.map(value => value / length);
35
+ };
36
+ export const add3 = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
37
+ export const subtract3 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
38
+ export const scale3 = (a, factor) => [a[0] * factor, a[1] * factor, a[2] * factor];
39
+ export const dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
40
+ export const cross3 = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
41
+ export const length3 = (a) => Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
42
+ export const between3 = (a, b, share) => [a[0] + (b[0] - a[0]) * share, a[1] + (b[1] - a[1]) * share, a[2] + (b[2] - a[2]) * share];
43
+ export const distance3 = (a, b) => length3(subtract3(a, b));
@@ -32,3 +32,60 @@ export interface RefinedSurfaceMesh {
32
32
  readonly positions: Inputs.Base.Point3[];
33
33
  readonly triangles: number[];
34
34
  }
35
+ export interface WindingComponents {
36
+ readonly flips: Uint8Array;
37
+ readonly component: Int32Array;
38
+ readonly count: number;
39
+ }
40
+ export interface EdgeUses {
41
+ readonly uses: Map<number, number[]>;
42
+ readonly stride: number;
43
+ }
44
+ export interface TriangleTree {
45
+ readonly corners: Float64Array;
46
+ readonly boxes: Float64Array;
47
+ readonly starts: Uint32Array;
48
+ readonly counts: Uint32Array;
49
+ readonly lefts: Int32Array;
50
+ readonly rights: Int32Array;
51
+ }
52
+ export interface TreeBox {
53
+ readonly min: Inputs.Base.Point3;
54
+ readonly max: Inputs.Base.Point3;
55
+ }
56
+ export interface VectorCellRange {
57
+ readonly center: number[];
58
+ readonly lowest: number[];
59
+ readonly highest: number[];
60
+ }
61
+ export interface UniqueVectors {
62
+ readonly kept: number[][];
63
+ readonly indexes: number[];
64
+ }
65
+ export interface CreasedVertices {
66
+ readonly sources: Uint32Array;
67
+ readonly normals: Float64Array;
68
+ readonly indices: Uint32Array;
69
+ }
70
+ export interface RoundedCorner {
71
+ readonly corner: Inputs.Base.Point2;
72
+ readonly radius: number;
73
+ readonly toPrevious: Inputs.Base.Vector2;
74
+ readonly toNext: Inputs.Base.Vector2;
75
+ readonly half: number;
76
+ readonly reach: number;
77
+ }
78
+ export interface GltfNode {
79
+ readonly name?: string;
80
+ readonly scale?: readonly number[];
81
+ readonly children?: readonly number[];
82
+ }
83
+ export interface GltfScene {
84
+ readonly nodes?: readonly number[];
85
+ }
86
+ export interface GltfJson {
87
+ readonly scene?: number;
88
+ readonly scenes?: readonly GltfScene[];
89
+ readonly nodes?: readonly GltfNode[];
90
+ }
91
+ export type UnitOfLength = `${Inputs.Base.unitOfLengthEnum}`;
@@ -0,0 +1,21 @@
1
+ import type { CreasedMesh, CreasedVertices } from "../helper-types";
2
+ /**
3
+ * Smooth normals for a mesh that arrives without them: each point takes the sum of the normals of
4
+ * the triangles around it, each as long as twice its triangle's area, scaled to length 1, so a large
5
+ * triangle counts for more than a sliver and the mesh shades smoothly. A point that no triangle with
6
+ * an area touches keeps a normal of zero.
7
+ * @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
8
+ * @param indices - Triangle indices
9
+ * @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
10
+ */
11
+ export declare function computeVertexNormals(positions: ArrayLike<number>, indices: ArrayLike<number>): number[];
12
+ /**
13
+ * Normals that keep sharp edges sharp: around each point, a triangle's corner takes the
14
+ * area-weighted sum of the normals of the triangles around that point that turn from it by less than
15
+ * `minSharpAngle` degrees. Where corners of one point end up with different normals the point is
16
+ * split, so a cube keeps hard edges while a cylinder's side stays smooth. Gives, for each point made,
17
+ * the point it was made from, its normal, and the triangles over the points made; points no
18
+ * triangle uses are left out.
19
+ */
20
+ export declare const creasedVertices: (positions: ArrayLike<number>, indices: ArrayLike<number>, minSharpAngle: number) => CreasedVertices;
21
+ export declare const creasedMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, minSharpAngle: number) => CreasedMesh;
@@ -1,67 +1,9 @@
1
+ import { radiansOf } from "../geometry/scalars";
1
2
  const CORNERS = 3;
2
3
  const COORDINATES = 3;
3
- const X = 0;
4
4
  const Y = 1;
5
5
  const Z = 2;
6
- const HALF_TURN_DEGREES = 180;
7
- const DEGREES_TO_RADIANS = Math.PI / HALF_TURN_DEGREES;
8
6
  const ANGLE_SLACK = 1e-9;
9
- /**
10
- * Compute smooth vertex normals for a mesh that arrives without them.
11
- * Accumulates each triangle's cross product onto its three vertices, then normalizes, so a vertex
12
- * shared by several triangles ends up with their average and the mesh shades smoothly.
13
- * @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
14
- * @param indices - Triangle indices
15
- * @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
16
- */
17
- export function computeVertexNormals(positions, indices) {
18
- const numVertices = positions.length / COORDINATES;
19
- const normals = new Float32Array(positions.length);
20
- for (let i = 0; i < indices.length; i += CORNERS) {
21
- const i0 = indices[i];
22
- const i1 = indices[i + 1];
23
- const i2 = indices[i + 2];
24
- const v0x = positions[i0 * COORDINATES + X];
25
- const v0y = positions[i0 * COORDINATES + Y];
26
- const v0z = positions[i0 * COORDINATES + Z];
27
- const v1x = positions[i1 * COORDINATES + X];
28
- const v1y = positions[i1 * COORDINATES + Y];
29
- const v1z = positions[i1 * COORDINATES + Z];
30
- const v2x = positions[i2 * COORDINATES + X];
31
- const v2y = positions[i2 * COORDINATES + Y];
32
- const v2z = positions[i2 * COORDINATES + Z];
33
- const e1x = v1x - v0x;
34
- const e1y = v1y - v0y;
35
- const e1z = v1z - v0z;
36
- const e2x = v2x - v0x;
37
- const e2y = v2y - v0y;
38
- const e2z = v2z - v0z;
39
- const nx = e1y * e2z - e1z * e2y;
40
- const ny = e1z * e2x - e1x * e2z;
41
- const nz = e1x * e2y - e1y * e2x;
42
- normals[i0 * COORDINATES + X] += nx;
43
- normals[i0 * COORDINATES + Y] += ny;
44
- normals[i0 * COORDINATES + Z] += nz;
45
- normals[i1 * COORDINATES + X] += nx;
46
- normals[i1 * COORDINATES + Y] += ny;
47
- normals[i1 * COORDINATES + Z] += nz;
48
- normals[i2 * COORDINATES + X] += nx;
49
- normals[i2 * COORDINATES + Y] += ny;
50
- normals[i2 * COORDINATES + Z] += nz;
51
- }
52
- for (let i = 0; i < numVertices; i++) {
53
- const x = normals[i * COORDINATES + X];
54
- const y = normals[i * COORDINATES + Y];
55
- const z = normals[i * COORDINATES + Z];
56
- const len = Math.sqrt(x * x + y * y + z * z);
57
- if (len > 0) {
58
- normals[i * COORDINATES + X] = x / len;
59
- normals[i * COORDINATES + Y] = y / len;
60
- normals[i * COORDINATES + Z] = z / len;
61
- }
62
- }
63
- return Array.from(normals);
64
- }
65
7
  const faceNormalsOf = (positions, indices) => {
66
8
  const normals = new Float64Array(indices.length);
67
9
  for (let at = 0; at + CORNERS - 1 < indices.length; at += CORNERS) {
@@ -95,7 +37,44 @@ const facesAround = (indices, vertexCount) => {
95
37
  }
96
38
  return [starts, faces];
97
39
  };
98
- export const creasedMesh = (positions, indices, minSharpAngle) => {
40
+ /**
41
+ * Smooth normals for a mesh that arrives without them: each point takes the sum of the normals of
42
+ * the triangles around it, each as long as twice its triangle's area, scaled to length 1, so a large
43
+ * triangle counts for more than a sliver and the mesh shades smoothly. A point that no triangle with
44
+ * an area touches keeps a normal of zero.
45
+ * @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
46
+ * @param indices - Triangle indices
47
+ * @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
48
+ */
49
+ export function computeVertexNormals(positions, indices) {
50
+ const faces = faceNormalsOf(positions, indices);
51
+ const normals = new Float64Array(positions.length);
52
+ for (let corner = 0; corner < faces.length; corner++) {
53
+ const face = corner - corner % CORNERS;
54
+ const at = indices[corner] * COORDINATES;
55
+ normals[at] = normals[at] + faces[face];
56
+ normals[at + Y] = normals[at + Y] + faces[face + Y];
57
+ normals[at + Z] = normals[at + Z] + faces[face + Z];
58
+ }
59
+ for (let at = 0; at + Z < normals.length; at += COORDINATES) {
60
+ const length = Math.hypot(normals[at], normals[at + Y], normals[at + Z]);
61
+ if (length > 0) {
62
+ normals[at] = normals[at] / length;
63
+ normals[at + Y] = normals[at + Y] / length;
64
+ normals[at + Z] = normals[at + Z] / length;
65
+ }
66
+ }
67
+ return Array.from(normals);
68
+ }
69
+ /**
70
+ * Normals that keep sharp edges sharp: around each point, a triangle's corner takes the
71
+ * area-weighted sum of the normals of the triangles around that point that turn from it by less than
72
+ * `minSharpAngle` degrees. Where corners of one point end up with different normals the point is
73
+ * split, so a cube keeps hard edges while a cylinder's side stays smooth. Gives, for each point made,
74
+ * the point it was made from, its normal, and the triangles over the points made; points no
75
+ * triangle uses are left out.
76
+ */
77
+ export const creasedVertices = (positions, indices, minSharpAngle) => {
99
78
  const vertexCount = Math.floor(positions.length / COORDINATES);
100
79
  const triangleCount = Math.floor(indices.length / CORNERS);
101
80
  const weighted = faceNormalsOf(positions, indices);
@@ -104,8 +83,8 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
104
83
  lengths[face] = Math.hypot(weighted[face * COORDINATES], weighted[face * COORDINATES + Y], weighted[face * COORDINATES + Z]);
105
84
  }
106
85
  const [starts, faces] = facesAround(indices, vertexCount);
107
- const cosine = Math.cos(minSharpAngle * DEGREES_TO_RADIANS) - ANGLE_SLACK;
108
- const outPositions = [];
86
+ const cosine = Math.cos(radiansOf(minSharpAngle)) - ANGLE_SLACK;
87
+ const sources = [];
109
88
  const outNormals = [];
110
89
  const outIndices = new Uint32Array(triangleCount * CORNERS);
111
90
  const made = Array.from({ length: vertexCount }, () => []);
@@ -134,8 +113,8 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
134
113
  }
135
114
  const reuse = made[vertex].find((index) => outNormals[index * COORDINATES] === nx && outNormals[index * COORDINATES + Y] === ny && outNormals[index * COORDINATES + Z] === nz);
136
115
  if (reuse === undefined) {
137
- const index = outPositions.length / COORDINATES;
138
- outPositions.push(positions[vertex * COORDINATES], positions[vertex * COORDINATES + Y], positions[vertex * COORDINATES + Z]);
116
+ const index = sources.length;
117
+ sources.push(vertex);
139
118
  outNormals.push(nx, ny, nz);
140
119
  made[vertex].push(index);
141
120
  outIndices[corner] = index;
@@ -144,5 +123,15 @@ export const creasedMesh = (positions, indices, minSharpAngle) => {
144
123
  outIndices[corner] = reuse;
145
124
  }
146
125
  }
147
- return { positions: Float32Array.from(outPositions), normals: Float32Array.from(outNormals), indices: outIndices };
126
+ return { sources: Uint32Array.from(sources), normals: Float64Array.from(outNormals), indices: outIndices };
127
+ };
128
+ export const creasedMesh = (positions, indices, minSharpAngle) => {
129
+ const creased = creasedVertices(positions, indices, minSharpAngle);
130
+ const outPositions = new Float32Array(creased.sources.length * COORDINATES);
131
+ creased.sources.forEach((vertex, at) => {
132
+ outPositions[at * COORDINATES] = positions[vertex * COORDINATES];
133
+ outPositions[at * COORDINATES + Y] = positions[vertex * COORDINATES + Y];
134
+ outPositions[at * COORDINATES + Z] = positions[vertex * COORDINATES + Z];
135
+ });
136
+ return { positions: outPositions, normals: Float32Array.from(creased.normals), indices: creased.indices };
148
137
  };
@@ -0,0 +1,24 @@
1
+ import type { WindingComponents } from "../helper-types";
2
+ /**
3
+ * Finds which triangles of a mesh to turn over so that every edge two triangles share is run one way
4
+ * by one and the other way by the other, and which connected piece each triangle belongs to. The
5
+ * first triangle of each piece keeps its winding; an edge shared by more than two triangles is not
6
+ * followed.
7
+ * @param indices - Triangle corners, three per triangle
8
+ * @param start - The first index of the range to read
9
+ * @param end - The index after the range to read
10
+ * @returns For each triangle of the range, whether to turn it over and its piece, and how many pieces there are
11
+ */
12
+ export declare function windingComponents(indices: ArrayLike<number>, start?: number, end?: number): WindingComponents;
13
+ /**
14
+ * Finds which triangles of a mesh wind against the rest of their connected piece and should be
15
+ * turned over: within each piece, the winding most of its area already has is kept, so a few faces
16
+ * written inside out are mended while a piece wound inward on purpose, such as the inside of a
17
+ * hollow profile, stays as it is.
18
+ * @param positions - Flat `x, y, z` triples
19
+ * @param indices - Triangle corners, three per triangle
20
+ * @param start - The first index of the range to read
21
+ * @param end - The index after the range to read
22
+ * @returns For each triangle of the range, 1 where it should be turned over
23
+ */
24
+ export declare function windingRepairs(positions: ArrayLike<number>, indices: ArrayLike<number>, start?: number, end?: number): Uint8Array;
@@ -0,0 +1,104 @@
1
+ const CORNERS = 3;
2
+ function cornerOf(indices, start, triangle, corner) {
3
+ return indices[start + triangle * CORNERS + (corner % CORNERS)];
4
+ }
5
+ function edgeUsesOf(indices, start, triangles) {
6
+ let highest = 0;
7
+ for (let at = start; at < start + triangles * CORNERS; at++) {
8
+ highest = Math.max(highest, indices[at]);
9
+ }
10
+ const stride = highest + 1;
11
+ const uses = new Map();
12
+ for (let triangle = 0; triangle < triangles; triangle++) {
13
+ for (let corner = 0; corner < CORNERS; corner++) {
14
+ const a = cornerOf(indices, start, triangle, corner);
15
+ const b = cornerOf(indices, start, triangle, corner + 1);
16
+ if (a === b) {
17
+ continue;
18
+ }
19
+ const key = a < b ? a * stride + b : b * stride + a;
20
+ const known = uses.get(key);
21
+ if (known === undefined) {
22
+ uses.set(key, [triangle * CORNERS + corner]);
23
+ }
24
+ else {
25
+ known.push(triangle * CORNERS + corner);
26
+ }
27
+ }
28
+ }
29
+ return { uses, stride };
30
+ }
31
+ /**
32
+ * Finds which triangles of a mesh to turn over so that every edge two triangles share is run one way
33
+ * by one and the other way by the other, and which connected piece each triangle belongs to. The
34
+ * first triangle of each piece keeps its winding; an edge shared by more than two triangles is not
35
+ * followed.
36
+ * @param indices - Triangle corners, three per triangle
37
+ * @param start - The first index of the range to read
38
+ * @param end - The index after the range to read
39
+ * @returns For each triangle of the range, whether to turn it over and its piece, and how many pieces there are
40
+ */
41
+ export function windingComponents(indices, start = 0, end = indices.length) {
42
+ const triangles = Math.max(0, Math.floor((end - start) / CORNERS));
43
+ const flips = new Uint8Array(triangles);
44
+ const component = new Int32Array(triangles).fill(-1);
45
+ const { uses, stride } = edgeUsesOf(indices, start, triangles);
46
+ const queue = new Int32Array(triangles);
47
+ let count = 0;
48
+ for (let seed = 0; seed < triangles; seed++) {
49
+ if (component[seed] >= 0) {
50
+ continue;
51
+ }
52
+ component[seed] = count;
53
+ let head = 0;
54
+ let tail = 0;
55
+ queue[tail++] = seed;
56
+ while (head < tail) {
57
+ const triangle = queue[head++];
58
+ for (let corner = 0; corner < CORNERS; corner++) {
59
+ const a = cornerOf(indices, start, triangle, corner);
60
+ const b = cornerOf(indices, start, triangle, corner + 1);
61
+ const shared = a === b ? undefined : uses.get(a < b ? a * stride + b : b * stride + a);
62
+ const other = (shared === null || shared === void 0 ? void 0 : shared.length) === 2 ? shared.find((use) => Math.floor(use / CORNERS) !== triangle) : undefined;
63
+ if (other === undefined) {
64
+ continue;
65
+ }
66
+ const neighbour = Math.floor(other / CORNERS);
67
+ if (component[neighbour] >= 0) {
68
+ continue;
69
+ }
70
+ const sameDirection = cornerOf(indices, start, neighbour, other % CORNERS) === a;
71
+ flips[neighbour] = sameDirection ? 1 - flips[triangle] : flips[triangle];
72
+ component[neighbour] = count;
73
+ queue[tail++] = neighbour;
74
+ }
75
+ }
76
+ count++;
77
+ }
78
+ return { flips, component, count };
79
+ }
80
+ function twiceArea(positions, indices, start, triangle) {
81
+ const [a, b, c] = [0, 1, 2].map((corner) => cornerOf(indices, start, triangle, corner) * CORNERS);
82
+ const [ux, uy, uz] = [positions[b] - positions[a], positions[b + 1] - positions[a + 1], positions[b + 2] - positions[a + 2]];
83
+ const [vx, vy, vz] = [positions[c] - positions[a], positions[c + 1] - positions[a + 1], positions[c + 2] - positions[a + 2]];
84
+ return Math.hypot(uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx);
85
+ }
86
+ /**
87
+ * Finds which triangles of a mesh wind against the rest of their connected piece and should be
88
+ * turned over: within each piece, the winding most of its area already has is kept, so a few faces
89
+ * written inside out are mended while a piece wound inward on purpose, such as the inside of a
90
+ * hollow profile, stays as it is.
91
+ * @param positions - Flat `x, y, z` triples
92
+ * @param indices - Triangle corners, three per triangle
93
+ * @param start - The first index of the range to read
94
+ * @param end - The index after the range to read
95
+ * @returns For each triangle of the range, 1 where it should be turned over
96
+ */
97
+ export function windingRepairs(positions, indices, start = 0, end = indices.length) {
98
+ const { flips, component, count } = windingComponents(indices, start, end);
99
+ const balance = new Float64Array(count);
100
+ flips.forEach((flip, triangle) => {
101
+ balance[component[triangle]] += flip === 1 ? -twiceArea(positions, indices, start, triangle) : twiceArea(positions, indices, start, triangle);
102
+ });
103
+ return flips.map((flip, triangle) => (balance[component[triangle]] < 0 ? 1 - flip : flip));
104
+ }
@@ -1,3 +1,3 @@
1
- import type { MeshArrays } from "./helper-types";
1
+ import type { MeshArrays } from "../helper-types";
2
2
  export declare const icosphere: (detail: number) => MeshArrays;
3
3
  export declare const frustum: (sides: number, bottomRadius: number, topRadius: number, height: number) => MeshArrays;
@@ -1,7 +1,8 @@
1
+ import { unitOf } from "../geometry/frame-axes";
2
+ import { between3, polar2 } from "../geometry/vectors";
1
3
  import { ICOSAHEDRON_FACES, ICOSAHEDRON_POINTS } from "./mesh-primitives.constants";
2
- function onUnitSphere([x, y, z]) {
3
- const length = Math.hypot(x, y, z);
4
- return [x / length, y / length, z / length];
4
+ function onUnitSphere(point) {
5
+ return unitOf([point[0], point[1], point[2]]);
5
6
  }
6
7
  export const icosphere = (detail) => {
7
8
  const points = ICOSAHEDRON_POINTS.map(onUnitSphere);
@@ -13,7 +14,7 @@ export const icosphere = (detail) => {
13
14
  let index = middles.get(key);
14
15
  if (index === undefined) {
15
16
  const [p, q] = [points[a], points[b]];
16
- index = points.push(onUnitSphere([(p[0] + q[0]) / 2, (p[1] + q[1]) / 2, (p[2] + q[2]) / 2])) - 1;
17
+ index = points.push(onUnitSphere(between3(p, q, 1 / 2))) - 1;
17
18
  middles.set(key, index);
18
19
  }
19
20
  return index;
@@ -30,7 +31,7 @@ export const frustum = (sides, bottomRadius, topRadius, height) => {
30
31
  for (const [radius, z] of [[bottomRadius, 0], [topRadius, height]]) {
31
32
  for (let side = 0; side < sides; side++) {
32
33
  const angle = side / sides * 2 * Math.PI;
33
- positions.push(radius * Math.cos(angle), radius * Math.sin(angle), z);
34
+ positions.push(...polar2(radius, angle), z);
34
35
  }
35
36
  }
36
37
  const bottom = (side) => 2 + side % sides;
@@ -0,0 +1,7 @@
1
+ export declare const LEAF_TRIANGLES = 8;
2
+ export declare const RAY_DIRECTIONS: readonly (readonly [number, number, number])[];
3
+ export declare const PARALLEL = 1e-12;
4
+ export declare const POINT_SHARE = 1e-12;
5
+ export declare const FLAT_SHARE = 1e-28;
6
+ export declare const WELD_SHARE = 1e-9;
7
+ export declare const PRUNE_SLACK: number;
@@ -0,0 +1,11 @@
1
+ export const LEAF_TRIANGLES = 8;
2
+ export const RAY_DIRECTIONS = [
3
+ [0.5773, 0.5779, 0.5767],
4
+ [-0.6123, 0.7071, 0.3536],
5
+ [0.2673, -0.5345, 0.8018],
6
+ ];
7
+ export const PARALLEL = 1e-12;
8
+ export const POINT_SHARE = 1e-12;
9
+ export const FLAT_SHARE = 1e-28;
10
+ export const WELD_SHARE = 1e-9;
11
+ export const PRUNE_SLACK = 8 * Number.EPSILON;
@@ -0,0 +1,11 @@
1
+ import type * as Inputs from "../../../inputs";
2
+ import type { TreeBox, TriangleTree } from "../helper-types";
3
+ type Vec = Inputs.Base.Point3;
4
+ export declare function triangleTree(positions: ArrayLike<number>, indices: ArrayLike<number>): TriangleTree;
5
+ export declare function treesWithin(first: TriangleTree, second: TriangleTree, limit: number): boolean;
6
+ export declare function pointInTree(tree: TriangleTree, point: Vec): boolean;
7
+ export declare function pointOnTree(tree: TriangleTree): Vec | undefined;
8
+ export declare function treesNested(first: TriangleTree, second: TriangleTree): boolean;
9
+ export declare function pointsOnTree(tree: TriangleTree, most: number): Vec[];
10
+ export declare function treeBox(tree: TriangleTree): TreeBox | undefined;
11
+ export {};