@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,382 @@
1
+ import { cross3, dot3, subtract3 } from "../geometry/vectors";
2
+ import { FLAT_SHARE, LEAF_TRIANGLES, PARALLEL, POINT_SHARE, PRUNE_SLACK, RAY_DIRECTIONS, WELD_SHARE } from "./mesh-proximity.constants";
3
+ import { windingComponents } from "./mesh-orientation";
4
+ import { uniqueVectors } from "../geometry/vector-grid";
5
+ const CORNERS = 3;
6
+ const TRIANGLE = 9;
7
+ const BOX = 6;
8
+ const AXES = 3;
9
+ function boxOf(corners, order, start, end, into, at) {
10
+ let minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
11
+ for (let index = start; index < end; index++) {
12
+ const base = order[index] * TRIANGLE;
13
+ for (let corner = 0; corner < TRIANGLE; corner += CORNERS) {
14
+ const x = corners[base + corner];
15
+ const y = corners[base + corner + 1];
16
+ const z = corners[base + corner + 2];
17
+ minX = Math.min(minX, x);
18
+ minY = Math.min(minY, y);
19
+ minZ = Math.min(minZ, z);
20
+ maxX = Math.max(maxX, x);
21
+ maxY = Math.max(maxY, y);
22
+ maxZ = Math.max(maxZ, z);
23
+ }
24
+ }
25
+ into[at] = minX;
26
+ into[at + 1] = minY;
27
+ into[at + 2] = minZ;
28
+ into[at + AXES] = maxX;
29
+ into[at + AXES + 1] = maxY;
30
+ into[at + AXES + 2] = maxZ;
31
+ }
32
+ export function triangleTree(positions, indices) {
33
+ const count = Math.floor(indices.length / CORNERS);
34
+ const source = new Float64Array(count * TRIANGLE);
35
+ const centres = new Float64Array(count * CORNERS);
36
+ for (let triangle = 0; triangle < count; triangle++) {
37
+ for (let corner = 0; corner < CORNERS; corner++) {
38
+ const vertex = indices[triangle * CORNERS + corner] * CORNERS;
39
+ for (let axis = 0; axis < AXES; axis++) {
40
+ const value = positions[vertex + axis];
41
+ source[triangle * TRIANGLE + corner * CORNERS + axis] = value;
42
+ centres[triangle * CORNERS + axis] = centres[triangle * CORNERS + axis] + value / CORNERS;
43
+ }
44
+ }
45
+ }
46
+ const order = new Uint32Array(count).map((_, index) => index);
47
+ const boxes = [];
48
+ const starts = [];
49
+ const counts = [];
50
+ const lefts = [];
51
+ const rights = [];
52
+ const box = new Float64Array(BOX);
53
+ const build = (start, end) => {
54
+ const node = starts.length;
55
+ boxOf(source, order, start, end, box, 0);
56
+ boxes.push(...box);
57
+ starts.push(start);
58
+ counts.push(end - start);
59
+ lefts.push(-1);
60
+ rights.push(-1);
61
+ if (end - start <= LEAF_TRIANGLES) {
62
+ return node;
63
+ }
64
+ const extents = [box[AXES] - box[0], box[AXES + 1] - box[1], box[AXES + 2] - box[2]];
65
+ const axis = extents.indexOf(Math.max(...extents));
66
+ const slice = Array.from(order.subarray(start, end)).sort((a, b) => centres[a * CORNERS + axis] - centres[b * CORNERS + axis]);
67
+ order.set(slice, start);
68
+ const middle = (start + end) >> 1;
69
+ lefts[node] = build(start, middle);
70
+ rights[node] = build(middle, end);
71
+ return node;
72
+ };
73
+ if (count > 0) {
74
+ build(0, count);
75
+ }
76
+ const corners = new Float64Array(count * TRIANGLE);
77
+ order.forEach((triangle, index) => corners.set(source.subarray(triangle * TRIANGLE, triangle * TRIANGLE + TRIANGLE), index * TRIANGLE));
78
+ return { corners, boxes: Float64Array.from(boxes), starts: Uint32Array.from(starts), counts: Uint32Array.from(counts), lefts: Int32Array.from(lefts), rights: Int32Array.from(rights) };
79
+ }
80
+ function boxGap(a, i, b, j) {
81
+ let sum = 0;
82
+ for (let axis = 0; axis < AXES; axis++) {
83
+ const gap = Math.max(0, a[i * BOX + axis] - b[j * BOX + AXES + axis], b[j * BOX + axis] - a[i * BOX + AXES + axis]);
84
+ sum += gap * gap;
85
+ }
86
+ return Math.sqrt(sum);
87
+ }
88
+ function corner(source, triangle, index) {
89
+ const at = triangle * TRIANGLE + index * CORNERS;
90
+ return [source[at], source[at + 1], source[at + 2]];
91
+ }
92
+ const along = (a, d, t) => [a[0] + d[0] * t, a[1] + d[1] * t, a[2] + d[2] * t];
93
+ const clamp = (value) => Math.min(1, Math.max(0, value));
94
+ function segmentsSquared(p1, q1, p2, q2) {
95
+ const d1 = subtract3(q1, p1);
96
+ const d2 = subtract3(q2, p2);
97
+ const r = subtract3(p1, p2);
98
+ const a = dot3(d1, d1);
99
+ const e = dot3(d2, d2);
100
+ const f = dot3(d2, r);
101
+ const point = POINT_SHARE * Math.max(a, e);
102
+ let s = 0;
103
+ let t = 0;
104
+ if (a <= point && e <= point) {
105
+ return dot3(r, r);
106
+ }
107
+ if (a <= point) {
108
+ t = clamp(f / e);
109
+ }
110
+ else {
111
+ const c = dot3(d1, r);
112
+ if (e <= point) {
113
+ s = clamp(-c / a);
114
+ }
115
+ else {
116
+ const b = dot3(d1, d2);
117
+ const denominator = a * e - b * b;
118
+ s = denominator > PARALLEL * a * e ? clamp((b * f - c * e) / denominator) : 0;
119
+ t = (b * s + f) / e;
120
+ if (t < 0) {
121
+ t = 0;
122
+ s = clamp(-c / a);
123
+ }
124
+ else if (t > 1) {
125
+ t = 1;
126
+ s = clamp((b - c) / a);
127
+ }
128
+ }
129
+ }
130
+ const gap = subtract3(along(p1, d1, s), along(p2, d2, t));
131
+ return dot3(gap, gap);
132
+ }
133
+ function pointTriangleSquared(p, a, b, c) {
134
+ const ab = subtract3(b, a);
135
+ const ac = subtract3(c, a);
136
+ const ap = subtract3(p, a);
137
+ const d1 = dot3(ab, ap);
138
+ const d2 = dot3(ac, ap);
139
+ if (d1 <= 0 && d2 <= 0) {
140
+ return dot3(ap, ap);
141
+ }
142
+ const bp = subtract3(p, b);
143
+ const d3 = dot3(ab, bp);
144
+ const d4 = dot3(ac, bp);
145
+ if (d3 >= 0 && d4 <= d3) {
146
+ return dot3(bp, bp);
147
+ }
148
+ const vc = d1 * d4 - d3 * d2;
149
+ if (vc <= 0 && d1 >= 0 && d3 <= 0) {
150
+ const q = subtract3(p, along(a, ab, d1 / (d1 - d3)));
151
+ return dot3(q, q);
152
+ }
153
+ const cp = subtract3(p, c);
154
+ const d5 = dot3(ab, cp);
155
+ const d6 = dot3(ac, cp);
156
+ if (d6 >= 0 && d5 <= d6) {
157
+ return dot3(cp, cp);
158
+ }
159
+ const vb = d5 * d2 - d1 * d6;
160
+ if (vb <= 0 && d2 >= 0 && d6 <= 0) {
161
+ const q = subtract3(p, along(a, ac, d2 / (d2 - d6)));
162
+ return dot3(q, q);
163
+ }
164
+ const va = d3 * d6 - d5 * d4;
165
+ if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) {
166
+ const q = subtract3(p, along(b, subtract3(c, b), (d4 - d3) / (d4 - d3 + (d5 - d6))));
167
+ return dot3(q, q);
168
+ }
169
+ const total = va + vb + vc;
170
+ const v = vb / total;
171
+ const w = vc / total;
172
+ const q = subtract3(p, [a[0] + ab[0] * v + ac[0] * w, a[1] + ab[1] * v + ac[1] * w, a[2] + ab[2] * v + ac[2] * w]);
173
+ return dot3(q, q);
174
+ }
175
+ function rayTriangleHit(from, direction, a, b, c) {
176
+ const e1 = subtract3(b, a);
177
+ const e2 = subtract3(c, a);
178
+ const p = cross3(direction, e2);
179
+ const determinant = dot3(e1, p);
180
+ const facing = cross3(e1, e2);
181
+ const facingSquared = dot3(facing, facing);
182
+ if (facingSquared <= FLAT_SHARE * dot3(e1, e1) * dot3(e2, e2) || determinant * determinant <= PARALLEL * dot3(direction, direction) * facingSquared) {
183
+ return undefined;
184
+ }
185
+ const inverse = 1 / determinant;
186
+ const s = subtract3(from, a);
187
+ const q = cross3(s, e1);
188
+ return [dot3(s, p) * inverse, dot3(direction, q) * inverse, dot3(e2, q) * inverse];
189
+ }
190
+ function segmentCrosses(from, to, a, b, c) {
191
+ const hit = rayTriangleHit(from, subtract3(to, from), a, b, c);
192
+ if (hit === undefined) {
193
+ return false;
194
+ }
195
+ const [u, v, t] = hit;
196
+ return u >= 0 && u <= 1 && v >= 0 && u + v <= 1 && t >= 0 && t <= 1;
197
+ }
198
+ function trianglesWithin(a0, a1, a2, b0, b1, b2, limit) {
199
+ if (segmentCrosses(a0, a1, b0, b1, b2) || segmentCrosses(a1, a2, b0, b1, b2) || segmentCrosses(a2, a0, b0, b1, b2)
200
+ || segmentCrosses(b0, b1, a0, a1, a2) || segmentCrosses(b1, b2, a0, a1, a2) || segmentCrosses(b2, b0, a0, a1, a2)) {
201
+ return true;
202
+ }
203
+ const squared = limit * limit;
204
+ if (pointTriangleSquared(a0, b0, b1, b2) <= squared || pointTriangleSquared(a1, b0, b1, b2) <= squared || pointTriangleSquared(a2, b0, b1, b2) <= squared
205
+ || pointTriangleSquared(b0, a0, a1, a2) <= squared || pointTriangleSquared(b1, a0, a1, a2) <= squared || pointTriangleSquared(b2, a0, a1, a2) <= squared) {
206
+ return true;
207
+ }
208
+ const edgesA = [[a0, a1], [a1, a2], [a2, a0]];
209
+ const edgesB = [[b0, b1], [b1, b2], [b2, b0]];
210
+ return edgesA.some(([p1, q1]) => edgesB.some(([p2, q2]) => segmentsSquared(p1, q1, p2, q2) <= squared));
211
+ }
212
+ function triangleBox(source, triangle, into) {
213
+ for (let axis = 0; axis < AXES; axis++) {
214
+ const a = source[triangle * TRIANGLE + axis];
215
+ const b = source[triangle * TRIANGLE + CORNERS + axis];
216
+ const c = source[triangle * TRIANGLE + 2 * CORNERS + axis];
217
+ into[axis] = Math.min(a, b, c);
218
+ into[AXES + axis] = Math.max(a, b, c);
219
+ }
220
+ }
221
+ function planeGap(normal, offset, boxes, node) {
222
+ let centre = 0;
223
+ let reach = 0;
224
+ for (let axis = 0; axis < AXES; axis++) {
225
+ const low = boxes[node * BOX + axis];
226
+ const high = boxes[node * BOX + AXES + axis];
227
+ centre += normal[axis] * (low + high) / 2;
228
+ reach += Math.abs(normal[axis]) * (high - low) / 2;
229
+ }
230
+ return Math.abs(centre - offset) - reach;
231
+ }
232
+ function triangleWithinTree(source, triangle, tree, node, limit, prune) {
233
+ const a0 = corner(source, triangle, 0);
234
+ const a1 = corner(source, triangle, 1);
235
+ const a2 = corner(source, triangle, 2);
236
+ const box = new Float64Array(BOX);
237
+ triangleBox(source, triangle, box);
238
+ const first = subtract3(a1, a0);
239
+ const second = subtract3(a2, a0);
240
+ const facing = cross3(first, second);
241
+ const length = Math.hypot(facing[0], facing[1], facing[2]);
242
+ const normal = length * length > PARALLEL * dot3(first, first) * dot3(second, second) ? [facing[0] / length, facing[1] / length, facing[2] / length] : undefined;
243
+ const offset = normal === undefined ? 0 : dot3(normal, a0);
244
+ const other = new Float64Array(BOX);
245
+ const stack = [node];
246
+ while (stack.length > 0) {
247
+ const at = stack.pop();
248
+ if (boxGap(box, 0, tree.boxes, at) > prune || (normal !== undefined && planeGap(normal, offset, tree.boxes, at) > prune)) {
249
+ continue;
250
+ }
251
+ if (tree.lefts[at] >= 0) {
252
+ stack.push(tree.lefts[at], tree.rights[at]);
253
+ continue;
254
+ }
255
+ for (let b = tree.starts[at]; b < tree.starts[at] + tree.counts[at]; b++) {
256
+ triangleBox(tree.corners, b, other);
257
+ if (boxGap(box, 0, other, 0) <= prune && trianglesWithin(a0, a1, a2, corner(tree.corners, b, 0), corner(tree.corners, b, 1), corner(tree.corners, b, 2), limit)) {
258
+ return true;
259
+ }
260
+ }
261
+ }
262
+ return false;
263
+ }
264
+ function leafWithin(leafTree, leaf, tree, node, limit, prune) {
265
+ for (let triangle = leafTree.starts[leaf]; triangle < leafTree.starts[leaf] + leafTree.counts[leaf]; triangle++) {
266
+ if (triangleWithinTree(leafTree.corners, triangle, tree, node, limit, prune)) {
267
+ return true;
268
+ }
269
+ }
270
+ return false;
271
+ }
272
+ const reachOfTree = (tree) => tree.boxes.subarray(0, BOX).reduce((largest, value) => Math.max(largest, Math.abs(value)), 0);
273
+ export function treesWithin(first, second, limit) {
274
+ if (first.starts.length === 0 || second.starts.length === 0) {
275
+ return false;
276
+ }
277
+ const prune = limit + PRUNE_SLACK * Math.max(reachOfTree(first), reachOfTree(second));
278
+ const stack = [0, 0];
279
+ while (stack.length > 0) {
280
+ const j = stack.pop();
281
+ const i = stack.pop();
282
+ if (boxGap(first.boxes, i, second.boxes, j) > prune) {
283
+ continue;
284
+ }
285
+ if (first.lefts[i] < 0) {
286
+ if (leafWithin(first, i, second, j, limit, prune)) {
287
+ return true;
288
+ }
289
+ }
290
+ else if (second.lefts[j] < 0) {
291
+ if (leafWithin(second, j, first, i, limit, prune)) {
292
+ return true;
293
+ }
294
+ }
295
+ else if (second.counts[j] > first.counts[i]) {
296
+ stack.push(i, second.lefts[j], i, second.rights[j]);
297
+ }
298
+ else {
299
+ stack.push(first.lefts[i], j, first.rights[i], j);
300
+ }
301
+ }
302
+ return false;
303
+ }
304
+ function rayHitsBox(origin, direction, boxes, node) {
305
+ let near = 0;
306
+ let far = Infinity;
307
+ for (let axis = 0; axis < AXES; axis++) {
308
+ const low = boxes[node * BOX + axis];
309
+ const high = boxes[node * BOX + AXES + axis];
310
+ const from = origin[axis];
311
+ const step = direction[axis];
312
+ const t1 = (low - from) / step;
313
+ const t2 = (high - from) / step;
314
+ near = Math.max(near, Math.min(t1, t2));
315
+ far = Math.min(far, Math.max(t1, t2));
316
+ if (near > far) {
317
+ return false;
318
+ }
319
+ }
320
+ return true;
321
+ }
322
+ function crossings(tree, origin, direction) {
323
+ let hits = 0;
324
+ const stack = [0];
325
+ while (stack.length > 0) {
326
+ const node = stack.pop();
327
+ if (!rayHitsBox(origin, direction, tree.boxes, node)) {
328
+ continue;
329
+ }
330
+ if (tree.lefts[node] >= 0) {
331
+ stack.push(tree.lefts[node], tree.rights[node]);
332
+ continue;
333
+ }
334
+ for (let triangle = tree.starts[node]; triangle < tree.starts[node] + tree.counts[node]; triangle++) {
335
+ const hit = rayTriangleHit(origin, direction, corner(tree.corners, triangle, 0), corner(tree.corners, triangle, 1), corner(tree.corners, triangle, 2));
336
+ if (hit !== undefined && hit[0] >= 0 && hit[1] >= 0 && hit[0] + hit[1] <= 1 && hit[2] > 0) {
337
+ hits++;
338
+ }
339
+ }
340
+ }
341
+ return hits;
342
+ }
343
+ export function pointInTree(tree, point) {
344
+ if (tree.starts.length === 0) {
345
+ return false;
346
+ }
347
+ const inside = RAY_DIRECTIONS.filter(direction => crossings(tree, point, [direction[0], direction[1], direction[2]]) % 2 === 1).length;
348
+ return inside * 2 > RAY_DIRECTIONS.length;
349
+ }
350
+ export function pointOnTree(tree) {
351
+ return tree.corners.length === 0 ? undefined : corner(tree.corners, 0, 0);
352
+ }
353
+ const piecePoints = new WeakMap();
354
+ function pointPerPiece(tree) {
355
+ const known = piecePoints.get(tree);
356
+ if (known !== undefined) {
357
+ return known;
358
+ }
359
+ const corners = Array.from({ length: tree.corners.length / CORNERS }, (_, at) => [tree.corners[at * CORNERS], tree.corners[at * CORNERS + 1], tree.corners[at * CORNERS + 2]]);
360
+ const reach = tree.boxes.subarray(0, BOX).reduce((largest, value) => Math.max(largest, Math.abs(value)), 1);
361
+ const { component, count } = windingComponents(uniqueVectors(corners, WELD_SHARE * reach).indexes);
362
+ const firsts = new Int32Array(count).fill(-1);
363
+ component.forEach((piece, triangle) => {
364
+ if (firsts[piece] < 0) {
365
+ firsts[piece] = triangle;
366
+ }
367
+ });
368
+ const points = Array.from(firsts, triangle => corner(tree.corners, triangle, 0));
369
+ piecePoints.set(tree, points);
370
+ return points;
371
+ }
372
+ export function treesNested(first, second) {
373
+ return pointPerPiece(second).some(point => pointInTree(first, point)) || pointPerPiece(first).some(point => pointInTree(second, point));
374
+ }
375
+ export function pointsOnTree(tree, most) {
376
+ const triangles = tree.corners.length / TRIANGLE;
377
+ const count = Math.min(Math.max(0, Math.floor(most)), triangles);
378
+ return Array.from({ length: count }, (_, index) => corner(tree.corners, Math.floor(index * triangles / count), index % CORNERS));
379
+ }
380
+ export function treeBox(tree) {
381
+ return tree.starts.length === 0 ? undefined : { min: [tree.boxes[0], tree.boxes[1], tree.boxes[2]], max: [tree.boxes[AXES], tree.boxes[AXES + 1], tree.boxes[AXES + 2]] };
382
+ }
@@ -13,3 +13,6 @@ export * from "./polyline";
13
13
  export * from "./mesh";
