@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,4 +1,4 @@
1
- import { BLOCK_TYPE_BITS, BYTE_BITS, CODE_LENGTH_BITS, CODE_LENGTH_ORDER, CODE_LENGTH_SYMBOLS, DISTANCE_BASE, DISTANCE_EXTRA, DISTANCE_SYMBOLS, DYNAMIC_BLOCK, END_OF_BLOCK, FIRST_LENGTH_SYMBOL, FIXED_BLOCK, FIXED_DISTANCE_BITS, FIXED_LITERAL_BITS, FIXED_LITERAL_ENDS, HCLEN_BASE, HCLEN_BITS, HDIST_BASE, HDIST_BITS, HLIT_BASE, HLIT_BITS, INITIAL_OUTPUT, LENGTH_BASE, LENGTH_EXTRA, LENGTH_MASK, LITERAL_LENGTH_SYMBOLS, MAX_CODE_BITS, REFILL_BELOW, REPEAT_PREVIOUS, REPEAT_PREVIOUS_BASE, REPEAT_PREVIOUS_BITS, REPEAT_ZERO_LONG_BASE, REPEAT_ZERO_LONG_BITS, REPEAT_ZERO_SHORT, REPEAT_ZERO_SHORT_BASE, REPEAT_ZERO_SHORT_BITS, STORED_BLOCK, STORED_HEADER_BYTES, STORED_LENGTH_BYTES, SYMBOL_SHIFT, UINT16_MASK, } from "./inflate.constants";
1
+ import { BLOCK_TYPE_BITS, BYTE_BITS, CODE_LENGTH_BITS, CODE_LENGTH_ORDER, CODE_LENGTH_SYMBOLS, DISTANCE_BASE, DISTANCE_EXTRA, DISTANCE_SYMBOLS, DYNAMIC_BLOCK, END_OF_BLOCK, FIRST_LENGTH_SYMBOL, FIXED_BLOCK, FIXED_DISTANCE_BITS, FIXED_LITERAL_BITS, FIXED_LITERAL_ENDS, HCLEN_BASE, HCLEN_BITS, HDIST_BASE, HDIST_BITS, HLIT_BASE, HLIT_BITS, INITIAL_OUTPUT, MOST_DEFLATE_RATIO, MOST_INFLATED_BYTES, LENGTH_BASE, LENGTH_EXTRA, LENGTH_MASK, LITERAL_LENGTH_SYMBOLS, MAX_CODE_BITS, REFILL_BELOW, REPEAT_PREVIOUS, REPEAT_PREVIOUS_BASE, REPEAT_PREVIOUS_BITS, REPEAT_ZERO_LONG_BASE, REPEAT_ZERO_LONG_BITS, REPEAT_ZERO_SHORT, REPEAT_ZERO_SHORT_BASE, REPEAT_ZERO_SHORT_BITS, STORED_BLOCK, STORED_HEADER_BYTES, STORED_LENGTH_BYTES, SYMBOL_SHIFT, UINT16_MASK, } from "./inflate.constants";
2
2
  function reversed(code, bits) {
3
3
  let result = 0;
4
4
  for (let bit = 0; bit < bits; bit++) {
@@ -50,14 +50,18 @@ function fixed() {
50
50
  return fixedTables;
51
51
  }
52
52
  class Inflater {
53
- constructor(data, expected) {
53
+ constructor(data, expected, limit) {
54
54
  this.data = data;
55
55
  this.expected = expected;
56
+ this.limit = limit;
56
57
  this.at = 0;
57
58
  this.bitBuffer = 0;
58
59
  this.bitCount = 0;
59
60
  this.size = 0;
60
- this.output = new Uint8Array(expected !== null && expected !== void 0 ? expected : Math.max(INITIAL_OUTPUT, data.length * 2));
61
+ if (expected !== undefined && expected > limit) {
62
+ throw new Error(`The deflate stream is said to hold ${expected} bytes, more than the ${limit} this reader inflates`);
63
+ }
64
+ this.output = new Uint8Array(Math.min(expected !== null && expected !== void 0 ? expected : Math.max(INITIAL_OUTPUT, data.length * 2), data.length * MOST_DEFLATE_RATIO + INITIAL_OUTPUT, limit));
61
65
  }
62
66
  run() {
63
67
  let last = 0;
@@ -118,13 +122,18 @@ class Inflater {
118
122
  return entry >> SYMBOL_SHIFT;
119
123
  }
120
124
  room(count) {
125
+ var _a;
121
126
  if (this.size + count <= this.output.length) {
122
127
  return;
123
128
  }
124
- if (this.expected !== undefined) {
129
+ if (this.expected !== undefined && this.size + count > this.expected) {
125
130
  throw new Error(`The deflate stream holds more than the ${this.expected} bytes expected`);
126
131
  }
127
- const grown = new Uint8Array(Math.max(this.output.length * 2, this.size + count));
132
+ if (this.size + count > this.limit) {
133
+ throw new Error(`The deflate stream inflates past the ${this.limit} bytes this reader inflates`);
134
+ }
135
+ const wanted = Math.max(this.output.length * 2, this.size + count);
136
+ const grown = new Uint8Array(Math.min(wanted, (_a = this.expected) !== null && _a !== void 0 ? _a : this.limit));
128
137
  grown.set(this.output.subarray(0, this.size));
129
138
  this.output = grown;
130
139
  }
@@ -223,6 +232,6 @@ class Inflater {
223
232
  }
224
233
  }
225
234
  }
226
- export function inflateRaw(data, expectedSize) {
227
- return new Inflater(data, expectedSize).run();
235
+ export function inflateRaw(data, expectedSize, limit = MOST_INFLATED_BYTES) {
236
+ return new Inflater(data, expectedSize, limit).run();
228
237
  }
@@ -32,3 +32,11 @@ export declare const STORED_METHOD = 0;
32
32
  export declare const DEFLATED_METHOD = 8;
33
33
  export declare const UINT16_BYTES = 2;
34
34
  export declare const UINT32_BYTES = 4;
35
+ export declare const ZIP_VERSION = 20;
36
+ export declare const DOS_EPOCH_YEAR = 1980;
37
+ export declare const DOS_YEAR_SHIFT = 9;
38
+ export declare const DOS_MONTH_SHIFT = 5;
39
+ export declare const DOS_HOUR_SHIFT = 11;
40
+ export declare const DOS_MINUTE_SHIFT = 5;
41
+ export declare const DOS_SECONDS_PER_UNIT = 2;
42
+ export declare const ZIP_MIME_TYPE = "application/zip";
@@ -32,3 +32,11 @@ export const STORED_METHOD = 0;
32
32
  export const DEFLATED_METHOD = 8;
33
33
  export const UINT16_BYTES = 2;
34
34
  export const UINT32_BYTES = 4;
35
+ export const ZIP_VERSION = 20;
36
+ export const DOS_EPOCH_YEAR = 1980;
37
+ export const DOS_YEAR_SHIFT = 9;
38
+ export const DOS_MONTH_SHIFT = 5;
39
+ export const DOS_HOUR_SHIFT = 11;
40
+ export const DOS_MINUTE_SHIFT = 5;
41
+ export const DOS_SECONDS_PER_UNIT = 2;
42
+ export const ZIP_MIME_TYPE = "application/zip";
@@ -0,0 +1,8 @@
1
+ import type { DosDateTime, ZipEntry, ZipFile, ZipStoredRecord } from "../helper-types";
2
+ export declare function isZip(bytes: Uint8Array): boolean;
3
+ export declare function zipEntries(bytes: Uint8Array): ZipEntry[];
4
+ export declare function zipEntryData(bytes: Uint8Array, entry: ZipEntry, limit?: number): Uint8Array;
5
+ export declare function dosDateTime(moment: Date): DosDateTime;
6
+ export declare function zipStoredParts<T>(records: readonly ZipStoredRecord<T>[], modified?: Date): (Uint8Array<ArrayBuffer> | T)[];
7
+ export declare function zipStored(files: readonly ZipFile[], modified?: Date): Uint8Array<ArrayBuffer>;
8
+ export declare function zipStoredBlob(files: readonly ZipFile[], modified?: Date): Blob;
@@ -0,0 +1,226 @@
1
+ import { crc32 } from "./crc32";
2
+ import { inflateRaw } from "./inflate";
3
+ import { MOST_INFLATED_BYTES } from "./inflate.constants";
4
+ import { BYTE_BITS, CENTRAL_COMMENT_LENGTH, CENTRAL_COMPRESSED_SIZE, CENTRAL_CRC32, CENTRAL_EXTRA_LENGTH, CENTRAL_FLAGS, CENTRAL_HEADER_SIGNATURE, CENTRAL_HEADER_SIZE, CENTRAL_LOCAL_OFFSET, CENTRAL_METHOD, CENTRAL_NAME_LENGTH, CENTRAL_SIZE, DEFLATED_METHOD, DOS_EPOCH_YEAR, DOS_HOUR_SHIFT, DOS_MINUTE_SHIFT, DOS_MONTH_SHIFT, DOS_SECONDS_PER_UNIT, DOS_YEAR_SHIFT, ENCRYPTED_FLAG, END_DIRECTORY_OFFSET, END_DIRECTORY_SIZE, END_ENTRY_COUNT, END_OF_CENTRAL_SIGNATURE, END_OF_CENTRAL_SIZE, LOCAL_EXTRA_LENGTH, LOCAL_HEADER_SIGNATURE, LOCAL_HEADER_SIZE, LOCAL_NAME_LENGTH, LONGEST_ARCHIVE_COMMENT, STORED_METHOD, UINT16_BYTES, UINT32_BYTES, UTF8_NAME_FLAG, ZIP64_COUNT, ZIP64_SIZE, ZIP_MIME_TYPE, ZIP_VERSION, } from "./zip.constants";
5
+ const utf8 = new TextDecoder("utf-8");
6
+ const windows1252 = new TextDecoder("windows-1252");
7
+ function uint16(bytes, at) {
8
+ if (at + UINT16_BYTES > bytes.length) {
9
+ throw new Error("The zip archive ends in the middle of a header");
10
+ }
11
+ return bytes[at] | (bytes[at + 1] << BYTE_BITS);
12
+ }
13
+ function uint32(bytes, at) {
14
+ if (at + UINT32_BYTES > bytes.length) {
15
+ throw new Error("The zip archive ends in the middle of a header");
16
+ }
17
+ return (uint16(bytes, at) | (uint16(bytes, at + UINT16_BYTES) << (BYTE_BITS * UINT16_BYTES))) >>> 0;
18
+ }
19
+ export function isZip(bytes) {
20
+ return bytes.length >= UINT32_BYTES && uint32(bytes, 0) === LOCAL_HEADER_SIGNATURE;
21
+ }
22
+ function endOfCentralDirectory(bytes) {
23
+ const last = bytes.length - END_OF_CENTRAL_SIZE;
24
+ for (let at = last; at >= Math.max(0, last - LONGEST_ARCHIVE_COMMENT); at--) {
25
+ if (uint32(bytes, at) === END_OF_CENTRAL_SIGNATURE) {
26
+ return at;
27
+ }
28
+ }
29
+ throw new Error("The zip archive has no end of central directory record");
30
+ }
31
+ export function zipEntries(bytes) {
32
+ const end = endOfCentralDirectory(bytes);
33
+ const count = uint16(bytes, end + END_ENTRY_COUNT);
34
+ const directorySize = uint32(bytes, end + END_DIRECTORY_SIZE);
35
+ const directory = uint32(bytes, end + END_DIRECTORY_OFFSET);
36
+ if (count === ZIP64_COUNT || directorySize === ZIP64_SIZE || directory === ZIP64_SIZE) {
37
+ throw new Error("The zip archive is a ZIP64 archive, which is not read");
38
+ }
39
+ const entries = [];
40
+ let at = directory;
41
+ for (let index = 0; index < count; index++) {
42
+ if (uint32(bytes, at) !== CENTRAL_HEADER_SIGNATURE) {
43
+ throw new Error(`The zip archive's central directory is corrupt at entry ${index}`);
44
+ }
45
+ const flags = uint16(bytes, at + CENTRAL_FLAGS);
46
+ const nameLength = uint16(bytes, at + CENTRAL_NAME_LENGTH);
47
+ const nameBytes = bytes.subarray(at + CENTRAL_HEADER_SIZE, at + CENTRAL_HEADER_SIZE + nameLength);
48
+ entries.push({
49
+ name: (flags & UTF8_NAME_FLAG ? utf8 : windows1252).decode(nameBytes),
50
+ method: uint16(bytes, at + CENTRAL_METHOD),
51
+ crc32: uint32(bytes, at + CENTRAL_CRC32),
52
+ compressedSize: uint32(bytes, at + CENTRAL_COMPRESSED_SIZE),
53
+ size: uint32(bytes, at + CENTRAL_SIZE),
54
+ localOffset: uint32(bytes, at + CENTRAL_LOCAL_OFFSET),
55
+ encrypted: (flags & ENCRYPTED_FLAG) !== 0,
56
+ });
57
+ at += CENTRAL_HEADER_SIZE + nameLength + uint16(bytes, at + CENTRAL_EXTRA_LENGTH) + uint16(bytes, at + CENTRAL_COMMENT_LENGTH);
58
+ }
59
+ refuseOverlappingEntries(entries, directory);
60
+ return entries;
61
+ }
62
+ function refuseOverlappingEntries(entries, directory) {
63
+ const byOffset = [...entries].sort((first, second) => first.localOffset - second.localOffset);
64
+ for (let index = 0; index < byOffset.length; index++) {
65
+ const entry = byOffset[index];
66
+ const end = entry.localOffset + LOCAL_HEADER_SIZE + entry.compressedSize;
67
+ const next = byOffset[index + 1];
68
+ if (next !== undefined && end > next.localOffset) {
69
+ throw new Error(`The zip archive's entries ${entry.name} and ${next.name} share their data, which a zip bomb does and an archive never needs`);
70
+ }
71
+ if (end > directory) {
72
+ throw new Error(`${entry.name} runs into the zip archive's central directory`);
73
+ }
74
+ }
75
+ }
76
+ export function zipEntryData(bytes, entry, limit = MOST_INFLATED_BYTES) {
77
+ if (entry.encrypted) {
78
+ throw new Error(`${entry.name} in the zip archive is encrypted`);
79
+ }
80
+ if (uint32(bytes, entry.localOffset) !== LOCAL_HEADER_SIGNATURE) {
81
+ throw new Error(`The zip archive's local header of ${entry.name} is missing`);
82
+ }
83
+ const start = entry.localOffset + LOCAL_HEADER_SIZE + uint16(bytes, entry.localOffset + LOCAL_NAME_LENGTH) + uint16(bytes, entry.localOffset + LOCAL_EXTRA_LENGTH);
84
+ if (start + entry.compressedSize > bytes.length) {
85
+ throw new Error(`${entry.name} runs past the end of the zip archive`);
86
+ }
87
+ const stored = bytes.subarray(start, start + entry.compressedSize);
88
+ let data;
89
+ if (entry.method === STORED_METHOD) {
90
+ data = stored;
91
+ }
92
+ else if (entry.method === DEFLATED_METHOD) {
93
+ data = inflateRaw(stored, entry.size, limit);
94
+ }
95
+ else {
96
+ throw new Error(`${entry.name} is compressed with zip method ${entry.method}; only stored and deflated entries are read`);
97
+ }
98
+ if (data.length !== entry.size) {
99
+ throw new Error(`${entry.name} holds ${data.length} bytes, not the ${entry.size} its zip archive records`);
100
+ }
101
+ if (crc32(data) !== entry.crc32) {
102
+ throw new Error(`${entry.name} fails its CRC-32 check`);
103
+ }
104
+ return data;
105
+ }
106
+ export function dosDateTime(moment) {
107
+ const year = Math.max(DOS_EPOCH_YEAR, moment.getFullYear());
108
+ return {
109
+ time: (moment.getHours() << DOS_HOUR_SHIFT) | (moment.getMinutes() << DOS_MINUTE_SHIFT) | Math.floor(moment.getSeconds() / DOS_SECONDS_PER_UNIT),
110
+ date: ((year - DOS_EPOCH_YEAR) << DOS_YEAR_SHIFT) | ((moment.getMonth() + 1) << DOS_MONTH_SHIFT) | moment.getDate(),
111
+ };
112
+ }
113
+ function headerWriter(size) {
114
+ const bytes = new Uint8Array(size);
115
+ const view = new DataView(bytes.buffer);
116
+ let at = 0;
117
+ return {
118
+ bytes,
119
+ u16: (value) => {
120
+ view.setUint16(at, value, true);
121
+ at += UINT16_BYTES;
122
+ },
123
+ u32: (value) => {
124
+ view.setUint32(at, value, true);
125
+ at += UINT32_BYTES;
126
+ },
127
+ raw: (value) => {
128
+ bytes.set(value, at);
129
+ at += value.length;
130
+ },
131
+ };
132
+ }
133
+ function sharedFields(writer, name, record, stamp) {
134
+ writer.u16(UTF8_NAME_FLAG);
135
+ writer.u16(STORED_METHOD);
136
+ writer.u16(stamp.time);
137
+ writer.u16(stamp.date);
138
+ writer.u32(record.crc32);
139
+ writer.u32(record.size);
140
+ writer.u32(record.size);
141
+ writer.u16(name.length);
142
+ writer.u16(0);
143
+ }
144
+ function checkedEntryName(name) {
145
+ const segments = name.split("/");
146
+ if (name === "" || name.startsWith("/") || name.includes("\\") || /^[A-Za-z]:/.test(name) || segments.includes("..") || /\p{Cc}/u.test(name)) {
147
+ throw new Error(`"${name}" cannot be a zip entry name: it must be a relative path without "..", backslashes or control characters`);
148
+ }
149
+ return name;
150
+ }
151
+ export function zipStoredParts(records, modified = new Date()) {
152
+ if (records.length >= ZIP64_COUNT) {
153
+ throw new Error(`A zip archive written here holds at most ${ZIP64_COUNT - 1} entries, not ${records.length}`);
154
+ }
155
+ const stamp = dosDateTime(modified);
156
+ const encoder = new TextEncoder();
157
+ const names = records.map((record) => encoder.encode(checkedEntryName(record.name)));
158
+ names.forEach((name, index) => {
159
+ if (name.length > LONGEST_ARCHIVE_COMMENT) {
160
+ throw new Error(`Zip entry ${index} has a name longer than ${LONGEST_ARCHIVE_COMMENT} bytes`);
161
+ }
162
+ });
163
+ let total = 0;
164
+ for (const record of records) {
165
+ total += record.size;
166
+ if (record.size >= ZIP64_SIZE || total >= ZIP64_SIZE) {
167
+ throw new Error("A zip archive written here holds less than 4 GB in all, because it does not write ZIP64");
168
+ }
169
+ }
170
+ const parts = [];
171
+ const offsets = [];
172
+ let at = 0;
173
+ records.forEach((record, index) => {
174
+ const name = names[index];
175
+ const local = headerWriter(LOCAL_HEADER_SIZE + name.length);
176
+ local.u32(LOCAL_HEADER_SIGNATURE);
177
+ local.u16(ZIP_VERSION);
178
+ sharedFields(local, name, record, stamp);
179
+ local.raw(name);
180
+ offsets.push(at);
181
+ parts.push(local.bytes, record.data);
182
+ at += local.bytes.length + record.size;
183
+ });
184
+ const directory = at;
185
+ records.forEach((record, index) => {
186
+ const name = names[index];
187
+ const central = headerWriter(CENTRAL_HEADER_SIZE + name.length);
188
+ central.u32(CENTRAL_HEADER_SIGNATURE);
189
+ central.u16(ZIP_VERSION);
190
+ central.u16(ZIP_VERSION);
191
+ sharedFields(central, name, record, stamp);
192
+ central.u16(0);
193
+ central.u16(0);
194
+ central.u16(0);
195
+ central.u32(0);
196
+ central.u32(offsets[index]);
197
+ central.raw(name);
198
+ parts.push(central.bytes);
199
+ at += central.bytes.length;
200
+ });
201
+ const end = headerWriter(END_OF_CENTRAL_SIZE);
202
+ end.u32(END_OF_CENTRAL_SIGNATURE);
203
+ end.u16(0);
204
+ end.u16(0);
205
+ end.u16(records.length);
206
+ end.u16(records.length);
207
+ end.u32(at - directory);
208
+ end.u32(directory);
209
+ end.u16(0);
210
+ parts.push(end.bytes);
211
+ return parts;
212
+ }
213
+ export function zipStored(files, modified = new Date()) {
214
+ const parts = zipStoredParts(files.map((file) => ({ name: file.name, size: file.data.length, crc32: crc32(file.data), data: file.data })), modified);
215
+ const archive = new Uint8Array(parts.reduce((sum, part) => sum + part.length, 0));
216
+ let at = 0;
217
+ for (const part of parts) {
218
+ archive.set(part, at);
219
+ at += part.length;
220
+ }
221
+ return archive;
222
+ }
223
+ export function zipStoredBlob(files, modified = new Date()) {
224
+ const records = files.map((file) => ({ name: file.name, size: file.data.length, crc32: crc32(file.data), data: file.data }));
225
+ return new Blob(zipStoredParts(records, modified), { type: ZIP_MIME_TYPE });
226
+ }
@@ -0,0 +1,9 @@
1
+ import type * as Inputs from "../../../inputs";
2
+ import type { ThreePointArc } from "../helper-types";
3
+ type Point2 = Inputs.Base.Point2;
4
+ type Point3 = Inputs.Base.Point3;
5
+ export declare const arcThroughThreePoints: (start: Point3, middle: Point3, end: Point3) => ThreePointArc | undefined;
6
+ export declare const pointsOnArc: (arc: ThreePointArc, start: Point3, end: Point3, segments: number) => Point3[];
7
+ export declare const pointOnCubic2: (from: Point2, control1: Point2, control2: Point2, to: Point2, t: number) => Point2;
8
+ export declare const pointOnCubic3: (from: Point3, control1: Point3, control2: Point3, to: Point3, t: number) => Point3;
9
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { add3, cross3, dot3, length3, scale3, subtract3 } from "./vectors";
2
2
  const FULL_TURN = 2 * Math.PI;
3
3
  const COLLINEAR_RATIO = 1e-12;
4
+ const CUBIC_MIDDLE_WEIGHT = 3;
4
5
  export const arcThroughThreePoints = (start, middle, end) => {
5
6
  const toMiddle = subtract3(middle, start);
6
7
  const toEnd = subtract3(end, start);
@@ -28,3 +29,9 @@ export const pointsOnArc = (arc, start, end, segments) => {
28
29
  points.push(end);
29
30
  return points;
30
31
  };
32
+ const cubicBlend = (from, control1, control2, to, t) => {
33
+ const u = 1 - t;
34
+ return u * u * u * from + CUBIC_MIDDLE_WEIGHT * u * t * (u * control1 + t * control2) + t * t * t * to;
35
+ };
36
+ export const pointOnCubic2 = (from, control1, control2, to, t) => [cubicBlend(from[0], control1[0], control2[0], to[0], t), cubicBlend(from[1], control1[1], control2[1], to[1], t)];
37
+ export const pointOnCubic3 = (from, control1, control2, to, t) => [cubicBlend(from[0], control1[0], control2[0], to[0], t), cubicBlend(from[1], control1[1], control2[1], to[1], t), cubicBlend(from[2], control1[2], control2[2], to[2], t)];
@@ -1,4 +1,4 @@
1
- import type * as Inputs from "../../inputs";
1
+ import type * as Inputs from "../../../inputs";
2
2
  type Vec3 = Inputs.Base.Vector3;
3
3
  /**
4
4
  * The sine below which two directions count as parallel wherever a frame is squared: a direction
@@ -19,10 +19,6 @@ export interface FrameAxes {
19
19
  export declare const isTriple: (value: unknown) => value is Vec3;
20
20
  /** Whether a value has the shape of a frame: an `origin`, a `normal` and a `direction`, three finite numbers each. */
21
21
  export declare const isFrameShaped: (value: unknown) => value is Inputs.Base.Frame;
22
- /**
23
- * A vector scaled to length 1, or undefined for one of no length. It is divided by its largest
24
- * component before it is measured, so no square overflows or underflows at any finite size.
25
- */
26
22
  export declare const unitOf: (vector: Vec3) => Vec3 | undefined;
27
23
  /**
28
24
  * The axes of an origin, a normal and a rough X direction: the normal scaled to length 1 and the
@@ -33,6 +29,13 @@ export declare const unitOf: (vector: Vec3) => Vec3 | undefined;
33
29
  * the first subtraction, and the second takes out what rounding left along the normal.
34
30
  */
35
31
  export declare const squareFrame: (origin: Vec3, normal: Vec3, direction: Vec3) => FrameAxes | "normal" | "direction";
32
+ /**
33
+ * The axes of an origin and a normal alone: X is the world axis least aligned with the normal,
34
+ * squared to it, so the choice never comes close to parallel. Axes within a billionth of the least
35
+ * aligned count as tied and the first of them, in X, Y, Z order, is taken, so rounding noise in the
36
+ * normal cannot turn the frame. Gives undefined for a normal of no length.
37
+ */
38
+ export declare const axesAlong: (origin: Vec3, normal: Vec3) => FrameAxes | undefined;
36
39
  export declare const WORLD_AXES: FrameAxes;
37
40
  export declare const vectorToWorld: (axes: FrameAxes, vector: Vec3) => Vec3;
38
41
  export declare const pointToWorld: (axes: FrameAxes, point: Vec3) => Vec3;
@@ -1,8 +1,10 @@
1
+ import { cross3, dot3, scale3, subtract3 } from "./vectors";
1
2
  /**
2
3
  * The sine below which two directions count as parallel wherever a frame is squared: a direction
3
4
  * closer than this to its normal leaves the X axis to rounding.
4
5
  */
5
6
  export const PARALLEL_SINE = 1e-9;
7
+ const LEAST_ALIGNED_SLACK = 1e-9;
6
8
  /** Whether a value is three finite numbers. */
7
9
  export const isTriple = (value) => Array.isArray(value) && value.length === 3 && value.every(n => typeof n === "number" && Number.isFinite(n));
8
10
  /** Whether a value has the shape of a frame: an `origin`, a `normal` and a `direction`, three finite numbers each. */
@@ -13,10 +15,6 @@ export const isFrameShaped = (value) => {
13
15
  const fields = value;
14
16
  return isTriple(fields["origin"]) && isTriple(fields["normal"]) && isTriple(fields["direction"]);
15
17
  };
16
- /**
17
- * A vector scaled to length 1, or undefined for one of no length. It is divided by its largest
18
- * component before it is measured, so no square overflows or underflows at any finite size.
19
- */
20
18
  export const unitOf = (vector) => {
21
19
  const largest = Math.max(Math.abs(vector[0]), Math.abs(vector[1]), Math.abs(vector[2]));
22
20
  if (!(largest > 0 && largest < Infinity)) {
@@ -26,10 +24,7 @@ export const unitOf = (vector) => {
26
24
  const length = Math.hypot(scaled[0], scaled[1], scaled[2]);
27
25
  return [scaled[0] / length, scaled[1] / length, scaled[2] / length];
28
26
  };
29
- const withoutPartAlong = (vector, unit) => {
30
- const along = vector[0] * unit[0] + vector[1] * unit[1] + vector[2] * unit[2];
31
- return [vector[0] - along * unit[0], vector[1] - along * unit[1], vector[2] - along * unit[2]];
32
- };
27
+ const withoutPartAlong = (vector, unit) => subtract3(vector, scale3(unit, dot3(vector, unit)));
33
28
  /**
34
29
  * The axes of an origin, a normal and a rough X direction: the normal scaled to length 1 and the
35
30
  * direction turned square to it. Gives the name of the part that cannot be squared instead: a
@@ -52,9 +47,26 @@ export const squareFrame = (origin, normal, direction) => {
52
47
  return "direction";
53
48
  }
54
49
  const x = unitOf(withoutPartAlong(square, z));
55
- const y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
50
+ const y = cross3(z, x);
56
51
  return { origin: [origin[0], origin[1], origin[2]], x, y, z };
57
52
  };
53
+ /**
54
+ * The axes of an origin and a normal alone: X is the world axis least aligned with the normal,
55
+ * squared to it, so the choice never comes close to parallel. Axes within a billionth of the least
56
+ * aligned count as tied and the first of them, in X, Y, Z order, is taken, so rounding noise in the
57
+ * normal cannot turn the frame. Gives undefined for a normal of no length.
58
+ */
59
+ export const axesAlong = (origin, normal) => {
60
+ const z = unitOf(normal);
61
+ if (z === undefined) {
62
+ return undefined;
63
+ }
64
+ const magnitudes = z.map(Math.abs);
65
+ const least = Math.min(...magnitudes);
66
+ const pick = magnitudes.findIndex(magnitude => magnitude <= least + LEAST_ALIGNED_SLACK);
67
+ const across = pick === 0 ? [1, 0, 0] : pick === 1 ? [0, 1, 0] : [0, 0, 1];
68
+ return squareFrame(origin, z, across);
69
+ };
58
70
  export const WORLD_AXES = { origin: [0, 0, 0], x: [1, 0, 0], y: [0, 1, 0], z: [0, 0, 1] };
59
71
  export const vectorToWorld = (axes, vector) => [
60
72
  (axes.x[0] * vector[0] + axes.y[0] * vector[1]) + axes.z[0] * vector[2],
@@ -0,0 +1,4 @@
1
+ import type { UnitOfLength } from "../helper-types";
2
+ export declare const MILLIMETRES_PER_UNIT: Readonly<Record<UnitOfLength, number>>;
3
+ export declare const CONVERTED_PLACES = 9;
4
+ export declare const TABLE_PLACES: Readonly<Record<UnitOfLength, number>>;
@@ -0,0 +1,3 @@
1
+ export const MILLIMETRES_PER_UNIT = { mm: 1, cm: 10, m: 1000, in: 25.4 };
2
+ export const CONVERTED_PLACES = 9;
3
+ export const TABLE_PLACES = { mm: 4, cm: 5, m: 7, in: 4 };
@@ -0,0 +1,7 @@
1
+ import type { UnitOfLength } from "../helper-types";
2
+ export declare const checkedUnitOfLength: (unit: unknown, property: string) => UnitOfLength;
3
+ export declare const millimetresPerUnitOf: (unit: UnitOfLength) => number;
4
+ export declare const lengthConverted: (value: number, from: UnitOfLength, to: UnitOfLength) => number;
5
+ export declare const snappedLength: (value: number, from: UnitOfLength, to: UnitOfLength) => number;
6
+ export declare const tableLength: (value: number, from: UnitOfLength, table: UnitOfLength) => number;
7
+ export declare function lengthsConverted<T extends Readonly<Record<K, number>>, K extends keyof T>(record: T, fields: readonly K[], from: UnitOfLength, to: UnitOfLength): T;
@@ -0,0 +1,20 @@
1
+ import { InputError } from "../../../kernel-calls/errors";
2
+ import { roundedTo } from "./scalars";
3
+ import { CONVERTED_PLACES, MILLIMETRES_PER_UNIT, TABLE_PLACES } from "./lengths.constants";
4
+ const UNITS = Object.keys(MILLIMETRES_PER_UNIT);
5
+ const isUnitOfLength = (unit) => typeof unit === "string" && UNITS.includes(unit);
6
+ export const checkedUnitOfLength = (unit, property) => {
7
+ if (!isUnitOfLength(unit)) {
8
+ throw new InputError(`\`${property}\` is ${String(unit)}, which is none of ${UNITS.join(", ")}.`, property);
9
+ }
10
+ return unit;
11
+ };
12
+ export const millimetresPerUnitOf = (unit) => MILLIMETRES_PER_UNIT[unit];
13
+ export const lengthConverted = (value, from, to) => from === to ? value : value * MILLIMETRES_PER_UNIT[from] / MILLIMETRES_PER_UNIT[to];
14
+ export const snappedLength = (value, from, to) => from === to ? value : roundedTo(lengthConverted(value, from, to), CONVERTED_PLACES);
15
+ export const tableLength = (value, from, table) => from === table ? value : roundedTo(lengthConverted(value, from, table), TABLE_PLACES[table]);
16
+ export function lengthsConverted(record, fields, from, to) {
17
+ const converted = {};
18
+ fields.forEach(field => { converted[field] = snappedLength(record[field], from, to); });
19
+ return Object.assign(Object.assign({}, record), converted);
20
+ }
@@ -0,0 +1,8 @@
1
+ import type * as Inputs from "../../../inputs";
2
+ export declare const RIGID_TOLERANCE = 1e-7;
3
+ export declare const LINEAR_COLUMN_STARTS: readonly [0, 4, 8];
4
+ export declare const MATRIX_COLUMN = 4;
5
+ export declare const TRANSLATION_START = 12;
6
+ export declare const W_AXIS = 3;
7
+ export declare const POSITION_SIZE = 3;
8
+ export declare const IDENTITY_MATRIX: Inputs.Base.TransformMatrix;
@@ -0,0 +1,7 @@
1
+ export const RIGID_TOLERANCE = 1e-7;
2
+ export const LINEAR_COLUMN_STARTS = [0, 4, 8];
3
+ export const MATRIX_COLUMN = 4;
4
+ export const TRANSLATION_START = 12;
5
+ export const W_AXIS = 3;
6
+ export const POSITION_SIZE = 3;
7
+ export const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
@@ -0,0 +1,17 @@
1
+ import type * as Inputs from "../../../inputs";
2
+ type Vec3 = Inputs.Base.Vector3;
3
+ export declare const isTransformMatrix: (value: unknown) => value is Inputs.Base.TransformMatrix;
4
+ export declare const movedCoordinate: (matrix: readonly number[], x: number, y: number, z: number, axis: number) => number;
5
+ export declare const movedPoint: (matrix: readonly number[], point: readonly number[]) => Inputs.Base.Point3;
6
+ export declare const turnedVector: (matrix: readonly number[], vector: readonly number[]) => Inputs.Base.Vector3;
7
+ export declare const movedPositions: (matrix: readonly number[], positions: ArrayLike<number>) => Float64Array;
8
+ export declare const followedBy: (first: readonly number[], second: readonly number[]) => Inputs.Base.TransformMatrix;
9
+ export declare const rigidInverse: (matrix: readonly number[]) => Inputs.Base.TransformMatrix;
10
+ export declare const linearDeterminant: (matrix: readonly number[]) => number;
11
+ export declare const isRigidMatrix: (matrix: readonly number[], tolerance?: number) => boolean;
12
+ export declare const composed: (matrices: readonly (readonly number[])[]) => Inputs.Base.TransformMatrix;
13
+ export declare const symmetricEigen: (matrix: readonly (readonly number[])[]) => {
14
+ value: number;
15
+ vector: Vec3;
16
+ }[];
17
+ export {};
@@ -1,8 +1,26 @@
1
- import { LINEAR_COLUMN_STARTS, RIGID_TOLERANCE } from "./matrices.constants";
2
- import { dot3 } from "./vectors";
3
- /** Whether a value is one column-major 4 x 4 matrix: sixteen finite numbers. */
1
+ import { IDENTITY_MATRIX, LINEAR_COLUMN_STARTS, MATRIX_COLUMN, POSITION_SIZE, RIGID_TOLERANCE, TRANSLATION_START } from "./matrices.constants";
2
+ import { dot3, length3 } from "./vectors";
4
3
  export const isTransformMatrix = (value) => Array.isArray(value) && value.length === 16 && value.every(n => typeof n === "number" && Number.isFinite(n));
5
- /** The product of two column-major 4 x 4 matrices: `first` applied, then `second`. */
4
+ export const movedCoordinate = (matrix, x, y, z, axis) => matrix[axis] * x + matrix[MATRIX_COLUMN + axis] * y + matrix[2 * MATRIX_COLUMN + axis] * z + matrix[TRANSLATION_START + axis];
5
+ export const movedPoint = (matrix, point) => {
6
+ const [x, y, z] = [point[0], point[1], point[2]];
7
+ return [movedCoordinate(matrix, x, y, z, 0), movedCoordinate(matrix, x, y, z, 1), movedCoordinate(matrix, x, y, z, 2)];
8
+ };
9
+ export const turnedVector = (matrix, vector) => {
10
+ const [x, y, z] = [vector[0], vector[1], vector[2]];
11
+ const turned = (axis) => matrix[axis] * x + matrix[MATRIX_COLUMN + axis] * y + matrix[2 * MATRIX_COLUMN + axis] * z;
12
+ return [turned(0), turned(1), turned(2)];
13
+ };
14
+ export const movedPositions = (matrix, positions) => {
15
+ const moved = new Float64Array(positions.length);
16
+ for (let at = 0; at + POSITION_SIZE <= positions.length; at += POSITION_SIZE) {
17
+ const [x, y, z] = [positions[at], positions[at + 1], positions[at + 2]];
18
+ moved[at] = movedCoordinate(matrix, x, y, z, 0);
19
+ moved[at + 1] = movedCoordinate(matrix, x, y, z, 1);
20
+ moved[at + 2] = movedCoordinate(matrix, x, y, z, 2);
21
+ }
22
+ return moved;
23
+ };
6
24
  export const followedBy = (first, second) => {
7
25
  const product = Array.from({ length: 16 }, (_, index) => {
8
26
  const column = Math.floor(index / 4);
@@ -12,28 +30,21 @@ export const followedBy = (first, second) => {
12
30
  });
13
31
  return product;
14
32
  };
15
- /** The determinant of a column-major 4 x 4 matrix's rotation and scale part: negative when it mirrors, near zero when it flattens. */
33
+ export const rigidInverse = (matrix) => {
34
+ const [a, b, c, , d, e, f, , g, h, i, , x, y, z] = matrix;
35
+ return [a, d, g, 0, b, e, h, 0, c, f, i, 0, -(a * x + b * y + c * z), -(d * x + e * y + f * z), -(g * x + h * y + i * z), 1];
36
+ };
16
37
  export const linearDeterminant = (matrix) => {
17
38
  const [a, b, c, , d, e, f, , g, h, i] = matrix;
18
39
  return a * (e * i - f * h) - d * (b * i - c * h) + g * (b * f - c * e);
19
40
  };
20
- /**
21
- * Whether a column-major 4 x 4 matrix only turns and moves: its rotation and scale part has columns
22
- * of length 1 and at right angles, within `tolerance` on their squared lengths and dot products, and
23
- * keeps its handedness.
24
- */
25
41
  export const isRigidMatrix = (matrix, tolerance = RIGID_TOLERANCE) => {
26
42
  const [x, y, z] = LINEAR_COLUMN_STARTS.map((start) => [matrix[start], matrix[start + 1], matrix[start + 2]]);
27
- return [x, y, z].every((column) => Math.abs(dot3(column, column) - 1) <= tolerance)
43
+ return [x, y, z].every((column) => Math.abs(length3(column) - 1) <= tolerance)
28
44
  && Math.abs(dot3(x, y)) <= tolerance && Math.abs(dot3(x, z)) <= tolerance && Math.abs(dot3(y, z)) <= tolerance
29
45
  && linearDeterminant(matrix) > 0;
30
46
  };
31
- /** One column-major 4 x 4 matrix that applies a list of them first to last; the identity for an empty list. */
32
- export const composed = (matrices) => matrices.reduce((total, matrix) => followedBy(total, matrix), [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
33
- /**
34
- * The eigenvalues of a symmetric 3 x 3 matrix, largest first, each with its unit eigenvector, by
35
- * cyclic Jacobi rotations; the vectors come out at right angles to each other.
36
- */
47
+ export const composed = (matrices) => matrices.reduce((total, matrix) => followedBy(total, matrix), [...IDENTITY_MATRIX]);
37
48
  export const symmetricEigen = (matrix) => {
38
49
  let a = matrix.map(row => [...row]);
39
50
  let v = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
@@ -1,6 +1,7 @@
1
- import type * as Inputs from "../../inputs";
1
+ import type * as Inputs from "../../../inputs";
2
2
  type Vec3 = Inputs.Base.Vector3;
3
3
  type Point3 = Inputs.Base.Point3;
4
+ export declare const pathLength3: (points: readonly Point3[]) => number;
4
5
  export declare const pathTangents: (points: readonly Point3[], start?: Vec3, end?: Vec3) => Vec3[];
5
6
  export declare const transportedAxes: (points: readonly Point3[], tangents: readonly Vec3[], first: Vec3) => Vec3[];
6
7
  export declare const sweepMatrices: (points: readonly Point3[], tangents: readonly Vec3[], xAxes: readonly Vec3[]) => Inputs.Base.TransformMatrix[];