@snaptrude/plugin-core 0.9.3 → 0.9.5

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.
@@ -1,6 +1,10 @@
1
1
  import * as z from "zod"
2
2
  import { PluginApiReturn } from "../../../../types"
3
- import { UnderlayHandle, BBoxComponents } from "../../../../handles"
3
+ import {
4
+ UnderlayHandle,
5
+ BBoxComponents,
6
+ Vec3Components,
7
+ } from "../../../../handles"
4
8
 
5
9
  /**
6
10
  * Underlays — inspect and edit the placed reference planes imported into the
@@ -65,7 +69,65 @@ export abstract class PluginCoreIoUnderlayApi {
65
69
  * if (bb) console.log(`width ${bb.max.x - bb.min.x}`)
66
70
  * ```
67
71
  */
68
- public abstract getBounds(underlay: UnderlayHandle): PluginApiReturn<BBoxComponents | null>
72
+ public abstract getBounds(
73
+ underlay: UnderlayHandle,
74
+ ): PluginApiReturn<BBoxComponents | null>
75
+
76
+ /**
77
+ * List the distinct original AutoCAD layer names retained by a placed CAD
78
+ * underlay. Returns `[]` for non-CAD underlays, legacy imports created before
79
+ * source-layer retention, missing underlays, or CAD drawings without layer tags.
80
+ *
81
+ * @param underlay - The placed CAD underlay to inspect.
82
+ * @returns the retained AutoCAD layer names in first-appearance order.
83
+ *
84
+ * @examplePrompt List the original AutoCAD layers in this imported drawing
85
+ * @examplePrompt Which CAD layers are available in this underlay?
86
+ *
87
+ * # Example
88
+ * ```ts
89
+ * const layers = await snaptrude.core.io.underlay.listCadLayers(cad)
90
+ * console.log(layers)
91
+ * ```
92
+ */
93
+ public abstract listCadLayers(
94
+ underlay: UnderlayHandle,
95
+ ): PluginApiReturn<string[]>
96
+
97
+ /**
98
+ * Read one original AutoCAD layer's retained line and arc geometry in
99
+ * **Snaptrude world space** and Snaptrude internal units. Results are paged so
100
+ * large drawings can be inspected without returning the whole DWG at once.
101
+ *
102
+ * The world-space coordinates include the CAD underlay's current position,
103
+ * rotation, scale, and storey elevation. `null` means the underlay no longer
104
+ * resolves. An unknown layer returns a page with `total: 0`.
105
+ *
106
+ * @param underlay - The placed CAD underlay to inspect.
107
+ * @param layer - Exact, case-sensitive original AutoCAD layer name.
108
+ * @param options - Optional zero-based offset and page limit (default 500,
109
+ * maximum 1000).
110
+ * @returns a page of retained CAD curves, or `null` if the underlay is gone.
111
+ * @throws if the handle resolves to an image/PDF rather than a CAD underlay.
112
+ *
113
+ * @examplePrompt Read the wall geometry from the A-WALL layer in this CAD underlay
114
+ * @examplePrompt Get the next 500 curves from the structural CAD layer
115
+ *
116
+ * # Example
117
+ * ```ts
118
+ * const page = await snaptrude.core.io.underlay.getCadLayerGeometry(
119
+ * cad,
120
+ * "A-WALL",
121
+ * { offset: 0, limit: 500 },
122
+ * )
123
+ * if (page) console.log(`${page.curves.length} of ${page.total} curves`)
124
+ * ```
125
+ */
126
+ public abstract getCadLayerGeometry(
127
+ underlay: UnderlayHandle,
128
+ layer: string,
129
+ options?: PluginCadLayerGeometryOptions,
130
+ ): PluginApiReturn<PluginCadLayerGeometryPage | null>
69
131
 
70
132
  /**
71
133
  * Read an underlay's scale. Works for **image and PDF** underlays. Returns
@@ -158,7 +220,9 @@ export abstract class PluginCoreIoUnderlayApi {
158
220
  * await snaptrude.core.io.underlay.resetScale(plan)
159
221
  * ```
160
222
  */
