@ac-kit/math-geometry 0.3.0 → 0.4.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 (51) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/README.md +43 -3
  3. package/dist/_polygon3-cross.d.ts +23 -0
  4. package/dist/_polygon3-cross.d.ts.map +1 -0
  5. package/dist/_polygon3-cross.js +418 -0
  6. package/dist/_polygon3-cross.js.map +1 -0
  7. package/dist/_triangle3-cross.d.ts +66 -0
  8. package/dist/_triangle3-cross.d.ts.map +1 -0
  9. package/dist/_triangle3-cross.js +396 -0
  10. package/dist/_triangle3-cross.js.map +1 -0
  11. package/dist/line2.d.ts +4 -0
  12. package/dist/line2.d.ts.map +1 -1
  13. package/dist/line2.js +26 -5
  14. package/dist/line2.js.map +1 -1
  15. package/dist/mesh/_index-kernels-u16.d.ts +51 -9
  16. package/dist/mesh/_index-kernels-u16.d.ts.map +1 -1
  17. package/dist/mesh/_index-kernels-u16.js +905 -124
  18. package/dist/mesh/_index-kernels-u16.js.map +1 -1
  19. package/dist/mesh/_index-kernels-u32.d.ts +51 -9
  20. package/dist/mesh/_index-kernels-u32.d.ts.map +1 -1
  21. package/dist/mesh/_index-kernels-u32.js +905 -124
  22. package/dist/mesh/_index-kernels-u32.js.map +1 -1
  23. package/dist/mesh/mesh3-kernels.d.ts +56 -16
  24. package/dist/mesh/mesh3-kernels.d.ts.map +1 -1
  25. package/dist/mesh/mesh3-kernels.js +56 -16
  26. package/dist/mesh/mesh3-kernels.js.map +1 -1
  27. package/dist/plane3.d.ts +4 -3
  28. package/dist/plane3.d.ts.map +1 -1
  29. package/dist/plane3.js +18 -35
  30. package/dist/plane3.js.map +1 -1
  31. package/dist/polygon2.d.ts +54 -4
  32. package/dist/polygon2.d.ts.map +1 -1
  33. package/dist/polygon2.js +297 -7
  34. package/dist/polygon2.js.map +1 -1
  35. package/dist/polygon3.d.ts +19 -3
  36. package/dist/polygon3.d.ts.map +1 -1
  37. package/dist/polygon3.js +40 -16
  38. package/dist/polygon3.js.map +1 -1
  39. package/dist/quadtree.d.ts +40 -23
  40. package/dist/quadtree.d.ts.map +1 -1
  41. package/dist/quadtree.js +196 -119
  42. package/dist/quadtree.js.map +1 -1
  43. package/dist/segment2.d.ts +6 -1
  44. package/dist/segment2.d.ts.map +1 -1
  45. package/dist/segment2.js +20 -4
  46. package/dist/segment2.js.map +1 -1
  47. package/dist/triangle3.d.ts +20 -1
  48. package/dist/triangle3.d.ts.map +1 -1
  49. package/dist/triangle3.js +38 -18
  50. package/dist/triangle3.js.map +1 -1
  51. package/package.json +7 -7
@@ -3,7 +3,21 @@ import type { ReadonlyRay3 } from "../ray3-record.js";
3
3
  /**
4
4
  * The `Uint16Array` twin of the area-weighted vertex normals: the public
5
5
  * function checks the lengths and dispatches on the index type once. Writes
6
- * `positions.length` numbers into `out`. O(vertices + triangles).
6
+ * `positions.length` numbers into `out`. Each face adds its cross product,
7
+ * twice its area times its unit normal (`faceCross_`: within 2^−49 of its
8
+ * largest component, zero only for a degenerate face). While every face's
9
+ * product is plain (k = 0, its largest component in [2^−400, 2^402)), the sums
10
+ * are those products' as they come; otherwise a first pass finds, per vertex,
11
+ * the largest product among its faces, and each face adds its product scaled by
12
+ * the power of two that brings that vertex's largest to [1, 2): the weights
13
+ * keep their ratios, nothing overflows, and a vertex whose faces are all tiny
14
+ * beside other vertices' still gets its normal. Each sum keeps a running bound
15
+ * on its rounding errors (Higham, "Accuracy and Stability of Numerical
16
+ * Algorithms", §4.2: within u/(1 − u) of the partial sums' magnitudes, u =
17
+ * 2^−53); a vertex whose bound is not within 2^−50 of its largest component
18
+ * (its faces cancel, or it has very many) is summed again exactly
19
+ * (`exactVertexSums_`). O(vertices + triangles); no allocation once the
20
+ * per-vertex scratch has grown to the largest mesh.
7
21
  */
8
22
  export declare function mesh3VertexNormalsU16(out: Float64Array, positions: Float64Array, indices: Uint16Array): void;
9
23
  /**
@@ -11,18 +25,44 @@ export declare function mesh3VertexNormalsU16(out: Float64Array, positions: Floa
11
25
  * zero vector for a degenerate one. O(triangles).
12
26
  */
13
27
  export declare function mesh3FaceNormalsU16(out: Float64Array, positions: Float64Array, indices: Uint16Array): void;