14
14
  export * from "./io";
15
15
  export * from "./frame";
16
+ export * from "./engineering";
17
+ export * from "./recipes";
18
+ export * from "./base-bitbybit";
@@ -13,3 +13,6 @@ export * from "./polyline";
13
13
  export * from "./mesh";
14
14
  export * from "./io";
15
15
  export * from "./frame";
16
+ export * from "./engineering";
17
+ export * from "./recipes";
18
+ export * from "./base-bitbybit";
@@ -1,4 +1,4 @@
1
- import { Dxf } from "./helpers/dxf/dxf";
1
+ import { Dxf } from "./helpers/files/dxf/dxf";
2
2
  /**
3
3
  * Reading and writing files: exporting geometry to the supported formats, importing it back, and
4
4
  * the download and upload helpers that move files between the browser and the user's machine.
@@ -1,4 +1,4 @@
1
- import { Dxf } from "./helpers/dxf/dxf";
1
+ import { Dxf } from "./helpers/files/dxf/dxf";
2
2
  /**
3
3
  * Reading and writing files: exporting geometry to the supported formats, importing it back, and
4
4
  * the download and upload helpers that move files between the browser and the user's machine.
@@ -1,5 +1,6 @@
1
1
  import * as Inputs from "../inputs";
2
2
  import { resolveDto } from "../kernel-calls";
3
+ import { add3, scale3, subtract3 } from "./helpers/geometry/vectors";
3
4
  /**
4
5
  * Straight lines between two points, held as plain objects of the form `{ start, end }`, and the
5
6
  * segment form `[start, end]` of the same thing. The methods here build lines, measure and
@@ -181,9 +182,7 @@ export class Line {
181
182
  const point1 = resolved.line.start;
182
183
  const point2 = resolved.line.end;
183
184
  const parameter = resolved.param;
184
- const direction = [point2[0] - point1[0], point2[1] - point1[1], point2[2] - point1[2]];
185
- const point = [point1[0] + parameter * direction[0], point1[1] + parameter * direction[1], point1[2] + parameter * direction[2]];
186
- return point;
185
+ return add3(point1, scale3(subtract3(point2, point1), parameter));
187
186
  }
188
187
  /**
189
188
  * Joins each point to the next with a line, so a list of points becomes a chain of lines.
@@ -458,6 +458,53 @@ export declare class MathBitByBit {
458
458
  * @drawable false
459
459
  */