161
- public abstract resetScale(underlay: UnderlayHandle): PluginApiReturn<{ scaleFactor: number }>
223
+ public abstract resetScale(
224
+ underlay: UnderlayHandle,
225
+ ): PluginApiReturn<{ scaleFactor: number }>
162
226
 
163
227
  /**
164
228
  * Read an underlay's opacity (`0`..`1`), or `null` if it has no material.
@@ -175,7 +239,9 @@ export abstract class PluginCoreIoUnderlayApi {
175
239
  * const o = await snaptrude.core.io.underlay.getOpacity(plan)
176
240
  * ```
177
241
  */
178
- public abstract getOpacity(underlay: UnderlayHandle): PluginApiReturn<number | null>
242
+ public abstract getOpacity(
243
+ underlay: UnderlayHandle,
244
+ ): PluginApiReturn<number | null>
179
245
 
180
246
  /**
181
247
  * Set an underlay's opacity (`0` = transparent .. `1` = opaque). Undoable.
@@ -197,7 +263,10 @@ export abstract class PluginCoreIoUnderlayApi {
197
263
  * await snaptrude.core.io.underlay.setOpacity(plan, 0.3)
198
264
  * ```
199
265
  */
200
- public abstract setOpacity(underlay: UnderlayHandle, opacity: number): PluginApiReturn<void>
266
+ public abstract setOpacity(
267
+ underlay: UnderlayHandle,
268
+ opacity: number,
269
+ ): PluginApiReturn<void>
201
270
 
202
271
  /**
203
272
  * Delete an underlay from the scene (and its backend record). Applies to image,
@@ -218,6 +287,106 @@ export abstract class PluginCoreIoUnderlayApi {
218
287
  * ```
219
288
  */
220
289
  public abstract delete(underlay: UnderlayHandle): PluginApiReturn<void>
