@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.
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/bearings/ansi-bearings.constants.d.ts +2 -0
- package/lib/api/bearings/ansi-bearings.constants.js +26 -0
- package/lib/api/bearings/ansi-bearings.d.ts +4 -0
- package/lib/api/bearings/ansi-bearings.js +14 -0
- package/lib/api/bearings/bearing-types.d.ts +25 -0
- package/lib/api/bearings/bearing-types.js +1 -0
- package/lib/api/bearings/bearings.constants.d.ts +1 -0
- package/lib/api/bearings/bearings.constants.js +1 -0
- package/lib/api/bearings/iso-bearings.constants.d.ts +2 -0
- package/lib/api/bearings/iso-bearings.constants.js +30 -0
- package/lib/api/bearings/iso-bearings.d.ts +4 -0
- package/lib/api/bearings/iso-bearings.js +14 -0
- package/lib/api/color-space.d.ts +2 -0
- package/lib/api/color-space.js +5 -8
- package/lib/api/fasteners/ansi-fasteners.constants.d.ts +16 -0
- package/lib/api/fasteners/ansi-fasteners.constants.js +118 -0
- package/lib/api/fasteners/ansi-fasteners.d.ts +8 -0
- package/lib/api/fasteners/ansi-fasteners.js +64 -0
- package/lib/api/fasteners/fastener-types.d.ts +161 -0
- package/lib/api/fasteners/fastener-types.js +1 -0
- package/lib/api/fasteners/fasteners.constants.d.ts +5 -0
- package/lib/api/fasteners/fasteners.constants.js +5 -0
- package/lib/api/fasteners/fasteners.d.ts +2 -0
- package/lib/api/fasteners/fasteners.js +9 -0
- package/lib/api/fasteners/iso-fasteners.constants.d.ts +23 -0
- package/lib/api/fasteners/iso-fasteners.constants.js +110 -0
- package/lib/api/fasteners/iso-fasteners.d.ts +9 -0
- package/lib/api/fasteners/iso-fasteners.js +61 -0
- package/lib/api/gears/bevel-gears.d.ts +6 -0
- package/lib/api/gears/bevel-gears.js +69 -0
- package/lib/api/gears/gear-checks.d.ts +8 -0
- package/lib/api/gears/gear-checks.js +69 -0
- package/lib/api/gears/gear-pairs.d.ts +4 -0
- package/lib/api/gears/gear-pairs.js +140 -0
- package/lib/api/gears/gear-types.d.ts +425 -0
- package/lib/api/gears/gear-types.js +1 -0
- package/lib/api/gears/gears.constants.d.ts +19 -0
- package/lib/api/gears/gears.constants.js +19 -0
- package/lib/api/gears/gears.d.ts +10 -0
- package/lib/api/gears/gears.js +156 -0
- package/lib/api/gears/helical-gears.d.ts +5 -0
- package/lib/api/gears/helical-gears.js +33 -0
- package/lib/api/gears/involute-flank.d.ts +26 -0
- package/lib/api/gears/involute-flank.js +158 -0
- package/lib/api/gears/racks.d.ts +3 -0
- package/lib/api/gears/racks.js +64 -0
- package/lib/api/index.d.ts +10 -1
- package/lib/api/index.js +0 -1
- package/lib/api/inputs/base-inputs.d.ts +450 -3
- package/lib/api/inputs/base-inputs.js +12 -0
- package/lib/api/inputs/color-inputs.d.ts +14 -0
- package/lib/api/inputs/color-inputs.js +19 -0
- package/lib/api/inputs/engineering-inputs.d.ts +1539 -0
- package/lib/api/inputs/engineering-inputs.js +2181 -0
- package/lib/api/inputs/index.d.ts +2 -0
- package/lib/api/inputs/index.js +2 -0
- package/lib/api/inputs/io-inputs.d.ts +8 -1
- package/lib/api/inputs/io-inputs.js +4 -1
- package/lib/api/inputs/math-inputs.d.ts +61 -0
- package/lib/api/inputs/math-inputs.js +85 -0
- package/lib/api/inputs/mesh-inputs.d.ts +170 -0
- package/lib/api/inputs/mesh-inputs.js +206 -0
- package/lib/api/inputs/point-inputs.d.ts +4 -4
- package/lib/api/inputs/polyline-inputs.d.ts +144 -0
- package/lib/api/inputs/polyline-inputs.js +151 -0
- package/lib/api/inputs/recipes-inputs.d.ts +76 -0
- package/lib/api/inputs/recipes-inputs.js +74 -0
- package/lib/api/inputs/transforms-inputs.d.ts +34 -0
- package/lib/api/inputs/transforms-inputs.js +35 -0
- package/lib/api/keys/ansi-keys.constants.d.ts +3 -0
- package/lib/api/keys/ansi-keys.constants.js +16 -0
- package/lib/api/keys/ansi-keys.d.ts +3 -0
- package/lib/api/keys/ansi-keys.js +14 -0
- package/lib/api/keys/din-keys.constants.d.ts +3 -0
- package/lib/api/keys/din-keys.constants.js +14 -0
- package/lib/api/keys/din-keys.d.ts +3 -0
- package/lib/api/keys/din-keys.js +13 -0
- package/lib/api/keys/key-types.d.ts +17 -0
- package/lib/api/keys/key-types.js +1 -0
- package/lib/api/keys/keys.constants.d.ts +1 -0
- package/lib/api/keys/keys.constants.js +1 -0
- package/lib/api/knurls/ansi-knurls.constants.d.ts +4 -0
- package/lib/api/knurls/ansi-knurls.constants.js +8 -0
- package/lib/api/knurls/ansi-knurls.d.ts +3 -0
- package/lib/api/knurls/ansi-knurls.js +20 -0
- package/lib/api/knurls/din-knurls.constants.d.ts +2 -0
- package/lib/api/knurls/din-knurls.constants.js +2 -0
- package/lib/api/knurls/din-knurls.d.ts +3 -0
- package/lib/api/knurls/din-knurls.js +19 -0
- package/lib/api/knurls/knurl-types.d.ts +24 -0
- package/lib/api/knurls/knurl-types.js +1 -0
- package/lib/api/knurls/knurls.constants.d.ts +1 -0
- package/lib/api/knurls/knurls.constants.js +1 -0
- package/lib/api/knurls/knurls.d.ts +2 -0
- package/lib/api/knurls/knurls.js +9 -0
- package/lib/api/recipes/checks.d.ts +15 -0
- package/lib/api/recipes/checks.js +85 -0
- package/lib/api/recipes/limits.constants.d.ts +4 -0
- package/lib/api/recipes/limits.constants.js +4 -0
- package/lib/api/recipes/sources.d.ts +0 -13
- package/lib/api/recipes/sources.js +3 -15
- package/lib/api/recipes/surface-mesh.d.ts +0 -14
- package/lib/api/recipes/surface-mesh.js +8 -21
- package/lib/api/recipes/validate-brep.d.ts +2 -0
- package/lib/api/recipes/validate-brep.js +330 -0
- package/lib/api/recipes/validate.d.ts +0 -31
- package/lib/api/recipes/validate.js +7 -115
- package/lib/api/resolved-inputs/index.d.ts +80 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.constants.d.ts +4 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.constants.js +93 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.d.ts +4 -0
- package/lib/api/retaining-rings/ansi-retaining-rings.js +20 -0
- package/lib/api/retaining-rings/din-retaining-rings.constants.d.ts +3 -0
- package/lib/api/retaining-rings/din-retaining-rings.constants.js +115 -0
- package/lib/api/retaining-rings/din-retaining-rings.d.ts +4 -0
- package/lib/api/retaining-rings/din-retaining-rings.js +20 -0
- package/lib/api/retaining-rings/retaining-ring-types.d.ts +30 -0
- package/lib/api/retaining-rings/retaining-ring-types.js +1 -0
- package/lib/api/retaining-rings/retaining-rings.constants.d.ts +1 -0
- package/lib/api/retaining-rings/retaining-rings.constants.js +1 -0
- package/lib/api/retaining-rings/retaining-rings.d.ts +2 -0
- package/lib/api/retaining-rings/retaining-rings.js +9 -0
- package/lib/api/services/base-bitbybit.d.ts +42 -0
- package/lib/api/services/base-bitbybit.js +43 -0
- package/lib/api/services/color.d.ts +35 -2
- package/lib/api/services/color.js +48 -12
- package/lib/api/services/engineering/engineering.d.ts +12 -0
- package/lib/api/services/engineering/engineering.js +13 -0
- package/lib/api/services/engineering/index.d.ts +2 -0
- package/lib/api/services/engineering/index.js +2 -0
- package/lib/api/services/engineering/mechanical/bearings-ansi.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/bearings-ansi.js +47 -0
- package/lib/api/services/engineering/mechanical/bearings-iso.d.ts +39 -0
- package/lib/api/services/engineering/mechanical/bearings-iso.js +46 -0
- package/lib/api/services/engineering/mechanical/bearings.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/bearings.js +15 -0
- package/lib/api/services/engineering/mechanical/fasteners-ansi.d.ts +109 -0
- package/lib/api/services/engineering/mechanical/fasteners-ansi.js +133 -0
- package/lib/api/services/engineering/mechanical/fasteners-iso.d.ts +123 -0
- package/lib/api/services/engineering/mechanical/fasteners-iso.js +151 -0
- package/lib/api/services/engineering/mechanical/fasteners.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/fasteners.js +14 -0
- package/lib/api/services/engineering/mechanical/gears.d.ts +267 -0
- package/lib/api/services/engineering/mechanical/gears.js +318 -0
- package/lib/api/services/engineering/mechanical/index.d.ts +24 -0
- package/lib/api/services/engineering/mechanical/index.js +24 -0
- package/lib/api/services/engineering/mechanical/keys-ansi.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/keys-ansi.js +32 -0
- package/lib/api/services/engineering/mechanical/keys-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/keys-din.js +31 -0
- package/lib/api/services/engineering/mechanical/keys.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/keys.js +15 -0
- package/lib/api/services/engineering/mechanical/knurls-ansi.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/knurls-ansi.js +31 -0
- package/lib/api/services/engineering/mechanical/knurls-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/knurls-din.js +31 -0
- package/lib/api/services/engineering/mechanical/knurls.d.ts +14 -0
- package/lib/api/services/engineering/mechanical/knurls.js +15 -0
- package/lib/api/services/engineering/mechanical/mechanical.d.ts +29 -0
- package/lib/api/services/engineering/mechanical/mechanical.js +30 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-ansi.d.ts +43 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-ansi.js +51 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-din.d.ts +43 -0
- package/lib/api/services/engineering/mechanical/retaining-rings-din.js +51 -0
- package/lib/api/services/engineering/mechanical/retaining-rings.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/retaining-rings.js +14 -0
- package/lib/api/services/engineering/mechanical/splines-ansi.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/splines-ansi.js +32 -0
- package/lib/api/services/engineering/mechanical/splines-din.d.ts +26 -0
- package/lib/api/services/engineering/mechanical/splines-din.js +31 -0
- package/lib/api/services/engineering/mechanical/splines.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/splines.js +14 -0
- package/lib/api/services/engineering/mechanical/springs.d.ts +27 -0
- package/lib/api/services/engineering/mechanical/springs.js +31 -0
- package/lib/api/services/engineering/mechanical/threads-ansi.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/threads-ansi.js +48 -0
- package/lib/api/services/engineering/mechanical/threads-iso.d.ts +40 -0
- package/lib/api/services/engineering/mechanical/threads-iso.js +48 -0
- package/lib/api/services/engineering/mechanical/threads.d.ts +13 -0
- package/lib/api/services/engineering/mechanical/threads.js +14 -0
- package/lib/api/services/frame.js +3 -3
- package/lib/api/services/geometry-helper.js +8 -111
- package/lib/api/services/helpers/color/color-space.d.ts +2 -0
- package/lib/api/services/helpers/color/color-space.js +12 -0
- package/lib/api/services/helpers/{nurbs.d.ts → curves/nurbs.d.ts} +1 -1
- package/lib/api/services/helpers/{surface-triangulation.d.ts → curves/surface-triangulation.d.ts} +2 -2
- package/lib/api/services/helpers/{surface-triangulation.js → curves/surface-triangulation.js} +14 -8
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.d.ts +2 -1
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf-generator.js +19 -5
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +4 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +4 -0
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf.d.ts +1 -1
- package/lib/api/services/helpers/{dxf → files/dxf}/dxf.js +2 -2
- package/lib/api/services/helpers/files/glb.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/glb.constants.js +11 -0
- package/lib/api/services/helpers/files/glb.d.ts +1 -0
- package/lib/api/services/helpers/files/glb.js +69 -0
- package/lib/api/services/helpers/files/gzip.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/gzip.constants.js +11 -0
- package/lib/api/services/helpers/files/gzip.d.ts +2 -0
- package/lib/api/services/helpers/files/gzip.js +50 -0
- package/lib/api/services/helpers/{inflate.constants.d.ts → files/inflate.constants.d.ts} +2 -0
- package/lib/api/services/helpers/{inflate.constants.js → files/inflate.constants.js} +2 -0
- package/lib/api/services/helpers/{inflate.d.ts → files/inflate.d.ts} +2 -2
- package/lib/api/services/helpers/{inflate.js → files/inflate.js} +16 -7
- package/lib/api/services/helpers/{zip.constants.d.ts → files/zip.constants.d.ts} +8 -0
- package/lib/api/services/helpers/{zip.constants.js → files/zip.constants.js} +8 -0
- package/lib/api/services/helpers/files/zip.d.ts +8 -0
- package/lib/api/services/helpers/files/zip.js +226 -0
- package/lib/api/services/helpers/geometry/arcs.d.ts +9 -0
- package/lib/api/services/helpers/{arcs.js → geometry/arcs.js} +7 -0
- package/lib/api/services/helpers/{frame-axes.d.ts → geometry/frame-axes.d.ts} +8 -5
- package/lib/api/services/helpers/{frame-axes.js → geometry/frame-axes.js} +21 -9
- package/lib/api/services/helpers/geometry/lengths.constants.d.ts +4 -0
- package/lib/api/services/helpers/geometry/lengths.constants.js +3 -0
- package/lib/api/services/helpers/geometry/lengths.d.ts +7 -0
- package/lib/api/services/helpers/geometry/lengths.js +20 -0
- package/lib/api/services/helpers/geometry/matrices.constants.d.ts +8 -0
- package/lib/api/services/helpers/geometry/matrices.constants.js +7 -0
- package/lib/api/services/helpers/geometry/matrices.d.ts +17 -0
- package/lib/api/services/helpers/{matrices.js → geometry/matrices.js} +28 -17
- package/lib/api/services/helpers/{paths.d.ts → geometry/paths.d.ts} +2 -1
- package/lib/api/services/helpers/{paths.js → geometry/paths.js} +36 -30
- package/lib/api/services/helpers/{polygons.d.ts → geometry/polygons.d.ts} +1 -1
- package/lib/api/services/helpers/geometry/polygons.js +111 -0
- package/lib/api/services/helpers/geometry/scalars.d.ts +9 -0
- package/lib/api/services/helpers/geometry/scalars.js +34 -0
- package/lib/api/services/helpers/{triangulation.js → geometry/triangulation.js} +11 -6
- package/lib/api/services/helpers/geometry/vector-grid.d.ts +12 -0
- package/lib/api/services/helpers/geometry/vector-grid.js +149 -0
- package/lib/api/services/helpers/{vectors.d.ts → geometry/vectors.d.ts} +8 -1
- package/lib/api/services/helpers/geometry/vectors.js +43 -0
- package/lib/api/services/helpers/helper-types.d.ts +77 -0
- package/lib/api/services/helpers/mesh/mesh-normals.d.ts +21 -0
- package/lib/api/services/helpers/{mesh-normals.js → mesh/mesh-normals.js} +54 -65
- package/lib/api/services/helpers/mesh/mesh-orientation.d.ts +24 -0
- package/lib/api/services/helpers/mesh/mesh-orientation.js +104 -0
- package/lib/api/services/helpers/{mesh-primitives.d.ts → mesh/mesh-primitives.d.ts} +1 -1
- package/lib/api/services/helpers/{mesh-primitives.js → mesh/mesh-primitives.js} +6 -5
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.d.ts +7 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.constants.js +11 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.d.ts +11 -0
- package/lib/api/services/helpers/mesh/mesh-proximity.js +382 -0
- package/lib/api/services/index.d.ts +3 -0
- package/lib/api/services/index.js +3 -0
- package/lib/api/services/io.d.ts +1 -1
- package/lib/api/services/io.js +1 -1
- package/lib/api/services/line.js +2 -3
- package/lib/api/services/math.d.ts +47 -0
- package/lib/api/services/math.js +77 -10
- package/lib/api/services/mesh.d.ts +174 -2
- package/lib/api/services/mesh.js +305 -7
- package/lib/api/services/point.js +4 -10
- package/lib/api/services/polyline-types.d.ts +6 -0
- package/lib/api/services/polyline-types.js +1 -0
- package/lib/api/services/polyline.d.ts +163 -1
- package/lib/api/services/polyline.js +270 -13
- package/lib/api/services/recipes.d.ts +80 -0
- package/lib/api/services/recipes.js +107 -0
- package/lib/api/services/transforms.d.ts +74 -2
- package/lib/api/services/transforms.js +100 -3
- package/lib/api/services/vector.d.ts +4 -3
- package/lib/api/services/vector.js +14 -14
- package/lib/api/splines/ansi-splines.constants.d.ts +9 -0
- package/lib/api/splines/ansi-splines.constants.js +9 -0
- package/lib/api/splines/ansi-splines.d.ts +3 -0
- package/lib/api/splines/ansi-splines.js +28 -0
- package/lib/api/splines/din-splines.constants.d.ts +12 -0
- package/lib/api/splines/din-splines.constants.js +12 -0
- package/lib/api/splines/din-splines.d.ts +3 -0
- package/lib/api/splines/din-splines.js +38 -0
- package/lib/api/splines/spline-types.d.ts +32 -0
- package/lib/api/splines/spline-types.js +1 -0
- package/lib/api/splines/splines.constants.d.ts +1 -0
- package/lib/api/splines/splines.constants.js +1 -0
- package/lib/api/springs/spring-types.d.ts +26 -0
- package/lib/api/springs/spring-types.js +1 -0
- package/lib/api/springs/springs.constants.d.ts +9 -0
- package/lib/api/springs/springs.constants.js +9 -0
- package/lib/api/springs/springs.d.ts +2 -0
- package/lib/api/springs/springs.js +50 -0
- package/lib/api/threads/ansi-threads.constants.d.ts +6 -0
- package/lib/api/threads/ansi-threads.constants.js +27 -0
- package/lib/api/threads/ansi-threads.d.ts +4 -0
- package/lib/api/threads/ansi-threads.js +50 -0
- package/lib/api/threads/iso-threads.constants.d.ts +5 -0
- package/lib/api/threads/iso-threads.constants.js +20 -0
- package/lib/api/threads/iso-threads.d.ts +4 -0
- package/lib/api/threads/iso-threads.js +32 -0
- package/lib/api/threads/thread-profile.constants.d.ts +3 -0
- package/lib/api/threads/thread-profile.constants.js +3 -0
- package/lib/api/threads/thread-types.d.ts +66 -0
- package/lib/api/threads/thread-types.js +1 -0
- package/package.json +1 -1
- package/lib/api/recipes/index.d.ts +0 -4
- package/lib/api/recipes/index.js +0 -3
- package/lib/api/services/helpers/arcs.d.ts +0 -6
- package/lib/api/services/helpers/matrices.constants.d.ts +0 -2
- package/lib/api/services/helpers/matrices.constants.js +0 -2
- package/lib/api/services/helpers/matrices.d.ts +0 -25
- package/lib/api/services/helpers/mesh-normals.d.ts +0 -11
- package/lib/api/services/helpers/polygons.js +0 -59
- package/lib/api/services/helpers/vectors.js +0 -17
- package/lib/api/services/helpers/zip.d.ts +0 -4
- package/lib/api/services/helpers/zip.js +0 -89
- /package/lib/api/services/helpers/{nurbs.js → curves/nurbs.js} +0 -0
- /package/lib/api/services/helpers/{crc32.d.ts → files/crc32.d.ts} +0 -0
- /package/lib/api/services/helpers/{crc32.js → files/crc32.js} +0 -0
- /package/lib/api/services/helpers/{triangulation.d.ts → geometry/triangulation.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-measures.d.ts → mesh/mesh-measures.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-measures.js → mesh/mesh-measures.js} +0 -0
- /package/lib/api/services/helpers/{mesh-primitives.constants.d.ts → mesh/mesh-primitives.constants.d.ts} +0 -0
- /package/lib/api/services/helpers/{mesh-primitives.constants.js → mesh/mesh-primitives.constants.js} +0 -0
|
@@ -1,34 +1,36 @@
|
|
|
1
1
|
import { arcThroughThreePoints, pointsOnArc } from "./arcs";
|
|
2
|
-
import { add3, cross3, dot3, length3, scale3, subtract3 } from "./vectors";
|
|
2
|
+
import { add3, cross3, distance3, dot3, length3, scale3, subtract3 } from "./vectors";
|
|
3
|
+
import { axesAlong, unitOf } from "./frame-axes";
|
|
3
4
|
const STRAIGHT_SLACK = 1e-12;
|
|
4
5
|
const STRAIGHT_COSINE = 1 - STRAIGHT_SLACK;
|
|
5
6
|
const CORNERED_POINTS = 3;
|
|
6
7
|
const MAX_MITRE = 8;
|
|
7
8
|
const TINY_LENGTH = 1e-9;
|
|
8
9
|
const TINY_SQUARED = 1e-18;
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const MEETING_SLACK = 1e-9;
|
|
11
|
+
const ARC_ULPS = 16;
|
|
11
12
|
const reflected = (vector, across, squared) => subtract3(vector, scale3(across, (2 / squared) * dot3(across, vector)));
|
|
12
13
|
const square = (vector, to) => {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
return square(least, tangent);
|
|
14
|
+
const once = subtract3(vector, scale3(to, dot3(vector, to)));
|
|
15
|
+
if (!(length3(once) > TINY_LENGTH)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
const twice = subtract3(once, scale3(to, dot3(once, to)));
|
|
19
|
+
return scale3(twice, 1 / length3(twice));
|
|
20
20
|
};
|
|
21
|
+
const anyAcross = (tangent) => axesAlong([0, 0, 0], tangent).x;
|
|
22
|
+
export const pathLength3 = (points) => points.reduce((length, point, at) => (at === 0 ? length : length + length3(subtract3(point, points[at - 1]))), 0);
|
|
21
23
|
export const pathTangents = (points, start, end) => {
|
|
22
|
-
const directions = points.slice(1).map((point, at) =>
|
|
24
|
+
const directions = points.slice(1).map((point, at) => unitOf(subtract3(point, points[at])));
|
|
23
25
|
return points.map((_, at) => {
|
|
24
26
|
if (at === 0) {
|
|
25
|
-
return start === undefined ? directions[0] :
|
|
27
|
+
return start === undefined ? directions[0] : unitOf(start);
|
|
26
28
|
}
|
|
27
29
|
if (at === points.length - 1) {
|
|
28
|
-
return end === undefined ? directions[at - 1] :
|
|
30
|
+
return end === undefined ? directions[at - 1] : unitOf(end);
|
|
29
31
|
}
|
|
30
32
|
const sum = add3(directions[at - 1], directions[at]);
|
|
31
|
-
return length3(sum) > TINY_LENGTH ?
|
|
33
|
+
return length3(sum) > TINY_LENGTH ? unitOf(sum) : directions[at];
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
export const transportedAxes = (points, tangents, first) => {
|
|
@@ -53,8 +55,8 @@ export const sweepMatrices = (points, tangents, xAxes) => points.map((origin, at
|
|
|
53
55
|
let x = xAxes[at];
|
|
54
56
|
let y = cross3(z, x);
|
|
55
57
|
if (at > 0 && at < points.length - 1) {
|
|
56
|
-
const incoming =
|
|
57
|
-
const outgoing =
|
|
58
|
+
const incoming = unitOf(subtract3(origin, points[at - 1]));
|
|
59
|
+
const outgoing = unitOf(subtract3(points[at + 1], origin));
|
|
58
60
|
const cosine = dot3(incoming, outgoing);
|
|
59
61
|
const bend = square(subtract3(outgoing, incoming), z);
|
|
60
62
|
if (cosine < STRAIGHT_COSINE && bend !== undefined) {
|
|
@@ -70,27 +72,31 @@ export const roundedPath3 = (points, radius, segmentsFor) => {
|
|
|
70
72
|
return [...points];
|
|
71
73
|
}
|
|
72
74
|
const rounded = [points[0]];
|
|
75
|
+
const append = (point) => {
|
|
76
|
+
if (distance3(point, rounded[rounded.length - 1]) > 0) {
|
|
77
|
+
rounded.push(point);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
let previousReach = 0;
|
|
73
81
|
for (let at = 1; at < points.length - 1; at++) {
|
|
74
82
|
const corner = points[at];
|
|
75
83
|
const toPrevious = subtract3(points[at - 1], corner);
|
|
76
84
|
const toNext = subtract3(points[at + 1], corner);
|
|
77
|
-
const
|
|
78
|
-
const
|
|
85
|
+
const previousLength = length3(toPrevious);
|
|
86
|
+
const incoming = scale3(toPrevious, -1 / previousLength);
|
|
87
|
+
const outgoing = unitOf(toNext);
|
|
79
88
|
const cosine = dot3(incoming, outgoing);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
const turn = Math.acos(Math.max(-1, Math.min(1, cosine)));
|
|
85
|
-
const reach = Math.min(radius * Math.tan(turn / 2), length3(toPrevious) / 2, length3(toNext) / 2);
|
|
86
|
-
const start = add3(corner, scale3(incoming, -reach));
|
|
89
|
+
const turn = Math.atan2(length3(cross3(incoming, outgoing)), cosine);
|
|
90
|
+
const reach = Math.min(radius * Math.tan(turn / 2), previousLength / 2, length3(toNext) / 2);
|
|
91
|
+
const start = previousReach + reach >= previousLength * (1 - MEETING_SLACK) ? rounded[rounded.length - 1] : add3(corner, scale3(incoming, -reach));
|
|
87
92
|
const end = add3(corner, scale3(outgoing, reach));
|
|
88
|
-
const inward =
|
|
93
|
+
const inward = unitOf(subtract3(outgoing, incoming));
|
|
89
94
|
const fitted = reach / Math.tan(turn / 2);
|
|
90
|
-
const
|
|
91
|
-
const arc = arcThroughThreePoints(start,
|
|
92
|
-
|
|
95
|
+
const precision = ARC_ULPS * Number.EPSILON * Math.max(Math.abs(corner[0]), Math.abs(corner[1]), Math.abs(corner[2]), reach);
|
|
96
|
+
const arc = cosine < STRAIGHT_COSINE && inward !== undefined && fitted > precision ? arcThroughThreePoints(start, add3(corner, scale3(inward, fitted / Math.cos(turn / 2) - fitted)), end) : undefined;
|
|
97
|
+
(arc ? pointsOnArc(arc, start, end, segmentsFor(turn)) : [corner]).forEach(append);
|
|
98
|
+
previousReach = arc ? reach : 0;
|
|
93
99
|
}
|
|
94
|
-
|
|
100
|
+
append(points[points.length - 1]);
|
|
95
101
|
return rounded;
|
|
96
102
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as Inputs from "
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
2
|
type Point2 = Inputs.Base.Point2;
|
|
3
3
|
export declare const signedArea2: (points: readonly Point2[]) => number;
|
|
4
4
|
export declare const wound2: (points: readonly Point2[], counterClockwise: boolean) => Point2[];
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { InputError } from "../../../kernel-calls/errors";
|
|
2
|
+
import { add2, between2, cross2, distance2, dot2, leftOf2, length2, polar2, scale2, subtract2, unit2Of } from "./vectors";
|
|
3
|
+
const STRAIGHT_TOLERANCE = 1e-9;
|
|
4
|
+
const FIT_TOLERANCE = 1e-9;
|
|
5
|
+
const MESSAGE_DIGITS = 12;
|
|
6
|
+
const shown = (value) => Number(value.toPrecision(MESSAGE_DIGITS));
|
|
7
|
+
export const signedArea2 = (points) => {
|
|
8
|
+
const origin = points[0];
|
|
9
|
+
let twice = 0;
|
|
10
|
+
for (let at = 1; at + 1 < points.length; at++) {
|
|
11
|
+
twice += cross2(subtract2(points[at], origin), subtract2(points[at + 1], origin));
|
|
12
|
+
}
|
|
13
|
+
return twice / 2;
|
|
14
|
+
};
|
|
15
|
+
export const wound2 = (points, counterClockwise) => (signedArea2(points) > 0) === counterClockwise ? [...points] : [...points].reverse();
|
|
16
|
+
export const isInsidePolygon2 = (point, outline) => {
|
|
17
|
+
let inside = false;
|
|
18
|
+
for (let at = 0, previous = outline.length - 1; at < outline.length; previous = at++) {
|
|
19
|
+
const [x1, y1] = outline[at];
|
|
20
|
+
const [x2, y2] = outline[previous];
|
|
21
|
+
if ((y1 > point[1]) !== (y2 > point[1]) && point[0] < ((x2 - x1) * (point[1] - y1)) / (y2 - y1) + x1) {
|
|
22
|
+
inside = !inside;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return inside;
|
|
26
|
+
};
|
|
27
|
+
export const perimeter2 = (points) => points.reduce((sum, point, at) => sum + length2(subtract2(points[(at + 1) % points.length], point)), 0);
|
|
28
|
+
const cornerOf = (points, radii, at) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const corner = points[at];
|
|
31
|
+
const radius = (_a = radii[at]) !== null && _a !== void 0 ? _a : 0;
|
|
32
|
+
const toPrevious = unit2Of(subtract2(points[(at + points.length - 1) % points.length], corner));
|
|
33
|
+
const toNext = unit2Of(subtract2(points[(at + 1) % points.length], corner));
|
|
34
|
+
if (toPrevious === undefined || toNext === undefined) {
|
|
35
|
+
throw new Error(`The point at position ${at} lies on a point beside it, so the corner there has no sides`);
|
|
36
|
+
}
|
|
37
|
+
const half = Math.atan2(Math.abs(cross2(toPrevious, toNext)), dot2(toPrevious, toNext)) / 2;
|
|
38
|
+
if (!(radius > 0) || half < STRAIGHT_TOLERANCE || half > Math.PI / 2 - STRAIGHT_TOLERANCE || unit2Of(add2(toPrevious, toNext)) === undefined) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return { corner, radius, toPrevious, toNext, half, reach: radius / Math.tan(half) };
|
|
42
|
+
};
|
|
43
|
+
const requireFit = (points, corners) => {
|
|
44
|
+
corners.forEach((first, at) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const next = (at + 1) % points.length;
|
|
47
|
+
const second = corners[next];
|
|
48
|
+
const side = length2(subtract2(points[next], points[at]));
|
|
49
|
+
const need = ((_a = first === null || first === void 0 ? void 0 : first.reach) !== null && _a !== void 0 ? _a : 0) + ((_b = second === null || second === void 0 ? void 0 : second.reach) !== null && _b !== void 0 ? _b : 0);
|
|
50
|
+
if (need <= side * (1 + FIT_TOLERANCE)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const single = first === undefined || second === undefined;
|
|
54
|
+
throw new InputError(single
|
|
55
|
+
? `A corner radius of ${(first !== null && first !== void 0 ? first : second).radius} does not fit the edges beside its corner`
|
|
56
|
+
: `the arcs at the points at positions ${at} and ${next} need ${shown(need)} of the side between them, which is ${shown(side)} long`);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
const meetingOf = (points, corners, at) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
const next = (at + 1) % points.length;
|
|
62
|
+
const first = corners[at];
|
|
63
|
+
const second = corners[next];
|
|
64
|
+
const need = ((_a = first === null || first === void 0 ? void 0 : first.reach) !== null && _a !== void 0 ? _a : 0) + ((_b = second === null || second === void 0 ? void 0 : second.reach) !== null && _b !== void 0 ? _b : 0);
|
|
65
|
+
if (need < distance2(points[next], points[at]) * (1 - FIT_TOLERANCE)) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
if (first === undefined) {
|
|
69
|
+
return points[at];
|
|
70
|
+
}
|
|
71
|
+
return second === undefined ? points[next] : between2(points[at], points[next], first.reach / need);
|
|
72
|
+
};
|
|
73
|
+
export const roundedCorners2 = (points, radii, segmentsFor) => {
|
|
74
|
+
const corners = points.map((_, at) => cornerOf(points, radii, at));
|
|
75
|
+
requireFit(points, corners);
|
|
76
|
+
const meetings = points.map((_, at) => meetingOf(points, corners, at));
|
|
77
|
+
const rounded = [];
|
|
78
|
+
const append = (point) => {
|
|
79
|
+
if (rounded.length === 0 || distance2(point, rounded[rounded.length - 1]) > 0) {
|
|
80
|
+
rounded.push(point);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
points.forEach((point, at) => {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
const rounding = corners[at];
|
|
86
|
+
if (rounding === undefined) {
|
|
87
|
+
append(point);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const { corner, radius, toPrevious, toNext, reach } = rounding;
|
|
91
|
+
const start = (_a = meetings[(at + points.length - 1) % points.length]) !== null && _a !== void 0 ? _a : add2(corner, scale2(toPrevious, reach));
|
|
92
|
+
const end = (_b = meetings[at]) !== null && _b !== void 0 ? _b : add2(corner, scale2(toNext, reach));
|
|
93
|
+
const inward = scale2(leftOf2(toPrevious), cross2(toPrevious, toNext) < 0 ? -radius : radius);
|
|
94
|
+
const center = add2(add2(corner, scale2(toPrevious, reach)), inward);
|
|
95
|
+
const fromStart = subtract2(start, center);
|
|
96
|
+
const toEnd = subtract2(end, center);
|
|
97
|
+
const from = Math.atan2(fromStart[1], fromStart[0]);
|
|
98
|
+
let sweep = Math.atan2(toEnd[1], toEnd[0]) - from;
|
|
99
|
+
sweep -= Math.round(sweep / (2 * Math.PI)) * 2 * Math.PI;
|
|
100
|
+
const segments = segmentsFor(Math.abs(sweep));
|
|
101
|
+
append(start);
|
|
102
|
+
for (let step = 1; step < segments; step++) {
|
|
103
|
+
append(add2(center, polar2(radius, from + (sweep * step) / segments)));
|
|
104
|
+
}
|
|
105
|
+
append(end);
|
|
106
|
+
});
|
|
107
|
+
if (rounded.length > 1 && distance2(rounded[0], rounded[rounded.length - 1]) === 0) {
|
|
108
|
+
rounded.pop();
|
|
109
|
+
}
|
|
110
|
+
return rounded;
|
|
111
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const smoothstep: (value: number) => number;
|
|
2
|
+
export declare const roundedTo: (value: number, places: number) => number;
|
|
3
|
+
export declare const roundedToMillionths: (value: number) => number;
|
|
4
|
+
export declare const fractionOf: (value: number) => number;
|
|
5
|
+
export declare const radiansOf: (degrees: number) => number;
|
|
6
|
+
export declare const degreesOf: (radians: number) => number;
|
|
7
|
+
export declare const angleOfCosine: (cosine: number) => number;
|
|
8
|
+
export declare const interpolated: (start: number, end: number, share: number) => number;
|
|
9
|
+
export declare function fractionText(value: number, denominator: number): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const MILLIONTH_PLACES = 6;
|
|
2
|
+
const DECIMAL_BASE = 10;
|
|
3
|
+
const SMOOTHSTEP_RISE = 3;
|
|
4
|
+
const HALF_TURN_DEGREES = 180;
|
|
5
|
+
export const smoothstep = (value) => {
|
|
6
|
+
const t = Math.min(1, Math.max(0, value));
|
|
7
|
+
return t * t * (SMOOTHSTEP_RISE - 2 * t);
|
|
8
|
+
};
|
|
9
|
+
export const roundedTo = (value, places) => Math.round(value * Math.pow(DECIMAL_BASE, places)) / Math.pow(DECIMAL_BASE, places);
|
|
10
|
+
export const roundedToMillionths = (value) => roundedTo(value, MILLIONTH_PLACES);
|
|
11
|
+
export const fractionOf = (value) => value - Math.floor(value);
|
|
12
|
+
export const radiansOf = (degrees) => degrees * Math.PI / HALF_TURN_DEGREES;
|
|
13
|
+
export const degreesOf = (radians) => radians * HALF_TURN_DEGREES / Math.PI;
|
|
14
|
+
export const angleOfCosine = (cosine) => Math.acos(Math.min(1, Math.max(-1, cosine)));
|
|
15
|
+
export const interpolated = (start, end, share) => start + (end - start) * share;
|
|
16
|
+
function greatestCommonDivisor(first, second) {
|
|
17
|
+
let [a, b] = [first, second];
|
|
18
|
+
while (b !== 0) {
|
|
19
|
+
[a, b] = [b, a % b];
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
}
|
|
23
|
+
export function fractionText(value, denominator) {
|
|
24
|
+
const units = Math.round(Math.abs(value) * denominator);
|
|
25
|
+
const whole = Math.floor(units / denominator);
|
|
26
|
+
const rest = units - whole * denominator;
|
|
27
|
+
const common = greatestCommonDivisor(rest, denominator);
|
|
28
|
+
const sign = value < 0 && units > 0 ? "-" : "";
|
|
29
|
+
if (rest === 0) {
|
|
30
|
+
return `${sign}${String(whole)}`;
|
|
31
|
+
}
|
|
32
|
+
const part = `${String(rest / common)}/${String(denominator / common)}`;
|
|
33
|
+
return whole === 0 ? `${sign}${part}` : `${sign}${String(whole)}-${part}`;
|
|
34
|
+
}
|
|
@@ -36,9 +36,11 @@ function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
|
|
36
36
|
&& (bx - px) * (cy - py) >= (cx - px) * (by - py);
|
|
37
37
|
}
|
|
38
38
|
function signedArea(xs, ys) {
|
|
39
|
+
const x0 = xs[0];
|
|
40
|
+
const y0 = ys[0];
|
|
39
41
|
let twice = 0;
|
|
40
|
-
for (let at =
|
|
41
|
-
twice += xs[
|
|
42
|
+
for (let at = 1; at + 1 < xs.length; at++) {
|
|
43
|
+
twice += (xs[at] - x0) * (ys[at + 1] - y0) - (xs[at + 1] - x0) * (ys[at] - y0);
|
|
42
44
|
}
|
|
43
45
|
return twice / 2;
|
|
44
46
|
}
|
|
@@ -51,8 +53,7 @@ class Ring {
|
|
|
51
53
|
this.next = [];
|
|
52
54
|
this.triangles = [];
|
|
53
55
|
}
|
|
54
|
-
loop(vertices, xs, ys,
|
|
55
|
-
const reversed = (signedArea(xs, ys) > 0) !== counterClockwise;
|
|
56
|
+
loop(vertices, xs, ys, reversed) {
|
|
56
57
|
let last = NO_NODE;
|
|
57
58
|
for (let step = 0; step < vertices.length; step++) {
|
|
58
59
|
const at = reversed ? vertices.length - 1 - step : step;
|
|
@@ -289,7 +290,11 @@ export function triangulateFace(positions, loops) {
|
|
|
289
290
|
return fan(outer);
|
|
290
291
|
}
|
|
291
292
|
const ring = new Ring();
|
|
292
|
-
const start = ring.loop(outer, xs, ys,
|
|
293
|
-
const holeStarts = holes.map((hole) =>
|
|
293
|
+
const start = ring.loop(outer, xs, ys, false);
|
|
294
|
+
const holeStarts = holes.map((hole) => {
|
|
295
|
+
const holeXs = xsOf(hole);
|
|
296
|
+
const holeYs = ysOf(hole);
|
|
297
|
+
return ring.loop(hole, holeXs, holeYs, signedArea(holeXs, holeYs) > 0);
|
|
298
|
+
});
|
|
294
299
|
return ring.clip(ring.withHoles(start, holeStarts));
|
|
295
300
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { UniqueVectors } from "../helper-types";
|
|
2
|
+
/**
|
|
3
|
+
* Keeps the first of every group of vectors that agree within `tolerance` in each component, and
|
|
4
|
+
* says for every vector given which kept one it matched: the first in order, as a plain scan finds.
|
|
5
|
+
* Kept vectors are filed in a grid of cells a few tolerances wide, so a vector is compared only with
|
|
6
|
+
* those in the cells it could match. The grid only narrows the candidates; every one is still
|
|
7
|
+
* compared component by component. A vector the grid cannot place (a component not finite, a
|
|
8
|
+
* tolerance that is not positive and finite, a magnitude where the cell arithmetic stops being exact)
|
|
9
|
+
* is compared with every kept vector instead, and kept ones of that kind are held apart, where the
|
|
10
|
+
* grid path looks too.
|
|
11
|
+
*/
|
|
12
|
+
export declare const uniqueVectors: (vectors: readonly number[][], tolerance: number) => UniqueVectors;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const CELL_KEY_DIMENSIONS = 6;
|
|
2
|
+
const CELL_SIZE_IN_TOLERANCES = 8;
|
|
3
|
+
const CELL_PROBE_MARGIN_IN_TOLERANCES = 1.5;
|
|
4
|
+
const EXACT_CELL_BITS = 50;
|
|
5
|
+
const CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE = Math.pow(2, EXACT_CELL_BITS);
|
|
6
|
+
const CELL_HASH_WORD = 4294967296;
|
|
7
|
+
const HASH_SEED = 0x9E3779B1;
|
|
8
|
+
const HASH_MIX_LOW = 0x85EBCA6B;
|
|
9
|
+
const HASH_MIX_HIGH = 0xC2B2AE35;
|
|
10
|
+
const HASH_FOLD_SHIFT = 15;
|
|
11
|
+
const hashCells = (vectorLength, cells) => {
|
|
12
|
+
let hash = Math.imul(vectorLength + 1, HASH_SEED);
|
|
13
|
+
for (let i = 0; i < cells.length; i++) {
|
|
14
|
+
const cell = cells[i];
|
|
15
|
+
const lowWord = cell % CELL_HASH_WORD;
|
|
16
|
+
const highWord = (cell - lowWord) / CELL_HASH_WORD;
|
|
17
|
+
hash = Math.imul(hash ^ lowWord, HASH_MIX_LOW);
|
|
18
|
+
hash = Math.imul(hash ^ highWord, HASH_MIX_HIGH);
|
|
19
|
+
hash ^= hash >>> HASH_FOLD_SHIFT;
|
|
20
|
+
}
|
|
21
|
+
return hash;
|
|
22
|
+
};
|
|
23
|
+
const neverMatchesAnyVector = (vector, tolerance) => {
|
|
24
|
+
for (let i = 0; i < vector.length; i++) {
|
|
25
|
+
if (!Number.isFinite(vector[i])) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return vector.length > 0 && !(tolerance > 0);
|
|
30
|
+
};
|
|
31
|
+
const sameWithin = (vector, other, tolerance) => {
|
|
32
|
+
if (vector.length !== other.length) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
for (let i = 0; i < vector.length; i++) {
|
|
36
|
+
if (!(Math.abs(vector[i] - other[i]) < tolerance)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
};
|
|
42
|
+
const vectorCellRange = (vector, tolerance) => {
|
|
43
|
+
const keyDimensions = Math.min(vector.length, CELL_KEY_DIMENSIONS);
|
|
44
|
+
if (keyDimensions > 0 && !Number.isFinite(tolerance)) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
const cellSize = tolerance * CELL_SIZE_IN_TOLERANCES;
|
|
48
|
+
const probeMargin = tolerance * CELL_PROBE_MARGIN_IN_TOLERANCES;
|
|
49
|
+
const center = [];
|
|
50
|
+
const lowest = [];
|
|
51
|
+
const highest = [];
|
|
52
|
+
for (let i = 0; i < keyDimensions; i++) {
|
|
53
|
+
const component = vector[i];
|
|
54
|
+
if (Math.abs(component) / tolerance >= CELL_ARITHMETIC_SAFE_MULTIPLE_OF_TOLERANCE) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
const lowestCell = Math.floor((component - probeMargin) / cellSize);
|
|
58
|
+
const highestCell = Math.floor((component + probeMargin) / cellSize);
|
|
59
|
+
const cellsToProbe = highestCell - lowestCell + 1;
|
|
60
|
+
if (!Number.isInteger(lowestCell) || !Number.isInteger(highestCell) || cellsToProbe < 1 || cellsToProbe > 2) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
center.push(Math.floor(component / cellSize));
|
|
64
|
+
lowest.push(lowestCell);
|
|
65
|
+
highest.push(highestCell);
|
|
66
|
+
}
|
|
67
|
+
return { center, lowest, highest };
|
|
68
|
+
};
|
|
69
|
+
const firstMatchInCells = (keptByCell, vectorLength, cellRange, matches) => {
|
|
70
|
+
var _a;
|
|
71
|
+
const { lowest, highest } = cellRange;
|
|
72
|
+
const probe = lowest.slice();
|
|
73
|
+
let first;
|
|
74
|
+
for (;;) {
|
|
75
|
+
for (const index of (_a = keptByCell.get(hashCells(vectorLength, probe))) !== null && _a !== void 0 ? _a : []) {
|
|
76
|
+
if ((first === undefined || index < first) && matches(index)) {
|
|
77
|
+
first = index;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let dimension = probe.length - 1;
|
|
81
|
+
while (dimension >= 0 && probe[dimension] === highest[dimension]) {
|
|
82
|
+
probe[dimension] = lowest[dimension];
|
|
83
|
+
dimension--;
|
|
84
|
+
}
|
|
85
|
+
if (dimension < 0) {
|
|
86
|
+
return first;
|
|
87
|
+
}
|
|
88
|
+
probe[dimension] = probe[dimension] + 1;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const addToCell = (keptByCell, vectorLength, cellRange, index) => {
|
|
92
|
+
const cellKey = hashCells(vectorLength, cellRange.center);
|
|
93
|
+
const cell = keptByCell.get(cellKey);
|
|
94
|
+
if (cell === undefined) {
|
|
95
|
+
keptByCell.set(cellKey, [index]);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
cell.push(index);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* Keeps the first of every group of vectors that agree within `tolerance` in each component, and
|
|
103
|
+
* says for every vector given which kept one it matched: the first in order, as a plain scan finds.
|
|
104
|
+
* Kept vectors are filed in a grid of cells a few tolerances wide, so a vector is compared only with
|
|
105
|
+
* those in the cells it could match. The grid only narrows the candidates; every one is still
|
|
106
|
+
* compared component by component. A vector the grid cannot place (a component not finite, a
|
|
107
|
+
* tolerance that is not positive and finite, a magnitude where the cell arithmetic stops being exact)
|
|
108
|
+
* is compared with every kept vector instead, and kept ones of that kind are held apart, where the
|
|
109
|
+
* grid path looks too.
|
|
110
|
+
*/
|
|
111
|
+
export const uniqueVectors = (vectors, tolerance) => {
|
|
112
|
+
const kept = [];
|
|
113
|
+
const indexes = [];
|
|
114
|
+
const keptByCell = new Map();
|
|
115
|
+
const keptOutsideCells = [];
|
|
116
|
+
const keep = (vector) => kept.push(vector) - 1;
|
|
117
|
+
for (const vector of vectors) {
|
|
118
|
+
if (neverMatchesAnyVector(vector, tolerance)) {
|
|
119
|
+
indexes.push(keep(vector));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const matches = (index) => sameWithin(vector, kept[index], tolerance);
|
|
123
|
+
const cellRange = vectorCellRange(vector, tolerance);
|
|
124
|
+
if (cellRange === undefined) {
|
|
125
|
+
const found = kept.findIndex((_, index) => matches(index));
|
|
126
|
+
if (found >= 0) {
|
|
127
|
+
indexes.push(found);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
const index = keep(vector);
|
|
131
|
+
keptOutsideCells.push(index);
|
|
132
|
+
indexes.push(index);
|
|
133
|
+
}
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const inCells = firstMatchInCells(keptByCell, vector.length, cellRange, matches);
|
|
137
|
+
const outside = keptOutsideCells.find(matches);
|
|
138
|
+
const found = inCells === undefined ? outside : outside === undefined ? inCells : Math.min(inCells, outside);
|
|
139
|
+
if (found === undefined) {
|
|
140
|
+
const index = keep(vector);
|
|
141
|
+
addToCell(keptByCell, vector.length, cellRange, index);
|
|
142
|
+
indexes.push(index);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
indexes.push(found);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { kept, indexes };
|
|
149
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type * as Inputs from "
|
|
1
|
+
import type * as Inputs from "../../../inputs";
|
|
2
2
|
type Vec2 = Inputs.Base.Vector2;
|
|
3
3
|
type Vec3 = Inputs.Base.Vector3;
|
|
4
4
|
export declare const add2: (a: Vec2, b: Vec2) => Vec2;
|
|
@@ -7,12 +7,19 @@ export declare const scale2: (a: Vec2, factor: number) => Vec2;
|
|
|
7
7
|
export declare const dot2: (a: Vec2, b: Vec2) => number;
|
|
8
8
|
export declare const cross2: (a: Vec2, b: Vec2) => number;
|
|
9
9
|
export declare const length2: (a: Vec2) => number;
|
|
10
|
+
export declare const distance2: (a: Vec2, b: Vec2) => number;
|
|
10
11
|
export declare const leftOf2: (a: Vec2) => Vec2;
|
|
12
|
+
export declare const between2: (a: Vec2, b: Vec2, share: number) => Vec2;
|
|
13
|
+
export declare const polar2: (radius: number, angle: number) => Vec2;
|
|
14
|
+
export declare const rotated2: (a: Vec2, angle: number) => Vec2;
|
|
11
15
|
export declare const unit2Of: (a: Vec2) => Vec2 | undefined;
|
|
16
|
+
export declare const unitVectorOf: (vector: readonly number[]) => number[] | undefined;
|
|
12
17
|
export declare const add3: (a: Vec3, b: Vec3) => Vec3;
|
|
13
18
|
export declare const subtract3: (a: Vec3, b: Vec3) => Vec3;
|
|
14
19
|
export declare const scale3: (a: Vec3, factor: number) => Vec3;
|
|
15
20
|
export declare const dot3: (a: Vec3, b: Vec3) => number;
|
|
16
21
|
export declare const cross3: (a: Vec3, b: Vec3) => Vec3;
|
|
17
22
|
export declare const length3: (a: Vec3) => number;
|
|
23
|
+
export declare const between3: (a: Vec3, b: Vec3, share: number) => Vec3;
|
|
24
|
+
export declare const distance3: (a: Vec3, b: Vec3) => number;
|
|
18
25
|
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const PLANE_Z = 0;
|
|
2
|
+
export const add2 = (a, b) => [a[0] + b[0], a[1] + b[1]];
|
|
3
|
+
export const subtract2 = (a, b) => [a[0] - b[0], a[1] - b[1]];
|
|
4
|
+
export const scale2 = (a, factor) => [a[0] * factor, a[1] * factor];
|
|
5
|
+
export const dot2 = (a, b) => a[0] * b[0] + a[1] * b[1];
|
|
6
|
+
export const cross2 = (a, b) => a[0] * b[1] - a[1] * b[0];
|
|
7
|
+
export const length2 = (a) => Math.sqrt(a[0] * a[0] + a[1] * a[1]);
|
|
8
|
+
export const distance2 = (a, b) => length2(subtract2(a, b));
|
|
9
|
+
export const leftOf2 = (a) => [-a[1], a[0]];
|
|
10
|
+
export const between2 = (a, b, share) => [a[0] + (b[0] - a[0]) * share, a[1] + (b[1] - a[1]) * share];
|
|
11
|
+
export const polar2 = (radius, angle) => [radius * Math.cos(angle), radius * Math.sin(angle)];
|
|
12
|
+
export const rotated2 = (a, angle) => {
|
|
13
|
+
const cos = Math.cos(angle);
|
|
14
|
+
const sin = Math.sin(angle);
|
|
15
|
+
return [a[0] * cos - a[1] * sin, a[0] * sin + a[1] * cos];
|
|
16
|
+
};
|
|
17
|
+
export const unit2Of = (a) => {
|
|
18
|
+
const largest = Math.max(Math.abs(a[0]), Math.abs(a[1]));
|
|
19
|
+
if (!(largest > 0 && largest < Infinity)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const x = a[0] / largest;
|
|
23
|
+
const y = a[1] / largest;
|
|
24
|
+
const length = Math.hypot(x, y, PLANE_Z);
|
|
25
|
+
return [x / length, y / length];
|
|
26
|
+
};
|
|
27
|
+
export const unitVectorOf = (vector) => {
|
|
28
|
+
const largest = Math.max(...vector.map(Math.abs));
|
|
29
|
+
if (!(largest > 0 && largest < Infinity)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const scaled = vector.map(value => value / largest);
|
|
33
|
+
const length = Math.hypot(...scaled);
|
|
34
|
+
return scaled.map(value => value / length);
|
|
35
|
+
};
|
|
36
|
+
export const add3 = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
37
|
+
export const subtract3 = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
38
|
+
export const scale3 = (a, factor) => [a[0] * factor, a[1] * factor, a[2] * factor];
|
|
39
|
+
export const dot3 = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
40
|
+
export const cross3 = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
41
|
+
export const length3 = (a) => Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
|
|
42
|
+
export const between3 = (a, b, share) => [a[0] + (b[0] - a[0]) * share, a[1] + (b[1] - a[1]) * share, a[2] + (b[2] - a[2]) * share];
|
|
43
|
+
export const distance3 = (a, b) => length3(subtract3(a, b));
|
|
@@ -19,6 +19,26 @@ export interface HuffmanTable {
|
|
|
19
19
|
readonly entries: Int32Array;
|
|
20
20
|
readonly bits: number;
|
|
21
21
|
}
|
|
22
|
+
export interface ZipFile {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly data: Uint8Array;
|
|
25
|
+
}
|
|
26
|
+
export interface ZipStoredRecord<T> {
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly size: number;
|
|
29
|
+
readonly crc32: number;
|
|
30
|
+
readonly data: T;
|
|
31
|
+
}
|
|
32
|
+
export interface ZipHeaderWriter {
|
|
33
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
34
|
+
readonly u16: (value: number) => void;
|
|
35
|
+
readonly u32: (value: number) => void;
|
|
36
|
+
readonly raw: (value: Uint8Array) => void;
|
|
37
|
+
}
|
|
38
|
+
export interface DosDateTime {
|
|
39
|
+
readonly time: number;
|
|
40
|
+
readonly date: number;
|
|
41
|
+
}
|
|
22
42
|
export interface ZipEntry {
|
|
23
43
|
readonly name: string;
|
|
24
44
|
readonly method: number;
|
|
@@ -32,3 +52,60 @@ export interface RefinedSurfaceMesh {
|
|
|
32
52
|
readonly positions: Inputs.Base.Point3[];
|
|
33
53
|
readonly triangles: number[];
|
|
34
54
|
}
|
|
55
|
+
export interface WindingComponents {
|
|
56
|
+
readonly flips: Uint8Array;
|
|
57
|
+
readonly component: Int32Array;
|
|
58
|
+
readonly count: number;
|
|
59
|
+
}
|
|
60
|
+
export interface EdgeUses {
|
|
61
|
+
readonly uses: Map<number, number[]>;
|
|
62
|
+
readonly stride: number;
|
|
63
|
+
}
|
|
64
|
+
export interface TriangleTree {
|
|
65
|
+
readonly corners: Float64Array;
|
|
66
|
+
readonly boxes: Float64Array;
|
|
67
|
+
readonly starts: Uint32Array;
|
|
68
|
+
readonly counts: Uint32Array;
|
|
69
|
+
readonly lefts: Int32Array;
|
|
70
|
+
readonly rights: Int32Array;
|
|
71
|
+
}
|
|
72
|
+
export interface TreeBox {
|
|
73
|
+
readonly min: Inputs.Base.Point3;
|
|
74
|
+
readonly max: Inputs.Base.Point3;
|
|
75
|
+
}
|
|
76
|
+
export interface VectorCellRange {
|
|
77
|
+
readonly center: number[];
|
|
78
|
+
readonly lowest: number[];
|
|
79
|
+
readonly highest: number[];
|
|
80
|
+
}
|
|
81
|
+
export interface UniqueVectors {
|
|
82
|
+
readonly kept: number[][];
|
|
83
|
+
readonly indexes: number[];
|
|
84
|
+
}
|
|
85
|
+
export interface CreasedVertices {
|
|
86
|
+
readonly sources: Uint32Array;
|
|
87
|
+
readonly normals: Float64Array;
|
|
88
|
+
readonly indices: Uint32Array;
|
|
89
|
+
}
|
|
90
|
+
export interface RoundedCorner {
|
|
91
|
+
readonly corner: Inputs.Base.Point2;
|
|
92
|
+
readonly radius: number;
|
|
93
|
+
readonly toPrevious: Inputs.Base.Vector2;
|
|
94
|
+
readonly toNext: Inputs.Base.Vector2;
|
|
95
|
+
readonly half: number;
|
|
96
|
+
readonly reach: number;
|
|
97
|
+
}
|
|
98
|
+
export interface GltfNode {
|
|
99
|
+
readonly name?: string;
|
|
100
|
+
readonly scale?: readonly number[];
|
|
101
|
+
readonly children?: readonly number[];
|
|
102
|
+
}
|
|
103
|
+
export interface GltfScene {
|
|
104
|
+
readonly nodes?: readonly number[];
|
|
105
|
+
}
|
|
106
|
+
export interface GltfJson {
|
|
107
|
+
readonly scene?: number;
|
|
108
|
+
readonly scenes?: readonly GltfScene[];
|
|
109
|
+
readonly nodes?: readonly GltfNode[];
|
|
110
|
+
}
|
|
111
|
+
export type UnitOfLength = `${Inputs.Base.unitOfLengthEnum}`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CreasedMesh, CreasedVertices } from "../helper-types";
|
|
2
|
+
/**
|
|
3
|
+
* Smooth normals for a mesh that arrives without them: each point takes the sum of the normals of
|
|
4
|
+
* the triangles around it, each as long as twice its triangle's area, scaled to length 1, so a large
|
|
5
|
+
* triangle counts for more than a sliver and the mesh shades smoothly. A point that no triangle with
|
|
6
|
+
* an area touches keeps a normal of zero.
|
|
7
|
+
* @param positions - Flat array of vertex positions [x,y,z,x,y,z,...]
|
|
8
|
+
* @param indices - Triangle indices
|
|
9
|
+
* @returns Flat array of normals [nx,ny,nz,nx,ny,nz,...]
|
|
10
|
+
*/
|
|
11
|
+
export declare function computeVertexNormals(positions: ArrayLike<number>, indices: ArrayLike<number>): number[];
|
|
12
|
+
/**
|
|
13
|
+
* Normals that keep sharp edges sharp: around each point, a triangle's corner takes the
|
|
14
|
+
* area-weighted sum of the normals of the triangles around that point that turn from it by less than
|
|
15
|
+
* `minSharpAngle` degrees. Where corners of one point end up with different normals the point is
|
|
16
|
+
* split, so a cube keeps hard edges while a cylinder's side stays smooth. Gives, for each point made,
|
|
17
|
+
* the point it was made from, its normal, and the triangles over the points made; points no
|
|
18
|
+
* triangle uses are left out.
|
|
19
|
+
*/
|
|
20
|
+
export declare const creasedVertices: (positions: ArrayLike<number>, indices: ArrayLike<number>, minSharpAngle: number) => CreasedVertices;
|
|
21
|
+
export declare const creasedMesh: (positions: ArrayLike<number>, indices: ArrayLike<number>, minSharpAngle: number) => CreasedMesh;
|