460
460
  radToDeg(inputs: Inputs.Math.NumberDto): number;
461
+ /**
462
+ * Converts a length from one unit to another.
463
+ *
464
+ * The factors are exact: an inch is 25.4 millimetres. A length in its own unit comes back
465
+ * unchanged. Example: 1 inch -> 25.4 millimetres, 250 millimetres -> 0.25 metres.
466
+ * @param inputs - The length and the units it is converted from and to
467
+ * @returns The length in `to`
468
+ * @group basics
469
+ * @shortname convert length
470
+ * @drawable false
471
+ * @example
472
+ * ```typescript
473
+ * const millimetres = bitbybit.math.convertLength({ value: 0.25, from: Bit.Inputs.Base.unitOfLengthEnum.inch, to: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
474
+ * ```
475
+ */
476
+ convertLength(inputs: Inputs.Math.ConvertLengthDto): number;
477
+ /**
478
+ * Gives how many millimetres one of a unit of length holds.
479
+ *
480
+ * Example: inch -> 25.4, centimetre -> 10, metre -> 1000.
481
+ * @param inputs - The unit
482
+ * @returns Millimetres in one of the unit
483
+ * @group basics
484
+ * @shortname millimetres per unit
485
+ * @drawable false
486
+ * @example
487
+ * ```typescript
488
+ * const perInch = bitbybit.math.millimetresPerUnit({ unit: Bit.Inputs.Base.unitOfLengthEnum.inch });
489
+ * ```
490
+ */
491
+ millimetresPerUnit(inputs: Inputs.Math.UnitOfLengthDto): number;
492
+ /**
493
+ * Writes a number as a whole number and a reduced fraction, rounded to the nearest
494
+ * `1/denominator`, as inch sizes are written.
495
+ *
496
+ * Example: 1.25 with denominator 64 -> "1-1/4", 0.375 -> "3/8", 2 -> "2", -0.5 -> "-1/2".
497
+ * @param inputs - The number and the finest fraction to round to
498
+ * @returns The number as text
499
+ * @group basics
500
+ * @shortname to fraction text
501
+ * @drawable false
502
+ * @example
503
+ * ```typescript
504
+ * const size = bitbybit.math.toFractionText({ number: 0.4375, denominator: 64 });
505
+ * ```
506
+ */
507
+ toFractionText(inputs: Inputs.Math.FractionTextDto): string;
461
508
  /**
462
509
  * Maps a value from 0 to 1 onto the range `min` to `max` along an easing curve, so the result
463
510
  * speeds up or slows down instead of changing evenly.
@@ -1,5 +1,8 @@
1
1
  import * as Inputs from "../inputs";
2
2
  import { resolveDto } from "../kernel-calls";
3
+ import { degreesOf, fractionOf, fractionText, interpolated, radiansOf, roundedTo, smoothstep } from "./helpers/geometry/scalars";
4
+ import { InputError } from "../kernel-calls/errors";
5
+ import { checkedUnitOfLength, lengthConverted, millimetresPerUnitOf } from "./helpers/geometry/lengths";
3
6
  /**
4
7
  * Arithmetic, rounding, ranges, random numbers and the trigonometric functions on plain numbers.
5
8
  * The trigonometric functions take and give angles in radians; `degToRad` and `radToDeg` convert at
@@ -101,7 +104,7 @@ export class MathBitByBit {
101
104
  */