290
+
291
+ /**
292
+ * Extract **continuous wall centrelines** from one retained AutoCAD layer's
293
+ * double-line wall faces — the deterministic tracing primitive behind
294
+ * CAD-to-BIM wall conversion. Instead of paging raw curves and re-deriving
295
+ * the geometry in worker code, this reads the whole layer and runs the vetted
296
+ * pipeline: cull fragments, dedupe, merge collinear runs into *faces*, pair
297
+ * parallel faces a wall-thickness apart into centrelines (midline = axis,
298
+ * separation = thickness), bridge collinear gaps up to
299
+ * `bridgeOpenings.maxWidth` into ONE continuous centreline while recording
300
+ * each bridged span as an opening, then snap near-touching endpoints at
301
+ * junctions.
302
+ *
303
+ * CAD drafters interrupt wall faces at every door/window, so raw wall layers
304
+ * always have gaps; Snaptrude doors/windows must host into a continuous wall.
305
+ * The returned centrelines are ready for `design.create.walls`, and each
306
+ * centreline's `openings` records where the CAD had a gap — feed those to the
307
+ * door/window placement step. `unpaired` faces (no parallel partner at wall
308
+ * thickness) are evidence, not noise: a run of unpaired perimeter faces
309
+ * usually means that stretch of facade is glazed, not solid.
310
+ *
311
+ * All lengths are in **Snaptrude internal units** (convert from project units
312
+ * with `core.units.convert`). Coordinates are world-space plan (x, z).
313
+ *
314
+ * Thin parallel pairs (glass lines, mullion faces) are the same algorithm at
315
+ * a smaller separation: pass e.g. `thicknessRange: [0.01, 0.25]` with
316
+ * `bridgeOpenings: null` to detect glazing runs on a glazing layer.
317
+ *
318
+ * @param underlay - The placed CAD underlay to read.
319
+ * @param layer - Exact, case-sensitive original AutoCAD layer name.
320
+ * @param options - Tolerances; see {@linkcode PluginCadCenterlineOptions}.
321
+ * @returns centrelines + unpaired faces + stats, or `null` if the underlay is gone.
322
+ * @throws if the handle resolves to an image/PDF rather than a CAD underlay.
323
+ *
324
+ * @examplePrompt Trace the walls from the a-wall CAD layer
325
+ * @examplePrompt Convert the AutoCAD wall linework into Snaptrude walls
326
+ * @examplePrompt Extract wall centrelines with thickness from the imported DWG
327
+ * @examplePrompt Find the glazing runs on the a-glazing layer
328
+ *
329
+ * # Example
330
+ * ```ts
331
+ * const [cad] = await snaptrude.core.io.underlay.list()
332
+ * const r = await snaptrude.core.io.underlay.extractCenterlines(cad, "a-wall")
333
+ * if (r) {
334
+ * const items = r.centerlines.map((c) => ({
335
+ * profile: [c.start, c.end],
336
+ * thickness: c.thickness,
337
+ * }))
338
+ * console.log(`${items.length} walls, ${r.unpaired.length} unpaired faces`)
339
+ * }
340
+ * ```
341
+ */
342
+ public abstract extractCenterlines(
343
+ underlay: UnderlayHandle,
344
+ layer: string,
345
+ options?: PluginCadCenterlineOptions,
346
+ ): PluginApiReturn<PluginCadCenterlinesResult | null>
347
+
348
+ /**
349
+ * Classify one retained AutoCAD layer's **arcs as door swings** — the
350
+ * deterministic tracing primitive behind CAD-to-BIM door placement. A door
351
+ * swing is drawn as a ~90° arc whose radius IS the leaf width and whose
352
+ * centre IS the hinge point. This filters the layer's arcs by plausible
353
+ * radius and sweep (rejecting inch-scale fillets, full-circle symbols and
354
+ * long shallow curves), reads each survivor as a door candidate (hinge, leaf
355
+ * width, swing direction, hosting wall direction), merges mirrored pairs
356
+ * sharing a chord line into double doors, and returns a radius histogram —
357
+ * real drawings use a handful of standard door sizes, so the histogram's
358
+ * clusters are the drawing's door widths (sanity-check them against the
359
+ * catalog; distrust arcs in no cluster).
360
+ *
361
+ * All lengths are in **Snaptrude internal units**. `rejected` lists filtered
362
+ * arcs with reasons so nothing is silently dropped.
363
+ *
364
+ * @param underlay - The placed CAD underlay to read.
365
+ * @param layer - Exact, case-sensitive original AutoCAD layer name.
366
+ * @param options - Gates and binning; see {@linkcode PluginCadArcClassifyOptions}.
367
+ * @returns door candidates + rejected arcs + histogram, or `null` if the underlay is gone.
368
+ * @throws if the handle resolves to an image/PDF rather than a CAD underlay.
369
+ *
370
+ * @examplePrompt Find the doors on the a-door CAD layer
371
+ * @examplePrompt Classify the door swing arcs in the imported drawing
372
+ * @examplePrompt What door sizes does this DWG use?
373
+ * @examplePrompt Read hinge points and leaf widths from the CAD door layer
374
+ *
375
+ * # Example
376
+ * ```ts
377
+ * const [cad] = await snaptrude.core.io.underlay.list()
378
+ * const r = await snaptrude.core.io.underlay.classifyArcs(cad, "a-door")
379
+ * if (r) {
380
+ * console.log(`${r.doors.length} doors; sizes:`,
381
+ * r.radiusHistogram.filter((b) => b.count > 1))
382
+ * }
383
+ * ```
384
+ */
385
+ public abstract classifyArcs(
386
+ underlay: UnderlayHandle,
387
+ layer: string,
388
+ options?: PluginCadArcClassifyOptions,
389
+ ): PluginApiReturn<PluginCadArcClassifyResult | null>
221
390
  }
222
391
 
