okgeometry-api 1.1.3 → 1.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "okgeometry-api",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Geometry engine API for AEC applications — NURBS, meshes, booleans, intersections. Powered by Rust/WASM.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/Mesh.ts CHANGED
@@ -278,77 +278,52 @@ export class Mesh {
278
278
  }));
279
279
  }
280
280
 
281
- private static buildBooleanDebugProbes(
281
+ private static buildDirectionalDebugProbes(
282
282
  inputA: Mesh,
283
283
  inputB: Mesh,
284
284
  result: Mesh,
285
- options?: MeshBooleanDebugOptions,
285
+ center: Point,
286
+ pad: number,
287
+ maxDistance: number,
288
+ maxHits: number,
289
+ probeIds: Array<"posX" | "negX" | "posY" | "negY" | "posZ" | "negZ">,
290
+ labelPrefix = "",
286
291
  ): MeshBooleanDebugProbe[] {
287
- const boundsA = Mesh.toDebugBounds(inputA.getBounds());
288
- const boundsB = Mesh.toDebugBounds(inputB.getBounds());
289
- const resultBounds = Mesh.toDebugBounds(result.getBounds());
290
- const min = new Point(
291
- Math.min(boundsA.min.x, boundsB.min.x, resultBounds.min.x),
292
- Math.min(boundsA.min.y, boundsB.min.y, resultBounds.min.y),
293
- Math.min(boundsA.min.z, boundsB.min.z, resultBounds.min.z),
294
- );
295
- const max = new Point(
296
- Math.max(boundsA.max.x, boundsB.max.x, resultBounds.max.x),
297
- Math.max(boundsA.max.y, boundsB.max.y, resultBounds.max.y),
298
- Math.max(boundsA.max.z, boundsB.max.z, resultBounds.max.z),
299
- );
300
- const center = new Point(
301
- (min.x + max.x) * 0.5,
302
- (min.y + max.y) * 0.5,
303
- (min.z + max.z) * 0.5,
304
- );
305
- const diag = Math.max(
306
- 1e-6,
307
- Math.hypot(max.x - min.x, max.y - min.y, max.z - min.z),
308
- );
309
- const padScale = Number.isFinite(options?.rayPaddingScale)
310
- ? Math.max(0.01, options?.rayPaddingScale ?? 0.25)
311
- : 0.25;
312
- const pad = Math.max(1e-3, diag * padScale);
313
- const maxHits = Mesh.clampDebugHitCount(options?.maxRayHits);
314
- const probeIds = options?.probes?.length
315
- ? options.probes
316
- : Mesh.DEFAULT_BOOLEAN_DEBUG_PROBES;
292
+ const prefixed = (id: string) => (labelPrefix ? `${labelPrefix}:${id}` : id);
317
293
  const probeSpecs: Record<
318
294
  "posX" | "negX" | "posY" | "negY" | "posZ" | "negZ",
319
295
  { origin: Point; direction: Vec3 }
320
296
  > = {
321
297
  posX: {
322
- origin: new Point(max.x + pad, center.y, center.z),
298
+ origin: new Point(center.x + pad, center.y, center.z),
323
299
  direction: new Vec3(-1, 0, 0),
324
300
  },
325
301
  negX: {
326
- origin: new Point(min.x - pad, center.y, center.z),
302
+ origin: new Point(center.x - pad, center.y, center.z),
327
303
  direction: new Vec3(1, 0, 0),
328
304
  },
329
305
  posY: {
330
- origin: new Point(center.x, max.y + pad, center.z),
306
+ origin: new Point(center.x, center.y + pad, center.z),
331
307
  direction: new Vec3(0, -1, 0),
332
308
  },
333
309
  negY: {
334
- origin: new Point(center.x, min.y - pad, center.z),
310
+ origin: new Point(center.x, center.y - pad, center.z),
335
311
  direction: new Vec3(0, 1, 0),
336
312
  },
337
313
  posZ: {
338
- origin: new Point(center.x, center.y, max.z + pad),
314
+ origin: new Point(center.x, center.y, center.z + pad),
339
315
  direction: new Vec3(0, 0, -1),
340
316
  },
341
317
  negZ: {
342
- origin: new Point(center.x, center.y, min.z - pad),
318
+ origin: new Point(center.x, center.y, center.z - pad),
343
319
  direction: new Vec3(0, 0, 1),
344
320
  },
345
321
  };
346
- const maxDistance = diag + pad * 2;
347
322
 
348
323
  return probeIds.map((id) => {
349
324
  const spec = probeSpecs[id];
350
325
  return {
351
- label: id,
326
+ label: prefixed(id),
352
327
  origin: spec.origin,
353
328
  direction: spec.direction,
354
329
  maxDistance,
@@ -359,6 +334,67 @@ export class Mesh {
359
334
  });
360
335
  }
361
336
 
337
+ private static buildBooleanDebugProbes(
338
+ inputA: Mesh,
339
+ inputB: Mesh,
340
+ result: Mesh,
341
+ options?: MeshBooleanDebugOptions,
342
+ ): MeshBooleanDebugProbe[] {
343
+ const boundsA = Mesh.toDebugBounds(inputA.getBounds());
344
+ const boundsB = Mesh.toDebugBounds(inputB.getBounds());
345
+ const resultBounds = Mesh.toDebugBounds(result.getBounds());
346
+ const min = new Point(
347
+ Math.min(boundsA.min.x, boundsB.min.x, resultBounds.min.x),
348
+ Math.min(boundsA.min.y, boundsB.min.y, resultBounds.min.y),
349
+ Math.min(boundsA.min.z, boundsB.min.z, resultBounds.min.z),
350
+ );
351
+ const max = new Point(
352
+ Math.max(boundsA.max.x, boundsB.max.x, resultBounds.max.x),
353
+ Math.max(boundsA.max.y, boundsB.max.y, resultBounds.max.y),
354
+ Math.max(boundsA.max.z, boundsB.max.z, resultBounds.max.z),
355
+ );
356
+ const center = new Point(
357
+ (min.x + max.x) * 0.5,
358
+ (min.y + max.y) * 0.5,
359
+ (min.z + max.z) * 0.5,
360
+ );
361
+ const diag = Math.max(
362
+ 1e-6,
363
+ Math.hypot(max.x - min.x, max.y - min.y, max.z - min.z),
364
+ );
365
+ const padScale = Number.isFinite(options?.rayPaddingScale)
366
+ ? Math.max(0.01, options?.rayPaddingScale ?? 0.25)
367
+ : 0.25;
368
+ const pad = Math.max(1e-3, diag * padScale);
369
+ const maxHits = Mesh.clampDebugHitCount(options?.maxRayHits);
370
+ const probeIds = options?.probes?.length
371
+ ? options.probes
372
+ : Mesh.DEFAULT_BOOLEAN_DEBUG_PROBES;
373
+ const maxDistance = diag + pad * 2;
374
+ const sceneCenterProbes = Mesh.buildDirectionalDebugProbes(
375
+ inputA,
376
+ inputB,
377
+ result,
378
+ center,
379
+ pad,
380
+ maxDistance,
381
+ maxHits,
382
+ probeIds,
383
+ );
384
+ const inputBCenterProbes = Mesh.buildDirectionalDebugProbes(
385
+ inputA,
386
+ inputB,
387
+ result,
388
+ boundsB.center,
389
+ pad,
390
+ maxDistance,
391
+ maxHits,
392
+ probeIds,
393
+ "inputB",
394
+ );
395
+ return sceneCenterProbes.concat(inputBCenterProbes);
396
+ }
397
+
362
398
  private static createBooleanDebugReport(
363
399
  inputA: Mesh,
364
400
  inputB: Mesh,