102
105
  roundToDecimals(inputs) {
103
106
  const resolved = resolveDto(Inputs.Math.RoundToDecimalsDto, inputs);
104
- return Math.round(resolved.number * Math.pow(10, resolved.decimalPlaces)) / Math.pow(10, resolved.decimalPlaces);
107
+ return roundedTo(resolved.number, resolved.decimalPlaces);
105
108
  }
106
109
  /**
107
110
  * Rounds a number to a given number of decimal places and drops the zeros at the end.
@@ -121,7 +124,7 @@ export class MathBitByBit {
121
124
  */
122
125
  roundAndRemoveTrailingZeros(inputs) {
123
126
  const resolved = resolveDto(Inputs.Math.RoundToDecimalsDto, inputs);
124
- const rounded = Math.round(resolved.number * Math.pow(10, resolved.decimalPlaces)) / Math.pow(10, resolved.decimalPlaces);
127
+ const rounded = roundedTo(resolved.number, resolved.decimalPlaces);
125
128
  return parseFloat(rounded.toFixed(resolved.decimalPlaces));
126
129
  }
127
130
  /**
@@ -197,10 +200,10 @@ export class MathBitByBit {
197
200
  result = Math.exp(resolved.number);
198
201
  break;
199
202
  case Inputs.Math.mathOneNrOperatorEnum.degToRad:
200
- result = resolved.number * Math.PI / 180;
203
+ result = radiansOf(resolved.number);
201
204
  break;
202
205
  case Inputs.Math.mathOneNrOperatorEnum.radToDeg:
203
- result = resolved.number * 180 / Math.PI;
206
+ result = degreesOf(resolved.number);
204
207
  break;
205
208
  default:
206
209
  break;
@@ -636,7 +639,7 @@ export class MathBitByBit {
636
639
  */