223
392
  /**
@@ -251,7 +420,9 @@ export const PluginUnderlaySetScaleValue = z.union([
251
420
  z.number().positive(),
252
421
  PluginUnderlayPlanSize,
253
422
  ])
254
- export type PluginUnderlaySetScaleValue = z.infer<typeof PluginUnderlaySetScaleValue>
423
+ export type PluginUnderlaySetScaleValue = z.infer<
424
+ typeof PluginUnderlaySetScaleValue
425
+ >
255
426
 
256
427
  /**
257
428
  * Arguments for {@link PluginCoreIoUnderlayApi.setScale}.
@@ -265,7 +436,9 @@ export const PluginUnderlaySetScaleArgs = z.object({
265
436
  underlay: UnderlayHandle,
266
437
  scale: PluginUnderlaySetScaleValue,
267
438
  })
268
- export type PluginUnderlaySetScaleArgs = z.infer<typeof PluginUnderlaySetScaleArgs>
439
+ export type PluginUnderlaySetScaleArgs = z.infer<
440
+ typeof PluginUnderlaySetScaleArgs
441
+ >
269
442
 
270
443
  /**
271
444
  * Arguments for {@link PluginCoreIoUnderlayApi.setOpacity}.
@@ -279,7 +452,9 @@ export const PluginUnderlaySetOpacityArgs = z.object({
279
452
  underlay: UnderlayHandle,
280
453
  opacity: z.number().min(0).max(1),
281
454
  })
282
- export type PluginUnderlaySetOpacityArgs = z.infer<typeof PluginUnderlaySetOpacityArgs>
455
+ export type PluginUnderlaySetOpacityArgs = z.infer<
456
+ typeof PluginUnderlaySetOpacityArgs
457
+ >
283
458
 
284
459
  /**
285
460
  * Arguments for the single-underlay methods
@@ -293,3 +468,238 @@ export const PluginUnderlayRefArgs = z.object({
293
468
  underlay: UnderlayHandle,
294
469
  })
295
470
  export type PluginUnderlayRefArgs = z.infer<typeof PluginUnderlayRefArgs>
471
+
472
+ /** A retained AutoCAD line represented as a world-space read record. */
473
+ export const PluginCadLineGeometry = z.object({
474
+ type: z.literal("line"),
475
+ start: Vec3Components,
476
+ end: Vec3Components,
477
+ })
478
+ export type PluginCadLineGeometry = z.infer<typeof PluginCadLineGeometry>
479
+
480
+ /** A retained AutoCAD arc represented as a world-space read record. */
481
+ export const PluginCadArcGeometry = z.object({
482
+ type: z.literal("arc"),
483
+ centre: Vec3Components,
484
+ axis: Vec3Components,
485
+ start: Vec3Components,
486
+ end: Vec3Components,
487
+ })
488
+ export type PluginCadArcGeometry = z.infer<typeof PluginCadArcGeometry>
489
+
490
+ /** Line or arc geometry returned by `getCadLayerGeometry`. */
491
+ export const PluginCadGeometry = z.discriminatedUnion("type", [
492
+ PluginCadLineGeometry,
493
+ PluginCadArcGeometry,
494
+ ])
495
+ export type PluginCadGeometry = z.infer<typeof PluginCadGeometry>
496
+
497
+ /** Pagination options for `getCadLayerGeometry`. */
498
+ export const PluginCadLayerGeometryOptions = z.object({
499
+ offset: z.number().int().nonnegative().default(0),
500
+ limit: z.number().int().positive().max(1000).default(500),
501
+ })
502
+ export type PluginCadLayerGeometryOptions = z.input<
503
+ typeof PluginCadLayerGeometryOptions
504
+ >
505
+
506
+ /** Arguments for {@link PluginCoreIoUnderlayApi.getCadLayerGeometry}. */
507
+ export const PluginCadLayerGeometryArgs = z.object({
508
+ underlay: UnderlayHandle,
509
+ layer: z.string(),
510
+ options: PluginCadLayerGeometryOptions.default({ offset: 0, limit: 500 }),
511
+ })
512
+ export type PluginCadLayerGeometryArgs = z.infer<
513
+ typeof PluginCadLayerGeometryArgs
514
+ >
515
+
516
+ /** A page of one original AutoCAD layer's geometry in Snaptrude world space. */
517
+ export const PluginCadLayerGeometryPage = z.object({
518
+ layer: z.string(),
519
+ coordinateSpace: z.literal("snaptrude-world"),
520
+ units: z.literal("snaptrude-internal"),
521
+ total: z.number().int().nonnegative(),
522
+ offset: z.number().int().nonnegative(),
523
+ curves: z.array(PluginCadGeometry),
524
+ })
525
+ export type PluginCadLayerGeometryPage = z.infer<
526
+ typeof PluginCadLayerGeometryPage
527
+ >
528
+
529
+
530
+ /** A point in the world-space plan (x, z) projection, Snaptrude internal units. */
531
+ export const PluginPlanPoint = z.object({ x: z.number(), z: z.number() })
532
+ export type PluginPlanPoint = z.infer<typeof PluginPlanPoint>
533
+
534
+ /**
535
+ * Options for {@link PluginCoreIoUnderlayApi.extractCenterlines}. All lengths in
536
+ * Snaptrude internal units.
537
+ *
538
+ * | Property | Type | Description |
539
+ * |---|---|---|
540
+ * | `thicknessRange` | `[number, number]`? | Plausible wall thickness `[min, max]` (default `[0.3, 1.6]` ≈ 3–16 in) |
541
+ * | `mergeGap` | `number`? | Noise tolerance joining collinear segments that are really one face (default `0.05`) |
542
+ * | `minLength` | `number`? | Cull fragments shorter than this (default `0.1`) |
543
+ * | `parallelTolDeg` | `number`? | Max angle in degrees between faces still considered parallel (default `2`) |
544
+ * | `minOverlap` | `number`? | Fraction of the shorter face that must overlap its pair (default `0.6`) |
545
+ * | `bridgeOpenings` | `{ maxWidth }` \| `null`? | Close collinear centreline gaps up to `maxWidth`, recording each as an opening (default `{ maxWidth: 9.6 }` ≈ 8 ft); `null` disables bridging |
546
+ */
547
+ export const PluginCadCenterlineOptions = z.object({
548
+ thicknessRange: z
549
+ .tuple([z.number().positive(), z.number().positive()])
550
+ .default([0.3, 1.6]),
551
+ mergeGap: z.number().nonnegative().default(0.05),
552
+ minLength: z.number().nonnegative().default(0.1),
553
+ parallelTolDeg: z.number().positive().max(15).default(2),
554
+ minOverlap: z.number().min(0).max(1).default(0.6),
555
+ bridgeOpenings: z
556
+ .object({ maxWidth: z.number().positive() })
557
+ .nullable()
558
+ .default({ maxWidth: 9.6 }),
559
+ })
560
+ export type PluginCadCenterlineOptions = z.input<
561
+ typeof PluginCadCenterlineOptions
562
+ >
563
+
564
+ /** Arguments for {@link PluginCoreIoUnderlayApi.extractCenterlines}. */
565
+ export const PluginCadCenterlinesArgs = z.object({
566
+ underlay: UnderlayHandle,
567
+ layer: z.string(),
568
+ options: PluginCadCenterlineOptions.default({
569
+ thicknessRange: [0.3, 1.6],
570
+ mergeGap: 0.05,
571
+ minLength: 0.1,
572
+ parallelTolDeg: 2,
573
+ minOverlap: 0.6,
574
+ bridgeOpenings: { maxWidth: 9.6 },
575
+ }),
576
+ })
577
+ export type PluginCadCenterlinesArgs = z.infer<typeof PluginCadCenterlinesArgs>
578
+
579
+ /** A span bridged over a CAD gap in a continuous centreline — a door/window opening candidate. */
580
+ export const PluginCadOpening = z.object({
581
+ start: PluginPlanPoint,
582
+ end: PluginPlanPoint,
583
+ width: z.number(),
584
+ })
585
+ export type PluginCadOpening = z.infer<typeof PluginCadOpening>
586
+
587
+ /**
588
+ * One continuous wall centreline extracted from CAD wall faces. `thickness` is
589
+ * the measured face separation; `openings` are the CAD gaps bridged into this
590
+ * centreline (feed the door/window step).
591
+ */
592
+ export const PluginCadCenterline = z.object({
593
+ start: PluginPlanPoint,
594
+ end: PluginPlanPoint,
595
+ thickness: z.number(),
596
+ length: z.number(),
597
+ sourceFaceCount: z.number().int().nonnegative(),
598
+ openings: z.array(PluginCadOpening),
599
+ })
600
+ export type PluginCadCenterline = z.infer<typeof PluginCadCenterline>
601
+
602
+ /** A merged face with no parallel partner at wall thickness — evidence (often glazing), not noise. */
603
+ export const PluginCadUnpairedFace = z.object({
604
+ start: PluginPlanPoint,
605
+ end: PluginPlanPoint,
606
+ length: z.number(),
607
+ })
608
+ export type PluginCadUnpairedFace = z.infer<typeof PluginCadUnpairedFace>
609
+
610
+ /** Result of {@link PluginCoreIoUnderlayApi.extractCenterlines}. */
611
+ export const PluginCadCenterlinesResult = z.object({
612
+ layer: z.string(),
613
+ coordinateSpace: z.literal("snaptrude-world"),
614
+ units: z.literal("snaptrude-internal"),
615
+ centerlines: z.array(PluginCadCenterline),
616
+ unpaired: z.array(PluginCadUnpairedFace),
617
+ stats: z.object({
618
+ curvesRead: z.number().int().nonnegative(),
619
+ arcsSkipped: z.number().int().nonnegative(),
620
+ fragmentsCulled: z.number().int().nonnegative(),
621
+ duplicates: z.number().int().nonnegative(),
622
+ faces: z.number().int().nonnegative(),
623
+ }),
624
+ })
625
+ export type PluginCadCenterlinesResult = z.infer<
626
+ typeof PluginCadCenterlinesResult
627
+ >
628
+
629
+ /**
630
+ * Options for {@link PluginCoreIoUnderlayApi.classifyArcs}. Lengths in Snaptrude
631
+ * internal units, sweeps in degrees.
632
+ *
633
+ * | Property | Type | Description |
634
+ * |---|---|---|
635
+ * | `radiusRange` | `[number, number]`? | Plausible door-leaf widths (default `[3, 5.4]` ≈ 2.5–4.5 ft) |
636
+ * | `sweepRangeDeg` | `[number, number]`? | Accepted arc sweep in degrees (default `[60, 120]`; a swing is ~90°) |
637
+ * | `clusterTol` | `number`? | Radius bin size for the histogram (default `0.1`) |
638
+ */
639
+ export const PluginCadArcClassifyOptions = z.object({
640
+ radiusRange: z
641
+ .tuple([z.number().positive(), z.number().positive()])
642
+ .default([3, 5.4]),
643
+ sweepRangeDeg: z
644
+ .tuple([z.number().positive(), z.number().positive()])
645
+ .default([60, 120]),
646
+ clusterTol: z.number().positive().default(0.1),
647
+ })
648
+ export type PluginCadArcClassifyOptions = z.input<
649
+ typeof PluginCadArcClassifyOptions
650
+ >
651
+
652
+ /** Arguments for {@link PluginCoreIoUnderlayApi.classifyArcs}. */
653
+ export const PluginCadArcClassifyArgs = z.object({
654
+ underlay: UnderlayHandle,
655
+ layer: z.string(),
656
+ options: PluginCadArcClassifyOptions.default({
657
+ radiusRange: [3, 5.4],
658
+ sweepRangeDeg: [60, 120],
659
+ clusterTol: 0.1,
660
+ }),
661
+ })
662
+ export type PluginCadArcClassifyArgs = z.infer<typeof PluginCadArcClassifyArgs>
663
+
664
+ /**
665
+ * One door candidate read from a CAD swing arc. `hinge` is the arc centre,
666
+ * `leafWidth` the arc radius, `swingDir` the unit direction from hinge toward
667
+ * the open leaf, `wallDir` the unit direction of the hosting wall (hinge →
668
+ * closed-leaf chord end). `openingWidth` equals `leafWidth` for singles and
669
+ * `2 × leafWidth` for doubles.
670
+ */
671
+ export const PluginCadDoorCandidate = z.object({
672
+ hinge: PluginPlanPoint,
673
+ leafWidth: z.number(),
674
+ swingDir: PluginPlanPoint,
675
+ wallDir: PluginPlanPoint,
676
+ openingWidth: z.number(),
677
+ double: z.boolean(),
678
+ })
679
+ export type PluginCadDoorCandidate = z.infer<typeof PluginCadDoorCandidate>
680
+
681
+ /** Result of {@link PluginCoreIoUnderlayApi.classifyArcs}. */
682
+ export const PluginCadArcClassifyResult = z.object({
683
+ layer: z.string(),
684
+ coordinateSpace: z.literal("snaptrude-world"),
685
+ units: z.literal("snaptrude-internal"),
686
+ doors: z.array(PluginCadDoorCandidate),
687
+ rejected: z.array(
688
+ z.object({
689
+ centre: PluginPlanPoint,
690
+ radius: z.number(),
691
+ sweepDeg: z.number(),
692
+ reason: z.string(),
693
+ }),
694
+ ),
695
+ radiusHistogram: z.array(
696
+ z.object({ radius: z.number(), count: z.number().int().positive() }),
697
+ ),
698
+ stats: z.object({
699
+ curvesRead: z.number().int().nonnegative(),
700
+ arcsConsidered: z.number().int().nonnegative(),
701
+ }),
702
+ })
703
+ export type PluginCadArcClassifyResult = z.infer<
704
+ typeof PluginCadArcClassifyResult
705
+ >
@@ -1041,8 +1041,107 @@ export abstract class PluginDesignQueryApi {
1041
1041
  public abstract getBoundingBox(
1042
1042
  components: ComponentHandle[],
1043
1043
  ): PluginApiReturn<BBoxComponents | null>
1044
+
1045
+ /**
1046
+ * Compute the plan **outline of what is built on a storey** — the union of
1047
+ * the storey's wall (by default) footprints as polygons-with-holes. This is
1048
+ * the footprint-from-the-built-model query: by the time slabs are needed the
1049
+ * walls exist, and the engine's own solids (snapped, joined and mitred at
1050
+ * creation) are the cleanest wall network available — no CAD re-tracing.
1051
+ *
1052
+ * Semantics: the union of wall solids is the wall *material* — a ring-shaped
1053
+ * polygon. The **outer ring is the OUTSIDE wall face** (the slab boundary);
1054
+ * every enclosed region — rooms AND courtyards — appears as a hole. When the
1055
+ * largest hole is ~zero the walls don't enclose anything: the footprint
1056
+ * reports `enclosed: false` (an open wall network), never a garbage outline.
1057
+ * Detached buildings come back as separate footprints.
1058
+ *
1059
+ * A read — nothing is created. Feed a footprint's `outline` to
1060
+ * `core.geom.create.profileFromLinePoints` → `design.create.slab` to build
1061
+ * the floor/roof plate. Coordinates are world-space plan (x, z) in Snaptrude
1062
+ * internal units; `areaSq` values are in squared internal units.
1063
+ *
1064
+ * @param options - storey / included kinds / debris filter; see
1065
+ * {@linkcode PluginStoreyOutlineOptions}.
1066
+ * @returns the storey's footprints (possibly several for detached buildings)
1067
+ * plus pieces discarded by `minArea` (`footprints: []` when nothing matches).
1068
+ *
1069
+ * @examplePrompt What is the building footprint on the ground floor?
1070
+ * @examplePrompt Create a floor slab covering the whole storey
1071
+ * @examplePrompt Get the outline of the walls on storey 1
1072
+ * @examplePrompt How much area do the ground-floor walls enclose?
1073
+ *
1074
+ * # Example
1075
+ * ```ts
1076
+ * const r = await snaptrude.design.query.storeyOutline({ storey: 1 })
1077
+ * const main = r.footprints.find((f) => f.enclosed)
1078
+ * if (main) {
1079
+ * const profile = await snaptrude.core.geom.create.profileFromLinePoints(
1080
+ * main.outline.map((p) => ({ x: p.x, y: 0, z: p.z })),
1081
+ * )
1082
+ * // → design.create.slab with the profile's contour
1083
+ * }
1084
+ * ```
1085
+ */
1086
+ public abstract storeyOutline(
1087
+ options?: PluginStoreyOutlineOptions,
1088
+ ): PluginApiReturn<PluginStoreyOutlineResult>
1044
1089
  }
