@ac-kit/math-geometry 0.3.0 → 0.5.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/CHANGELOG.md +177 -0
- package/README.md +76 -5
- package/dist/_polygon3-cross.d.ts +23 -0
- package/dist/_polygon3-cross.d.ts.map +1 -0
- package/dist/_polygon3-cross.js +418 -0
- package/dist/_polygon3-cross.js.map +1 -0
- package/dist/_polyline-simplify.d.ts +11 -0
- package/dist/_polyline-simplify.d.ts.map +1 -0
- package/dist/_polyline-simplify.js +92 -0
- package/dist/_polyline-simplify.js.map +1 -0
- package/dist/_triangle3-cross.d.ts +66 -0
- package/dist/_triangle3-cross.d.ts.map +1 -0
- package/dist/_triangle3-cross.js +405 -0
- package/dist/_triangle3-cross.js.map +1 -0
- package/dist/convex-hull2.d.ts +26 -0
- package/dist/convex-hull2.d.ts.map +1 -0
- package/dist/convex-hull2.js +88 -0
- package/dist/convex-hull2.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/line2.d.ts +4 -0
- package/dist/line2.d.ts.map +1 -1
- package/dist/line2.js +26 -5
- package/dist/line2.js.map +1 -1
- package/dist/mesh/_index-kernels-u16.d.ts +46 -11
- package/dist/mesh/_index-kernels-u16.d.ts.map +1 -1
- package/dist/mesh/_index-kernels-u16.js +1442 -132
- package/dist/mesh/_index-kernels-u16.js.map +1 -1
- package/dist/mesh/_index-kernels-u32.d.ts +46 -11
- package/dist/mesh/_index-kernels-u32.d.ts.map +1 -1
- package/dist/mesh/_index-kernels-u32.js +1442 -132
- package/dist/mesh/_index-kernels-u32.js.map +1 -1
- package/dist/mesh/mesh3-kernels.d.ts +104 -20
- package/dist/mesh/mesh3-kernels.d.ts.map +1 -1
- package/dist/mesh/mesh3-kernels.js +123 -25
- package/dist/mesh/mesh3-kernels.js.map +1 -1
- package/dist/plane3.d.ts +4 -3
- package/dist/plane3.d.ts.map +1 -1
- package/dist/plane3.js +18 -35
- package/dist/plane3.js.map +1 -1
- package/dist/polygon2.d.ts +76 -4
- package/dist/polygon2.d.ts.map +1 -1
- package/dist/polygon2.js +366 -7
- package/dist/polygon2.js.map +1 -1
- package/dist/polygon3.d.ts +19 -3
- package/dist/polygon3.d.ts.map +1 -1
- package/dist/polygon3.js +40 -16
- package/dist/polygon3.js.map +1 -1
- package/dist/polyline2.d.ts +20 -0
- package/dist/polyline2.d.ts.map +1 -1
- package/dist/polyline2.js +25 -0
- package/dist/polyline2.js.map +1 -1
- package/dist/polyline3.d.ts +17 -0
- package/dist/polyline3.d.ts.map +1 -1
- package/dist/polyline3.js +22 -0
- package/dist/polyline3.js.map +1 -1
- package/dist/predicates2.d.ts +51 -0
- package/dist/predicates2.d.ts.map +1 -0
- package/dist/predicates2.js +172 -0
- package/dist/predicates2.js.map +1 -0
- package/dist/quadtree.d.ts +40 -23
- package/dist/quadtree.d.ts.map +1 -1
- package/dist/quadtree.js +196 -119
- package/dist/quadtree.js.map +1 -1
- package/dist/segment2.d.ts +6 -1
- package/dist/segment2.d.ts.map +1 -1
- package/dist/segment2.js +20 -4
- package/dist/segment2.js.map +1 -1
- package/dist/triangle3.d.ts +20 -1
- package/dist/triangle3.d.ts.map +1 -1
- package/dist/triangle3.js +38 -18
- package/dist/triangle3.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,182 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5c203e7: `polygon2GroupRings(coordinates, ringStarts)` groups the rings of a non-zero
|
|
8
|
+
fill into polygons for `polygon2Triangulate`: each counter-clockwise ring is an
|
|
9
|
+
outer ring, each clockwise ring a hole of the smallest outer ring holding it
|
|
10
|
+
(rings of no area, and holes no outer ring holds, are left out).
|
|
11
|
+
- 5c203e7: Added `Mesh3MeasureOptions` (`rounding?: "correct" | "faithful"`) to
|
|
12
|
+
`mesh3Volume` and `mesh3Centroid`. `"correct"` (the default) is rounded once
|
|
13
|
+
from the exact value, the same in every face order, and `mesh3Volume` now
|
|
14
|
+
computes it about 1.5× faster. `"faithful"` promises a result within one unit
|
|
15
|
+
in the last place of the `"correct"` one (equal or adjacent doubles,
|
|
16
|
+
subnormals included), proven by a rigorous error bound, with no allocation and
|
|
17
|
+
the same overflow guarantees; it may differ by an ulp between face orders.
|
|
18
|
+
`mesh3Centroid` reaches it in one plain compensated pass, about 1.7× a plain
|
|
19
|
+
double centroid, on a mesh far from the origin beside its size (about 2⁷ times
|
|
20
|
+
its extent); nearer, the bound cannot prove one ulp and the `"correct"`
|
|
21
|
+
computation runs after that pass. `mesh3Volume` with `"faithful"` returns the
|
|
22
|
+
`"correct"` result at its cost: no uniform error bound on a plain pass can
|
|
23
|
+
prove one ulp of a volume.
|
|
24
|
+
|
|
25
|
+
`mesh3Volume` is now the exact volume rounded once: six times it is taken from
|
|
26
|
+
the exact coordinates (it rounded each edge difference, which could erase a
|
|
27
|
+
volume and made a face's term depend on the rotation of its corners), then
|
|
28
|
+
divided by six before its one rounding (it rounded six times the volume first:
|
|
29
|
+
`Infinity` for a volume of a third of `Number.MAX_VALUE`, 0 for one above half
|
|
30
|
+
of `Number.MIN_VALUE`). The default `mesh3Centroid` is now correctly rounded
|
|
31
|
+
for its area weights (it was within a few ulps of the mesh's extent): a finite
|
|
32
|
+
centroid at `Number.MAX_VALUE` no longer overflows to `Infinity`, and a
|
|
33
|
+
centroid that cancels against the bounding box's corner keeps its last bits.
|
|
34
|
+
|
|
35
|
+
`mesh3VolumeInto(out, index, positions, indices, options?)` writes the volume
|
|
36
|
+
into an array: it and `mesh3Centroid` allocate nothing on any path, even where
|
|
37
|
+
the engine inlines nothing. `mesh3Volume` allocates nothing under normal
|
|
38
|
+
optimisation, but its returned double is boxed by a call the engine does not
|
|
39
|
+
inline.
|
|
40
|
+
|
|
41
|
+
A volume that rounds to zero keeps its sign (−0 for an inward mesh); an
|
|
42
|
+
exactly zero one is +0. A centroid within a hair of half of
|
|
43
|
+
`Number.MIN_VALUE` is rounded from its exact residual.
|
|
44
|
+
- 5c203e7: `polyline2Simplify(coordinates, tolerance)` and `polyline3Simplify` simplify a
|
|
45
|
+
chain by Ramer–Douglas–Peucker (distances to segments, ends kept), returning
|
|
46
|
+
the kept vertices; `polyline2SimplifyIndices` and `polyline3SimplifyIndices`
|
|
47
|
+
return their positions instead. A `RangeError` for a negative or `NaN`
|
|
48
|
+
tolerance.
|
|
49
|
+
- 5c203e7: - `orient2(ax, ay, bx, by, cx, cy)` and `inCircle2(ax, ay, bx, by, cx, cy, dx,
|
|
50
|
+
dy)` are exact orientation and in-circle predicates: `1`, `-1` or `0` for
|
|
51
|
+
every finite input (`NaN` otherwise), the rounded determinant accepted only
|
|
52
|
+
under Shewchuk's error bound and evaluated exactly otherwise; the common case
|
|
53
|
+
allocates nothing.
|
|
54
|
+
- `convexHull2(coordinates)` returns the convex hull of interleaved `x, y`
|
|
55
|
+
points as a `Uint32Array` of their indices, counter-clockwise from the
|
|
56
|
+
lexicographically smallest point, without collinear vertices or duplicates;
|
|
57
|
+
a `RangeError` for an odd length or a non-finite coordinate.
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- Updated dependencies [5c203e7]
|
|
62
|
+
- Updated dependencies [5c203e7]
|
|
63
|
+
- Updated dependencies [5c203e7]
|
|
64
|
+
- Updated dependencies [5c203e7]
|
|
65
|
+
- Updated dependencies [5c203e7]
|
|
66
|
+
- Updated dependencies [5c203e7]
|
|
67
|
+
- Updated dependencies [5c203e7]
|
|
68
|
+
- Updated dependencies [5c203e7]
|
|
69
|
+
- Updated dependencies [5c203e7]
|
|
70
|
+
- Updated dependencies [5c203e7]
|
|
71
|
+
- Updated dependencies [5c203e7]
|
|
72
|
+
- @ac-kit/core@0.14.0
|
|
73
|
+
- @ac-kit/math-linear@0.5.0
|
|
74
|
+
- @ac-kit/math-scalar@0.5.0
|
|
75
|
+
|
|
76
|
+
## 0.4.0
|
|
77
|
+
|
|
78
|
+
### Minor Changes
|
|
79
|
+
|
|
80
|
+
- 0b4fe43: `polygon2SignedArea(coordinates, vertexCount?)` and
|
|
81
|
+
`polygon2Area(coordinates, vertexCount?)` measure the polygon of the first
|
|
82
|
+
`vertexCount` vertices when a count is given, so a polygon can live at the start
|
|
83
|
+
of a longer working buffer; a count that is not an integer from 0 to
|
|
84
|
+
`coordinates.length / 2` throws a `RangeError`. Without it they read every
|
|
85
|
+
vertex, as before.
|
|
86
|
+
|
|
87
|
+
`polygon2ClipHalfPlane(out, coordinates, vertexCount, halfPlanes, index?)`
|
|
88
|
+
writes the polygon cut to the half-plane `normal · p ≤ limit`, read as
|
|
89
|
+
`(normalX, normalY, limit)` from `halfPlanes[index]`, into `out` and
|
|
90
|
+
returns its vertex count (Sutherland–Hodgman): the convex intersection, at most
|
|
91
|
+
`vertexCount + 1` vertices, for a convex polygon; pieces of the same area joined
|
|
92
|
+
by zero-width bridges, at most `⌊3 · vertexCount / 2⌋` vertices, for a concave
|
|
93
|
+
one. Vertices on the line are kept; an infinite limit (or a zero normal) keeps
|
|
94
|
+
everything or nothing, and the half-plane is scaled by a power of two before
|
|
95
|
+
any side is evaluated, so every finite input gives finite vertices; a vertex
|
|
96
|
+
too near the line for the scaled evaluation is placed by the exact sign of its
|
|
97
|
+
side, so which vertices are kept is exact. No double
|
|
98
|
+
crosses the call, so it allocates nothing whether or not the engine inlines it;
|
|
99
|
+
it throws a `RangeError` before
|
|
100
|
+
writing when `out` is shorter than `2 · ⌊3 · vertexCount / 2⌋` entries or
|
|
101
|
+
shares memory with the vertices read, the count or index is out of range, the
|
|
102
|
+
normal is not finite or `limit` is `NaN`.
|
|
103
|
+
|
|
104
|
+
`line2IntersectLine2` now allocates nothing for coordinate-sized lines (its
|
|
105
|
+
determinants go through `diffOfProductsInPlace`), and `segment2ClosestPoint`
|
|
106
|
+
allocates nothing whether or not the engine inlines it; their results are
|
|
107
|
+
unchanged.
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- 0b4fe43: The mesh kernels stay finite and independent of order over the whole binary64
|
|
112
|
+
range. `triangle3Normal`, `mesh3FaceNormals` and `mesh3VertexNormals` take the
|
|
113
|
+
exact cross product's direction for any finite corners: the unit normal within
|
|
114
|
+
2^−48 per component (normwise, about 3.4 · 2^−53 at worst in testing), so a
|
|
115
|
+
component smaller than that beside the largest may round to a zero of either
|
|
116
|
+
sign while every larger one has the exact sign; +0 where the exact component
|
|
117
|
+
is 0, and the zero
|
|
118
|
+
vector exactly for a degenerate triangle (collinear or repeated corners) — a
|
|
119
|
+
triangle with edges of `Number.MAX_VALUE` and `Number.MIN_VALUE` gets its
|
|
120
|
+
normal; `plane3FromPoints` takes the same normal. `mesh3VertexNormals` takes faces of any size, spanning
|
|
121
|
+
±`Number.MAX_VALUE` included. `mesh3SurfaceArea` scales each face's edges per
|
|
122
|
+
axis by powers of two, so no square overflows or underflows, and sums the faces
|
|
123
|
+
exactly. `mesh3Volume` and `mesh3Centroid` are exact sums over face-local edges,
|
|
124
|
+
relative to a corner of the mesh's bounding box, each axis scaled by its own
|
|
125
|
+
power of two: the result is the same in every face or merge order, and nothing
|
|
126
|
+
overflows for a mesh however thin, wide or small, anywhere up to
|
|
127
|
+
±`Number.MAX_VALUE`. `mesh3TriangleDepths` is finite next to ±`Number.MAX_VALUE`
|
|
128
|
+
wherever `z / w` is.
|
|
129
|
+
- 0b4fe43: The quadtree stores its nodes in typed columns reused across calls, so once
|
|
130
|
+
warmed up `assign`, `visit`, `visitAfter`, `find` and `forEachInBox` allocate
|
|
131
|
+
nothing, and not only the traversal per node.
|
|
132
|
+
- 0b4fe43: `polygon3Normal` takes the exact Newell vector's direction for any finite
|
|
133
|
+
coordinates, with `triangle3Normal`'s guarantee: each component within 2^−48 of
|
|
134
|
+
the exact unit normal's (normwise), +0 where the exact component is 0, the exact
|
|
135
|
+
sign wherever that bound cannot reach 0, and the zero vector exactly when the
|
|
136
|
+
vector is zero. A polygon of `Number.MAX_VALUE` or `Number.MIN_VALUE` size, or
|
|
137
|
+
one whose fan triangles cancel, gets its normal where it used to get `NaN` or
|
|
138
|
+
the zero vector; a coordinate that is not finite gives `NaN`s.
|
|
139
|
+
`mesh3VertexNormals` gives each vertex the direction of the exact sum of its
|
|
140
|
+
faces' cross products, within 2^−48 per component: opposite faces that cancel no
|
|
141
|
+
longer take a far smaller face's normal with them (two faces of 2^2000 beside
|
|
142
|
+
one of `Number.MIN_VALUE²`, or unit faces beside one of 2^−80), and a vertex
|
|
143
|
+
whose faces cancel exactly, as on a double-sided mesh, gets the zero vector
|
|
144
|
+
exactly. Neither allocates once its scratch has grown to the largest input.
|
|
145
|
+
- Updated dependencies [0b4fe43]
|
|
146
|
+
- Updated dependencies [0b4fe43]
|
|
147
|
+
- Updated dependencies [0b4fe43]
|
|
148
|
+
- Updated dependencies [0b4fe43]
|
|
149
|
+
- Updated dependencies [0b4fe43]
|
|
150
|
+
- Updated dependencies [0b4fe43]
|
|
151
|
+
- Updated dependencies [0b4fe43]
|
|
152
|
+
- Updated dependencies [0b4fe43]
|
|
153
|
+
- Updated dependencies [0b4fe43]
|
|
154
|
+
- Updated dependencies [0b4fe43]
|
|
155
|
+
- Updated dependencies [0b4fe43]
|
|
156
|
+
- Updated dependencies [0b4fe43]
|
|
157
|
+
- Updated dependencies [0b4fe43]
|
|
158
|
+
- Updated dependencies [0b4fe43]
|
|
159
|
+
- Updated dependencies [0b4fe43]
|
|
160
|
+
- Updated dependencies [0b4fe43]
|
|
161
|
+
- Updated dependencies [0b4fe43]
|
|
162
|
+
- Updated dependencies [0b4fe43]
|
|
163
|
+
- Updated dependencies [0b4fe43]
|
|
164
|
+
- Updated dependencies [0b4fe43]
|
|
165
|
+
- Updated dependencies [0b4fe43]
|
|
166
|
+
- Updated dependencies [0b4fe43]
|
|
167
|
+
- Updated dependencies [0b4fe43]
|
|
168
|
+
- Updated dependencies [0b4fe43]
|
|
169
|
+
- Updated dependencies [0b4fe43]
|
|
170
|
+
- Updated dependencies [0b4fe43]
|
|
171
|
+
- Updated dependencies [0b4fe43]
|
|
172
|
+
- Updated dependencies [0b4fe43]
|
|
173
|
+
- Updated dependencies [0b4fe43]
|
|
174
|
+
- Updated dependencies [0b4fe43]
|
|
175
|
+
- Updated dependencies [0b4fe43]
|
|
176
|
+
- @ac-kit/core@0.13.0
|
|
177
|
+
- @ac-kit/math-linear@0.4.0
|
|
178
|
+
- @ac-kit/math-scalar@0.4.0
|
|
179
|
+
|
|
3
180
|
## 0.3.0
|
|
4
181
|
|
|
5
182
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ projections are not here, the sphere is abstract.
|
|
|
24
24
|
| Round shapes | `Circle2`, `Sphere3` |
|
|
25
25
|
| Linear | `Segment2/3`, `Ray2/3`, `Line2/3`, `Plane3`, `Frustum3` (six inward planes) |
|
|
26
26
|
| Triangles | `Triangle2`, `Triangle3` |
|
|
27
|
-
| Chains | polygons (rings, holes) and polylines, packed in a `Float64Array`
|
|
27
|
+
| Chains | polygons (rings, holes) and polylines, packed in a `Float64Array`; `polyline2Simplify`/`polyline3Simplify` (Ramer–Douglas–Peucker) |
|
|
28
|
+
| Predicates | `orient2`, `inCircle2` (exact signs), `convexHull2` (indices, counter-clockwise) |
|
|
28
29
|
| Coordinates | `PolarCoords`, `SphericalCoords`, `CylindricalCoords`, `LongitudeLatitude`, `HorizontalCoords` |
|
|
29
30
|
| Sphere | bearing, destination, small circles, arcs, `sphericalArcClipToCap` and friends |
|
|
30
31
|
| Meshes | `Mesh3`, packed positions and indices, kernels and generators (`mesh3Box`, `mesh3IcoSphere`, …) |
|
|
@@ -195,7 +196,33 @@ implicitly closed, holes given by the vertex index where each hole ring starts
|
|
|
195
196
|
(earcut's convention). `polygon2ContainsXy` takes a fill rule (`"nonzero"` or
|
|
196
197
|
`"evenodd"`, the Canvas and SVG spellings) and `polygon2Triangulate` clips ears
|
|
197
198
|
with the holes bridged to the outer ring, writing triangle indices into a
|
|
198
|
-
`Uint32Array` (`3·(n + 2h − 2)` entries).
|
|
199
|
+
`Uint32Array` (`3·(n + 2h − 2)` entries). `polygon2GroupRings` sorts the rings
|
|
200
|
+
of a non-zero fill (counter-clockwise outer rings, clockwise holes, as map
|
|
201
|
+
projections cut them) into outer rings and the holes each holds, ready for the
|
|
202
|
+
triangulation.
|
|
203
|
+
|
|
204
|
+
`polygon2SignedArea` and `polygon2Area` take an optional vertex count, for a
|
|
205
|
+
polygon held at the start of a longer working buffer, and
|
|
206
|
+
`polygon2ClipHalfPlane` cuts the first `n` vertices of one buffer to a
|
|
207
|
+
half-plane `(normalX, normalY, limit)` read from a third (Sutherland–Hodgman;
|
|
208
|
+
at most `n + 1` vertices for a convex polygon, `⌊3n/2⌋` for a concave one,
|
|
209
|
+
whose pieces stay joined by zero-width bridges of no area). No double crosses
|
|
210
|
+
the clip's call, so clipping twice and measuring, as area-coverage
|
|
211
|
+
antialiasing does per pixel, allocates nothing; the clip refuses an `out` that
|
|
212
|
+
shares memory with its input, since it cannot work in place.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { polygon2Area, polygon2ClipHalfPlane } from "@ac-kit/math-geometry";
|
|
216
|
+
|
|
217
|
+
// The area of a pixel square left of x = 0.3 and below y = 0.2.
|
|
218
|
+
const pixel = new Float64Array([0, 0, 1, 0, 1, 1, 0, 1]);
|
|
219
|
+
const planes = new Float64Array([1, 0, 0.3, 0, 1, 0.2]);
|
|
220
|
+
const half = new Float64Array(12);
|
|
221
|
+
const quarter = new Float64Array(16);
|
|
222
|
+
const halfCount = polygon2ClipHalfPlane(half, pixel, 4, planes, 0);
|
|
223
|
+
const count = polygon2ClipHalfPlane(quarter, half, halfCount, planes, 3);
|
|
224
|
+
polygon2Area(quarter, count); // ≈ 0.06
|
|
225
|
+
```
|
|
199
226
|
|
|
200
227
|
```ts
|
|
201
228
|
import { polygon2Area, polygon2Triangulate } from "@ac-kit/math-geometry";
|
|
@@ -207,6 +234,26 @@ const indices = new Uint32Array(3 * (8 + 2 - 2));
|
|
|
207
234
|
const triangles = polygon2Triangulate(indices, ring, holes); // 8
|
|
208
235
|
```
|
|
209
236
|
|
|
237
|
+
## Exact predicates and convex hulls
|
|
238
|
+
|
|
239
|
+
`orient2(ax, ay, bx, by, cx, cy)` (left, right or collinear) and
|
|
240
|
+
`inCircle2(ax, ay, bx, by, cx, cy, dx, dy)` (inside, outside or on the circle
|
|
241
|
+
through three counter-clockwise points) return `1`, `-1` or `0`, exactly, for
|
|
242
|
+
every finite input: the rounded determinant is accepted only when Shewchuk's
|
|
243
|
+
error bound proves its sign, and is otherwise evaluated in exact integer
|
|
244
|
+
arithmetic. A plain sign test can answer differently for nearly collinear
|
|
245
|
+
points depending on the order it is asked in, which is what breaks hulls and
|
|
246
|
+
triangulations. `convexHull2(coordinates)` is Andrew's monotone chain on
|
|
247
|
+
`orient2`: the indices of the hull's vertices, counter-clockwise from the
|
|
248
|
+
lexicographically smallest point, with no collinear vertex.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
import { convexHull2, orient2 } from "@ac-kit/math-geometry";
|
|
252
|
+
|
|
253
|
+
orient2(0.5, 0.5 + 2 ** -53, 12, 12, 24, 24); // 1 — the plain formula gives 0
|
|
254
|
+
convexHull2(new Float64Array([0, 0, 2, 0, 1, 1, 2, 2, 0, 2])); // Uint32Array [0, 1, 3, 4]
|
|
255
|
+
```
|
|
256
|
+
|
|
210
257
|
## Coordinates
|
|
211
258
|
|
|
212
259
|
Records are tuples; the system (up axis, local axes) is in the function name,
|
|
@@ -290,8 +337,30 @@ meshes with every attribute, and `mesh3Merge` joins several into one. The kernel
|
|
|
290
337
|
`mesh3ReorderTriangles`) write into an `out` you provide, which must not share
|
|
291
338
|
memory with an input (`RangeError`). They check lengths once
|
|
292
339
|
and no index: an index past the last vertex reads `NaN`, which the checked layer
|
|
293
|
-
catches before an upload. A vertex no triangle uses, and a
|
|
294
|
-
|
|
340
|
+
catches before an upload. A vertex no triangle uses, and a degenerate face (an
|
|
341
|
+
exactly zero cross product: collinear or repeated corners), get the zero
|
|
342
|
+
normal; every other face gets a unit normal with the exact cross product's
|
|
343
|
+
direction, within 2^−48 per component (normwise, about 3.4 · 2^−53 at worst
|
|
344
|
+
in testing): a component smaller than that beside the largest may round to a
|
|
345
|
+
zero of either sign, an exactly zero one is +0. That holds however long, thin,
|
|
346
|
+
small or far out the face is. A vertex normal is the direction of the exact sum
|
|
347
|
+
of its faces' cross products, within 2^−48 per component (normwise), the zero
|
|
348
|
+
vector where that sum is zero: each sum carries a running error bound, and a
|
|
349
|
+
vertex it does not settle (faces that cancel, however large beside the ones
|
|
350
|
+
left) is summed again exactly. `polygon3Normal` gives a polygon's normal with
|
|
351
|
+
the same guarantee as a face's, from the exact Newell vector. The volume is
|
|
352
|
+
signed, positive when the faces point outward.
|
|
353
|
+
The area, volume and centroid sum exactly, at any magnitude, so they give the
|
|
354
|
+
same result in every face order and never overflow on the way, for a mesh
|
|
355
|
+
however thin, wide or small and anywhere up to ±`Number.MAX_VALUE`; the volume
|
|
356
|
+
(from the exact coordinates, the same for each rotation of a face's corners)
|
|
357
|
+
and the centroid are rounded once (the centroid correctly for its area
|
|
358
|
+
weights). With `{ rounding: "faithful" }` they may return a result within one
|
|
359
|
+
unit in the last place instead, which the centroid proves from one plain pass
|
|
360
|
+
on a mesh far from the origin beside its size. `mesh3VolumeInto` writes the
|
|
361
|
+
volume into an array and, like `mesh3Centroid`, allocates nothing even where
|
|
362
|
+
the engine inlines nothing; `mesh3Volume` allocates nothing under normal
|
|
363
|
+
optimisation, but a call that is not inlined boxes the number it returns.
|
|
295
364
|
|
|
296
365
|
```ts
|
|
297
366
|
import { mesh3Heightfield, mesh3VertexNormals } from "@ac-kit/math-geometry";
|
|
@@ -329,7 +398,9 @@ index.tryInsert(box2FromXywh(box2Create(), 100, 44, 60, 14), 2); // false: it ov
|
|
|
329
398
|
## Nearest point and range queries
|
|
330
399
|
|
|
331
400
|
`Quadtree` indexes 2-D points by integer id over a `Float64Array` of x, y
|
|
332
|
-
pairs, with d3-quadtree's cells and visit order at every ordinary scale.
|
|
401
|
+
pairs, with d3-quadtree's cells and visit order at every ordinary scale. Its
|
|
402
|
+
storage is typed columns reused across calls, so once warmed up `assign`,
|
|
403
|
+
`visit`, `visitAfter`, `find` and `forEachInBox` allocate nothing. Stored
|
|
333
404
|
coordinates (construction, `assign`, `add`) must be finite with |x|, |y| ≤
|
|
334
405
|
1e150; larger or non-finite values throw `RangeError` before the tree changes.
|
|
335
406
|
Queries never throw: `find` returns −1 for a NaN, infinite or beyond-±1e150
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes Newell's vector of the ring of the first `count` (at least 3) vertices
|
|
3
|
+
* of `coordinates` into `out` as `[x, y, z, k]`, the vector being `(x, y, z) ·
|
|
4
|
+
* 2^k`, with `triangle3Cross_`'s guarantees: every component within 2^−49 of
|
|
5
|
+
* the largest component of the exact vector, for any finite coordinates; `[0,
|
|
6
|
+
* 0, 0, 0]` exactly when the exact vector is zero, a component +0 where the
|
|
7
|
+
* exact one is 0, and one with the exact one's sign wherever that bound cannot
|
|
8
|
+
* reach 0; k = 0 when the largest component lies in `[2^−400, 2^402)`,
|
|
9
|
+
* otherwise the largest lies in `[1, 2)`. A coordinate that is not finite gives
|
|
10
|
+
* `NaN`s. Allocates nothing.
|
|
11
|
+
*
|
|
12
|
+
* The plain fan sum where its rigorous bound settles every component (edges up
|
|
13
|
+
* to 2^200, no cancellation between the fan triangles beyond about 2^−50 of the
|
|
14
|
+
* largest component); then the same sum in doubled precision (each edge split
|
|
15
|
+
* exactly by TwoSum and scaled per axis as `triangle3Cross_` scales a
|
|
16
|
+
* triangle's, each product of high parts by TwoProduct, every part summed by
|
|
17
|
+
* Ogita, Rump & Oishi's `Sum2`, with a rigorous bound on what is lost); last,
|
|
18
|
+
* each component as the exact sum `Σ vᵢ × vᵢ₊₁` around the ring (the fan's sum
|
|
19
|
+
* expanded, the first vertex's terms cancelling) by Kulisch's long accumulator,
|
|
20
|
+
* rounded once at any exponent.
|
|
21
|
+
*/
|
|
22
|
+
export declare function polygon3Cross_(out: Float64Array, coordinates: Float64Array, count: number): void;
|
|
23
|
+
//# sourceMappingURL=_polygon3-cross.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_polygon3-cross.d.ts","sourceRoot":"","sources":["../src/_polygon3-cross.ts"],"names":[],"mappings":"AA8EA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAC7B,GAAG,EAAE,YAAY,EACjB,WAAW,EAAE,YAAY,EACzB,KAAK,EAAE,MAAM,GACX,IAAI,CA0BN"}
|