@bitbybit-dev/base 1.5.0 → 1.6.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 (314) 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 +50 -0
  203. package/lib/api/services/helpers/{inflate.constants.d.ts → files/inflate.constants.d.ts} +2 -0
  204. package/lib/api/services/helpers/{inflate.constants.js → files/inflate.constants.js} +2 -0
  205. package/lib/api/services/helpers/{inflate.d.ts → files/inflate.d.ts} +2 -2
  206. package/lib/api/services/helpers/{inflate.js → files/inflate.js} +16 -7
  207. package/lib/api/services/helpers/{zip.constants.d.ts → files/zip.constants.d.ts} +8 -0
  208. package/lib/api/services/helpers/{zip.constants.js → files/zip.constants.js} +8 -0
  209. package/lib/api/services/helpers/files/zip.d.ts +8 -0
  210. package/lib/api/services/helpers/files/zip.js +226 -0
  211. package/lib/api/services/helpers/geometry/arcs.d.ts +9 -0
  212. package/lib/api/services/helpers/{arcs.js → geometry/arcs.js} +7 -0
  213. package/lib/api/services/helpers/{frame-axes.d.ts → geometry/frame-axes.d.ts} +8 -5
  214. package/lib/api/services/helpers/{frame-axes.js → geometry/frame-axes.js} +21 -9
  215. package/lib/api/services/helpers/geometry/lengths.constants.d.ts +4 -0
  216. package/lib/api/services/helpers/geometry/lengths.constants.js +3 -0
  217. package/lib/api/services/helpers/geometry/lengths.d.ts +7 -0
  218. package/lib/api/services/helpers/geometry/lengths.js +20 -0
  219. package/lib/api/services/helpers/geometry/matrices.constants.d.ts +8 -0
  220. package/lib/api/services/helpers/geometry/matrices.constants.js +7 -0
  221. package/lib/api/services/helpers/geometry/matrices.d.ts +17 -0
  222. package/lib/api/services/helpers/{matrices.js → geometry/matrices.js} +28 -17
  223. package/lib/api/services/helpers/{paths.d.ts → geometry/paths.d.ts} +2 -1
  224. package/lib/api/services/helpers/{paths.js → geometry/paths.js} +36 -30
  225. package/lib/api/services/helpers/{polygons.d.ts → geometry/polygons.d.ts} +1 -1
  226. package/lib/api/services/helpers/geometry/polygons.js +111 -0
  227. package/lib/api/services/helpers/geometry/scalars.d.ts +9 -0
  228. package/lib/api/services/helpers/geometry/scalars.js +34 -0
  229. package/lib/api/services/helpers/{triangulation.js → geometry/triangulation.js} +11 -6
  230. package/lib/api/services/helpers/geometry/vector-grid.d.ts +12 -0
  231. package/lib/api/services/helpers/geometry/vector-grid.js +149 -0
  232. package/lib/api/services/helpers/{vectors.d.ts → geometry/vectors.d.ts} +8 -1
  233. package/lib/api/services/helpers/geometry/vectors.js +43 -0
  234. package/lib/api/services/helpers/helper-types.d.ts +77 -0
  235. package/lib/api/services/helpers/mesh/mesh-normals.d.ts +21 -0
  236. package/lib/api/services/helpers/{mesh-normals.js → mesh/mesh-normals.js} +54 -65
  237. package/lib/api/services/helpers/mesh/mesh-orientation.d.ts +24 -0
  238. package/lib/api/services/helpers/mesh/mesh-orientation.js +104 -0
  239. package/lib/api/services/helpers/{mesh-primitives.d.ts → mesh/mesh-primitives.d.ts} +1 -1
  240. package/lib/api/services/helpers/{mesh-primitives.js → mesh/mesh-primitives.js} +6 -5
  241. package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +7 -0
  242. package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +11 -0
  243. package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +11 -0
  244. package/lib/api/services/helpers/mesh/mesh-proximity.js +382 -0
  245. package/lib/api/services/index.d.ts +3 -0
  246. package/lib/api/services/index.js +3 -0
  247. package/lib/api/services/io.d.ts +1 -1
  248. package/lib/api/services/io.js +1 -1
  249. package/lib/api/services/line.js +2 -3
  250. package/lib/api/services/math.d.ts +47 -0
  251. package/lib/api/services/math.js +77 -10
  252. package/lib/api/services/mesh.d.ts +174 -2
  253. package/lib/api/services/mesh.js +305 -7
  254. package/lib/api/services/point.js +4 -10
  255. package/lib/api/services/polyline-types.d.ts +6 -0
  256. package/lib/api/services/polyline-types.js +1 -0
  257. package/lib/api/services/polyline.d.ts +163 -1
  258. package/lib/api/services/polyline.js +270 -13
  259. package/lib/api/services/recipes.d.ts +80 -0
  260. package/lib/api/services/recipes.js +107 -0
  261. package/lib/api/services/transforms.d.ts +74 -2
  262. package/lib/api/services/transforms.js +100 -3
  263. package/lib/api/services/vector.d.ts +4 -3
  264. package/lib/api/services/vector.js +14 -14
  265. package/lib/api/splines/ansi-splines.constants.d.ts +9 -0
  266. package/lib/api/splines/ansi-splines.constants.js +9 -0
  267. package/lib/api/splines/ansi-splines.d.ts +3 -0
  268. package/lib/api/splines/ansi-splines.js +28 -0
  269. package/lib/api/splines/din-splines.constants.d.ts +12 -0
  270. package/lib/api/splines/din-splines.constants.js +12 -0
  271. package/lib/api/splines/din-splines.d.ts +3 -0
  272. package/lib/api/splines/din-splines.js +38 -0
  273. package/lib/api/splines/spline-types.d.ts +32 -0
  274. package/lib/api/splines/spline-types.js +1 -0
  275. package/lib/api/splines/splines.constants.d.ts +1 -0
  276. package/lib/api/splines/splines.constants.js +1 -0
  277. package/lib/api/springs/spring-types.d.ts +26 -0
  278. package/lib/api/springs/spring-types.js +1 -0
  279. package/lib/api/springs/springs.constants.d.ts +9 -0
  280. package/lib/api/springs/springs.constants.js +9 -0
  281. package/lib/api/springs/springs.d.ts +2 -0
  282. package/lib/api/springs/springs.js +50 -0
  283. package/lib/api/threads/ansi-threads.constants.d.ts +6 -0
  284. package/lib/api/threads/ansi-threads.constants.js +27 -0
  285. package/lib/api/threads/ansi-threads.d.ts +4 -0
  286. package/lib/api/threads/ansi-threads.js +50 -0
  287. package/lib/api/threads/iso-threads.constants.d.ts +5 -0
  288. package/lib/api/threads/iso-threads.constants.js +20 -0
  289. package/lib/api/threads/iso-threads.d.ts +4 -0
  290. package/lib/api/threads/iso-threads.js +32 -0
  291. package/lib/api/threads/thread-profile.constants.d.ts +3 -0
  292. package/lib/api/threads/thread-profile.constants.js +3 -0
  293. package/lib/api/threads/thread-types.d.ts +66 -0
  294. package/lib/api/threads/thread-types.js +1 -0
  295. package/package.json +1 -1
  296. package/lib/api/recipes/index.d.ts +0 -4
  297. package/lib/api/recipes/index.js +0 -3
  298. package/lib/api/services/helpers/arcs.d.ts +0 -6
  299. package/lib/api/services/helpers/matrices.constants.d.ts +0 -2
  300. package/lib/api/services/helpers/matrices.constants.js +0 -2
  301. package/lib/api/services/helpers/matrices.d.ts +0 -25
  302. package/lib/api/services/helpers/mesh-normals.d.ts +0 -11
  303. package/lib/api/services/helpers/polygons.js +0 -59
  304. package/lib/api/services/helpers/vectors.js +0 -17
  305. package/lib/api/services/helpers/zip.d.ts +0 -4
  306. package/lib/api/services/helpers/zip.js +0 -89
  307. /package/lib/api/services/helpers/{nurbs.js → curves/nurbs.js} +0 -0
  308. /package/lib/api/services/helpers/{crc32.d.ts → files/crc32.d.ts} +0 -0
  309. /package/lib/api/services/helpers/{crc32.js → files/crc32.js} +0 -0
  310. /package/lib/api/services/helpers/{triangulation.d.ts → geometry/triangulation.d.ts} +0 -0
  311. /package/lib/api/services/helpers/{mesh-measures.d.ts → mesh/mesh-measures.d.ts} +0 -0
  312. /package/lib/api/services/helpers/{mesh-measures.js → mesh/mesh-measures.js} +0 -0
  313. /package/lib/api/services/helpers/{mesh-primitives.constants.d.ts → mesh/mesh-primitives.constants.d.ts} +0 -0
  314. /package/lib/api/services/helpers/{mesh-primitives.constants.js → mesh/mesh-primitives.constants.js} +0 -0
@@ -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 {};