14
- /** The `Uint16Array` twin of the surface area. O(triangles). */
28
+ /**
29
+ * The `Uint16Array` twin of the surface area: each face's area from its edges
30
+ * and cross product scaled by powers of two (`faceArea_`), so no square
31
+ * overflows or underflows at any size or distance from the origin, rounded once
32
+ * per face and summed exactly: the same number in every face order.
33
+ * O(triangles), no allocation.
34
+ */
15
35
  export declare function mesh3SurfaceAreaU16(positions: Float64Array, indices: Uint16Array): number;
16
36
  /**
17
- * The `Uint16Array` twin of the signed volume, summed from the first triangle's
18
- * first vertex so that a mesh far from the origin, or a vertex no triangle
19
- * uses, loses no digits. O(triangles).
37
+ * The `Uint16Array` twin of the signed volume: six times it is `Σ (a − o) · ((b
38
+ * − a) × (c − a))` over the faces, o being the frame's anchor (any point gives
39
+ * the same volume for a closed mesh). The sum is a determinant per face, so
40
+ * each axis may take its own power-of-two scale: the frame brings every axis's
41
+ * extent below 1, then a first pass over the faces bounds their terms and one
42
+ * common power of two brings the largest near 2^1000, so that no product
43
+ * overflows and small faces keep their digits, however thin, wide or far from
44
+ * the origin the mesh is. Each face's term is then written as exact products:
45
+ * `a − o` as TwoSum's pair, the cross product as an expansion (each component
46
+ * two products and their rounding errors, Ogita, Rump & Oishi's TwoProduct),
47
+ * and the whole summed exactly (`PreciseSum`). With the face-local edge
48
+ * differences exact, which they are wherever a face is small beside its
49
+ * distance from the origin (Sterbenz), the result is six times the volume
50
+ * rounded once, then divided by 6: the same number in every face order and at
51
+ * every offset, and a vertex no triangle uses is never read. A term below about
52
+ * 2^−1900 of the largest may lose digits to the subnormal range; so may a
53
+ * volume that small beside the largest term. O(triangles), no allocation.
20
54
  */
21
55
  export declare function mesh3VolumeU16(positions: Float64Array, indices: Uint16Array): number;
22
56
  /**
23
- * The `Uint16Array` twin of the surface centroid, relative to the first
24
- * triangle's first vertex. A zero total area divides zero by zero: `NaN`.
25
- * O(triangles).
57
+ * The `Uint16Array` twin of the surface centroid: `o + Σ A · (a + b + c − 3o) /
58
+ * 3` over `Σ A`, o being the frame's anchor and A each face's doubled area
59
+ * (`faceArea_`), scaled by one power of two that brings the largest near 1, so
60
+ * no weight overflows and only one below 2^−1070 of the largest is lost. Every
61
+ * corner minus o is TwoSum's exact pair scaled into the frame per axis, every
62
+ * product split exactly (TwoProduct) and every sum exact (`PreciseSum`), so the
63
+ * result is the same in every face order, nothing overflows at any size or
64
+ * distance from the origin, and a vertex no triangle uses is never read. A zero
65
+ * total area divides zero by zero: `NaN`. O(triangles), no allocation.
26
66
  */
27
67
  export declare function mesh3CentroidU16(out: Vec3, positions: Float64Array, indices: Uint16Array): void;
28
68
  /**
@@ -32,7 +72,9 @@ export declare function mesh3CentroidU16(out: Vec3, positions: Float64Array, ind
32
72
  export declare function mesh3IntersectRay3U16(out: Vec3, ray: ReadonlyRay3, positions: Float64Array, indices: Uint16Array, cullBackFaces: boolean): number;
33
73
  /**
34
74
  * The `Uint16Array` twin of the triangle depths: `z / w` of each triangle's
35
- * centroid under `viewProjection`. O(triangles).
75
+ * centroid under `viewProjection`. A centroid whose coordinates overflow when
76
+ * summed takes halves; one whose transformed z or w overflows is scaled by a
77
+ * power of two first, which leaves `z / w` unchanged. O(triangles).
36
78
  */
37
79
  export declare function mesh3TriangleDepthsU16(out: Float64Array, positions: Float64Array, indices: Uint16Array, viewProjection: ReadonlyMat4x4): void;
38
80
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"_index-kernels-u16.d.ts","sourceRoot":"","sources":["../../src/mesh/_index-kernels-u16.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,IAAI,EAGT,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,GAClB,IAAI,CAuDN;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,GAClB,IAAI,CAmBN;AAED,gEAAgE;AAChE,wBAAgB,mBAAmB,CAClC,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,GAClB,MAAM,CAoBR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC7B,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,GAClB,MAAM,CA2BR;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,IAAI,EACT,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,GAClB,IAAI,CA0CN;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACpC,GAAG,EAAE,IAAI,EACT,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,OAAO,GACpB,MAAM,CAuCR;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,WAAW,EACpB,cAAc,EAAE,cAAc,GAC5B,IAAI,CAuBN;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,WAAW,GAChB,IAAI,CAQN"}
1
+ {"version":3,"file":"_index-kernels-u16.d.ts","sourceRoot":"","sources":["../../src/mesh/_index-kernels-u16.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,IAAI,EAGT,MAAM,qBAAqB,CAAC;AAW7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAiFt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