1045
1090
 
1091
+
1092
+ /** A point in the world-space plan (x, z) projection, Snaptrude internal units. */
1093
+ export const PluginOutlinePlanPoint = z.object({ x: z.number(), z: z.number() })
1094
+ export type PluginOutlinePlanPoint = z.infer<typeof PluginOutlinePlanPoint>
1095
+
1096
+ /**
1097
+ * Options for {@link PluginDesignQueryApi.storeyOutline}.
1098
+ *
1099
+ * | Property | Type | Description |
1100
+ * |---|---|---|
1101
+ * | `storey` | `number`? | Only components on this storey (default: all storeys) |
1102
+ * | `include` | {@link PluginEntityType}`[]`? | Component kinds to union (default `["wall"]`) |
1103
+ * | `minArea` | `number`? | Drop union pieces below this plan area, squared internal units (default `1`) |
1104
+ */
1105
+ export const PluginStoreyOutlineOptions = z.object({
1106
+ storey: z.number().int().optional(),
1107
+ include: z.array(PluginEntityType).nonempty().default(["wall"]),
1108
+ minArea: z.number().nonnegative().default(1),
1109
+ })
1110
+ export type PluginStoreyOutlineOptions = z.input<
1111
+ typeof PluginStoreyOutlineOptions
1112
+ >
1113
+
1114
+ /**
1115
+ * One connected footprint from {@link PluginDesignQueryApi.storeyOutline}.
1116
+ * `outline` traces the OUTSIDE wall face; `holes` are the enclosed regions
1117
+ * (rooms and courtyards). `enclosed` is `false` when the wall network does not
1118
+ * close around any region (open C-shape) — don't slab an unenclosed outline
1119
+ * without checking it.
1120
+ */
1121
+ export const PluginStoreyFootprint = z.object({
1122
+ outline: z.array(PluginOutlinePlanPoint),
1123
+ holes: z.array(
1124
+ z.object({
1125
+ ring: z.array(PluginOutlinePlanPoint),
1126
+ areaSq: z.number().nonnegative(),
1127
+ }),
1128
+ ),
1129
+ areaSq: z.number().nonnegative(),
1130
+ enclosed: z.boolean(),
1131
+ })
1132
+ export type PluginStoreyFootprint = z.infer<typeof PluginStoreyFootprint>
1133
+
1134
+ /** Result of {@link PluginDesignQueryApi.storeyOutline}. */
1135
+ export const PluginStoreyOutlineResult = z.object({
1136
+ footprints: z.array(PluginStoreyFootprint),
1137
+ discarded: z.array(
1138
+ z.object({ areaSq: z.number().nonnegative(), reason: z.string() }),
1139
+ ),
1140
+ })
1141
+ export type PluginStoreyOutlineResult = z.infer<
1142
+ typeof PluginStoreyOutlineResult
1143
+ >
1144
+
1046
1145
  export * from "./geometry"
1047
1146
  export * from "./spaces"
1048
1147
  export * from "./referenceLines"