637
640
  degToRad(inputs) {
638
641
  const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
639
- return resolved.number * Math.PI / 180;
642
+ return radiansOf(resolved.number);
640
643
  }
641
644
  /**
642
645
  * Converts an angle from radians to degrees.
@@ -650,7 +653,72 @@ export class MathBitByBit {
650
653
  */
651
654
  radToDeg(inputs) {
652
655
  const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
653
- return resolved.number * 180 / Math.PI;
656
+ return degreesOf(resolved.number);
657
+ }
658
+ /**
659
+ * Converts a length from one unit to another.
660
+ *
661
+ * The factors are exact: an inch is 25.4 millimetres. A length in its own unit comes back
662
+ * unchanged. Example: 1 inch -> 25.4 millimetres, 250 millimetres -> 0.25 metres.
663
+ * @param inputs - The length and the units it is converted from and to
664
+ * @returns The length in `to`
665
+ * @group basics
666
+ * @shortname convert length
667
+ * @drawable false
668
+ * @example
669
+ * ```typescript
670
+ * const millimetres = bitbybit.math.convertLength({ value: 0.25, from: Bit.Inputs.Base.unitOfLengthEnum.inch, to: Bit.Inputs.Base.unitOfLengthEnum.millimetre });
671
+ * ```
672
+ */
673
+ convertLength(inputs) {
674
+ const resolved = resolveDto(Inputs.Math.ConvertLengthDto, inputs);
675
+ return lengthConverted(resolved.value, checkedUnitOfLength(resolved.from, "from"), checkedUnitOfLength(resolved.to, "to"));
676
+ }
677
+ /**
678
+ * Gives how many millimetres one of a unit of length holds.
679
+ *
680
+ * Example: inch -> 25.4, centimetre -> 10, metre -> 1000.
681
+ * @param inputs - The unit
682
+ * @returns Millimetres in one of the unit
683
+ * @group basics
684
+ * @shortname millimetres per unit
685
+ * @drawable false
686
+ * @example
687
+ * ```typescript
688
+ * const perInch = bitbybit.math.millimetresPerUnit({ unit: Bit.Inputs.Base.unitOfLengthEnum.inch });
689
+ * ```
690
+ */
691
+ millimetresPerUnit(inputs) {
692
+ const resolved = resolveDto(Inputs.Math.UnitOfLengthDto, inputs);
693
+ return millimetresPerUnitOf(checkedUnitOfLength(resolved.unit, "unit"));
694
+ }
695
+ /**
696
+ * Writes a number as a whole number and a reduced fraction, rounded to the nearest
697
+ * `1/denominator`, as inch sizes are written.
698
+ *
699
+ * Example: 1.25 with denominator 64 -> "1-1/4", 0.375 -> "3/8", 2 -> "2", -0.5 -> "-1/2".
700
+ * @param inputs - The number and the finest fraction to round to
701
+ * @returns The number as text
702
+ * @group basics
703
+ * @shortname to fraction text
704
+ * @drawable false
705
+ * @example
706
+ * ```typescript
707
+ * const size = bitbybit.math.toFractionText({ number: 0.4375, denominator: 64 });
708
+ * ```
709
+ */
710
+ toFractionText(inputs) {
711
+ const resolved = resolveDto(Inputs.Math.FractionTextDto, inputs);
712
+ if (!Number.isFinite(resolved.number)) {
713
+ throw new InputError(`\`number\` is ${String(resolved.number)}, not a finite number.`, "number");
714
+ }
715
+ if (!Number.isInteger(resolved.denominator) || resolved.denominator < 1) {
716
+ throw new InputError(`\`denominator\` is ${String(resolved.denominator)}, and has to be a whole number of at least 1.`, "denominator");
717
+ }
718
+ if (!(Math.abs(resolved.number) * resolved.denominator <= Number.MAX_SAFE_INTEGER)) {
719
+ throw new InputError(`\`number\` is ${String(resolved.number)}, too large to write in parts of ${String(resolved.denominator)}.`, "number");
720
+ }
721
+ return fractionText(resolved.number, resolved.denominator);
654
722
  }
