@absolutejs/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.
package/README.md CHANGED
@@ -155,3 +155,46 @@ models, predict extraction clearance or validate dynamic contact penetration.
155
155
  Bounds are not proof of overlap. Limits: 64 meshes, 100,000 total vertices,
156
156
  200,000 total triangles, and at most 1,024 requested pair queries. A host worker
157
157
  must impose its own lifetime bound on its injected native kernel.
158
+
159
+ ## Exclusive material partition (0.4.0)
160
+
161
+ `partitionSolidMaterials(meshes, kernel, maximumOperations = 126)` implements
162
+ ordered solid ownership. Cell i is input i minus the union of earlier inputs.
163
+ The caller explicitly chooses the order; this library does not invent a material
164
+ priority. Inputs must be valid oriented solid boundaries, including cavity walls.
165
+
166
+ Supply `{create(mesh), subtract(a,b), union(a,b), mesh(solid)}`. Native handles
167
+ implement `volume()` and `delete()`; every construction/operation returns a fresh
168
+ handle, and failures inside the adapter must clean up allocations not returned.
169
+ `mesh` returns Float64 positions and Uint32 indices in the supplied local frame.
170
+ Return a valid closed boundary, or two empty arrays for an empty solid. The
171
+ package copies all borrowed arrays and releases native handles on success/failure.
172
+ At most three native handles are retained at once, including the output of the
173
+ current operation; previous union/intermediate geometry is promptly released.
174
+
175
+ Results include:
176
+ - `cells`: one entry per input, with stable `source` index, mesh and volume.
177
+ A fully covered source remains an explicitly empty cell.
178
+ - `exterior`: the separate whole-union boundary and volume.
179
+ - `inputVolumes`, `authoredVolume`, `materialVolume`, `volumeDifference`,
180
+ `maximumVolumeError` and `operations`. The signed volume difference is not
181
+ clamped; insignificant negative roundoff can remain.
182
+
183
+ Cell walls include internal material interfaces. **Do not render every cell wall
184
+ as exposed material or infer that two touching cells are detached.** Exterior face
185
+ provenance, adjacency, strength, density, fracture surfaces and extraction/physics
186
+ acceptance remain host concerns. In particular this does not turn an existing
187
+ positive-overlap attachment graph into a surface-interface graph.
188
+
189
+ Limits: 1–64 inputs, 100,000 input vertices/200,000 input triangles, up to 126
190
+ Boolean operations, and 200,000 exported vertices/400,000 exported triangles
191
+ across all cells plus exterior. Native input/output volume and total conservation
192
+ errors above 1e-5 reject. These are acceptance budgets, not certified geometric
193
+ error bounds or a proof against a faulty Boolean backend. Topology checks do not
194
+ detect all geometric self-intersections. Use a cancellable worker: a synchronous
195
+ backend call cannot be interrupted by an operation counter.
196
+
197
+ The implementation uses the set identity
198
+ `C_i = S_i ∖ (S_0 ∪ … ∪ S_(i−1))`; its tests use Manifold only as a development
199
+ dependency. [Manifold's documentation](https://manifoldcad.org/docs/jsuser/classes/Manifold.html)
200
+ describes the native Boolean/volume contract. No Boolean engine is bundled.
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { closedComponents } from './closedComponents.js';
4
4
  export { solidPointMembership } from './solidPointMembership.js';
5
5
  export { solidComponents } from './solidComponents.js';
6
6
  export { auditSolidOverlaps, type OverlapMesh, type OverlapSolid, type SolidOverlapAudit } from './overlap.js';
7
+ export { partitionSolidMaterials, type MaterialPartitionKernel, type SolidMaterialPartition } from './materialPartition.js';
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export { closedComponents } from './closedComponents.js';
4
4
  export { solidPointMembership } from './solidPointMembership.js';
5
5
  export { solidComponents } from './solidComponents.js';
6
6
  export { auditSolidOverlaps } from './overlap.js';
7
+ export { partitionSolidMaterials } from './materialPartition.js';
@@ -0,0 +1,39 @@
1
+ import type { OverlapMesh, OverlapSolid } from './overlap.js';
2
+ export type MaterialPartitionKernel<S extends OverlapSolid> = {
3
+ create(mesh: OverlapMesh): S;
4
+ subtract(a: S, b: S): S;
5
+ union(a: S, b: S): S;
6
+ mesh(solid: S): OverlapMesh;
7
+ };
8
+ /**
9
+ * Ordered CSG material ownership: cell i = input i minus all earlier inputs.
10
+ * Input order is the host's explicit policy. The separate union mesh is the
11
+ * exterior; cell boundaries include INTERNAL partition walls and must not be
12
+ * blindly rendered or interpreted as fractures. No attachment/strength inference.
13
+ *
14
+ * The host must supply correct Boolean operations and fresh disposable handles.
15
+ * Meshes are valid, consistently oriented, non-self-intersecting solid boundaries;
16
+ * closedComponents checks topology, not geometric self-intersection. All input
17
+ * geometry is copied/rebased before the host sees it. Returned meshes are copied.
18
+ * Native work is bounded by input/output sizes and operation count, not wall time.
19
+ * Run in a cancellable worker for a wall-clock deadline.
20
+ */
21
+ export declare function partitionSolidMaterials<S extends OverlapSolid>(meshes: readonly OverlapMesh[], kernel: MaterialPartitionKernel<S>, maximumOperations?: number): {
22
+ cells: ({
23
+ source: number;
24
+ } & OverlapMesh & {
25
+ volume: number;
26
+ })[];
27
+ exterior: {
28
+ positions: Float64Array<ArrayBuffer>;
29
+ indices: Uint32Array<ArrayBuffer>;
30
+ volume: number;
31
+ };
32
+ inputVolumes: number[];
33
+ authoredVolume: number;
34
+ materialVolume: number;
35
+ volumeDifference: number;
36
+ maximumVolumeError: number;
37
+ operations: number;
38
+ };
39
+ export type SolidMaterialPartition = ReturnType<typeof partitionSolidMaterials>;
@@ -0,0 +1,117 @@
1
+ import { closedComponents } from './closedComponents.js';
2
+ import { signedVolume } from './signedVolume.js';
3
+ /**
4
+ * Ordered CSG material ownership: cell i = input i minus all earlier inputs.
5
+ * Input order is the host's explicit policy. The separate union mesh is the
6
+ * exterior; cell boundaries include INTERNAL partition walls and must not be
7
+ * blindly rendered or interpreted as fractures. No attachment/strength inference.
8
+ *
9
+ * The host must supply correct Boolean operations and fresh disposable handles.
10
+ * Meshes are valid, consistently oriented, non-self-intersecting solid boundaries;
11
+ * closedComponents checks topology, not geometric self-intersection. All input
12
+ * geometry is copied/rebased before the host sees it. Returned meshes are copied.
13
+ * Native work is bounded by input/output sizes and operation count, not wall time.
14
+ * Run in a cancellable worker for a wall-clock deadline.
15
+ */
16
+ export function partitionSolidMaterials(meshes, kernel, maximumOperations = 126) {
17
+ if (!Array.isArray(meshes) || !meshes.length || meshes.length > 64 ||
18
+ !kernel || !['create', 'subtract', 'union', 'mesh'].every(k => typeof kernel[k] === 'function') ||
19
+ !Number.isSafeInteger(maximumOperations) || maximumOperations < 0 || maximumOperations > 126 ||
20
+ 2 * (meshes.length - 1) > maximumOperations ||
21
+ meshes.reduce((n, m) => n + (m?.positions?.length ?? Infinity), 0) > 300000 ||
22
+ meshes.reduce((n, m) => n + (m?.indices?.length ?? Infinity), 0) > 600000)
23
+ throw Error('Invalid material partition budget');
24
+ const inputs = meshes;
25
+ const min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
26
+ const volumes = inputs.map(m => {
27
+ if (!(m.positions instanceof Float64Array) || !(m.indices instanceof Uint32Array) || !m.indices.length)
28
+ throw Error('Invalid material partition mesh');
29
+ closedComponents(m.positions, m.indices);
30
+ const v = signedVolume(m.positions, m.indices);
31
+ if (!Number.isFinite(v) || v <= 0)
32
+ throw Error('Invalid material input volume');
33
+ m.positions.forEach((p, i) => { min[i % 3] = Math.min(min[i % 3], p); max[i % 3] = Math.max(max[i % 3], p); });
34
+ return v;
35
+ });
36
+ const origin = min.map((v, k) => v / 2 + max[k] / 2);
37
+ const handles = new Set(), seen = new Set();
38
+ const own = (s) => {
39
+ if (seen.has(s))
40
+ throw Error('Material kernel must return fresh handles');
41
+ seen.add(s);
42
+ handles.add(s);
43
+ return s;
44
+ };
45
+ const release = (s) => { handles.delete(s); s.delete(); };
46
+ let maximumVolumeError = 0, outputVertices = 0, outputIndices = 0, operations = 0;
47
+ const checkVolume = (actual, expected) => {
48
+ const error = Math.abs(actual / expected - 1);
49
+ if (!Number.isFinite(error) || error > 1e-5)
50
+ throw Error('Material volume precision budget exceeded');
51
+ maximumVolumeError = Math.max(maximumVolumeError, error);
52
+ };
53
+ const read = (s) => {
54
+ const volume = s.volume();
55
+ if (!Number.isFinite(volume) || volume < 0)
56
+ throw Error('Invalid partition output volume');
57
+ const raw = kernel.mesh(s);
58
+ if (!(raw?.positions instanceof Float64Array) || !(raw?.indices instanceof Uint32Array) ||
59
+ (outputVertices += raw.positions.length / 3) > 200000 ||
60
+ (outputIndices += raw.indices.length) > 1200000)
61
+ throw Error('Material output budget exceeded');
62
+ const positions = raw.positions.slice(), indices = raw.indices.slice();
63
+ if (!indices.length) {
64
+ if (positions.length || volume !== 0)
65
+ throw Error('Invalid empty material cell');
66
+ return { positions, indices, volume };
67
+ }
68
+ closedComponents(positions, indices);
69
+ checkVolume(signedVolume(positions, indices), volume);
70
+ for (let i = 0; i < positions.length; i++)
71
+ positions[i] = positions[i] + origin[i % 3];
72
+ // Re-check precision after restoring the requested coordinate frame.
73
+ checkVolume(signedVolume(positions, indices), volume);
74
+ return { positions, indices, volume };
75
+ };
76
+ try {
77
+ const cells = [];
78
+ let combined;
79
+ for (let i = 0; i < inputs.length; i++) {
80
+ const m = inputs[i];
81
+ const input = own(kernel.create({
82
+ positions: Float64Array.from(m.positions, (v, j) => v - origin[j % 3]),
83
+ indices: m.indices.slice(),
84
+ }));
85
+ checkVolume(input.volume(), volumes[i]);
86
+ const exclusive = combined ? own(kernel.subtract(input, combined)) : input;
87
+ if (combined)
88
+ operations++;
89
+ if (exclusive.volume() > input.volume() * 1.00001)
90
+ throw Error('Partition subtraction enlarged material');
91
+ cells.push({ source: i, ...read(exclusive) });
92
+ if (combined) {
93
+ release(exclusive);
94
+ const previous = combined;
95
+ combined = own(kernel.union(previous, input));
96
+ operations++;
97
+ release(previous);
98
+ release(input);
99
+ }
100
+ else
101
+ combined = input;
102
+ }
103
+ const exterior = read(combined);
104
+ const materialVolume = cells.reduce((n, c) => n + c.volume, 0);
105
+ checkVolume(materialVolume, exterior.volume);
106
+ const authoredVolume = volumes.reduce((n, v) => n + v, 0);
107
+ if (exterior.volume > authoredVolume * 1.00001)
108
+ throw Error('Partition union enlarged material');
109
+ return { cells, exterior, inputVolumes: volumes, authoredVolume,
110
+ materialVolume: exterior.volume, volumeDifference: authoredVolume - exterior.volume,
111
+ maximumVolumeError, operations };
112
+ }
113
+ finally {
114
+ for (const h of [...handles].reverse())
115
+ h.delete();
116
+ }
117
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/geometry",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Bounded geometry projection, oriented material components and point membership for worker-side web 3D tooling.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",