655
723
  /**
656
724
  * Maps a value from 0 to 1 onto the range `min` to `max` along an easing curve, so the result
@@ -714,7 +782,7 @@ export class MathBitByBit {
714
782
  */
715
783
  lerp(inputs) {
716
784
  const resolved = resolveDto(Inputs.Math.LerpDto, inputs);
717
- return resolved.start + (resolved.end - resolved.start) * resolved.t;
785
+ return interpolated(resolved.start, resolved.end, resolved.t);
718
786
  }
719
787
  /**
720
788
  * Finds where a value sits between a start and an end, as a fraction: the `t` that `lerp` would
@@ -751,8 +819,7 @@ export class MathBitByBit {
751
819
  */
752
820
  smoothstep(inputs) {
753
821
  const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
754
- const t = Math.max(0, Math.min(1, resolved.number));
755
- return t * t * (3 - 2 * t);
822
+ return smoothstep(resolved.number);
756
823
  }
757
824
  /**
758
825
  * Tells the sign of a number: -1 when negative, 0 when zero, 1 when positive.
@@ -781,7 +848,7 @@ export class MathBitByBit {
781
848
  */
782
849
  fract(inputs) {
783
850
  const resolved = resolveDto(Inputs.Math.NumberDto, inputs);
784
- return resolved.number - Math.floor(resolved.number);
851
+ return fractionOf(resolved.number);
785
852
  }
786
853
  /**
787
854
  * Wraps a number into a range so it cycles round: past `max` it comes back in at `min`, and