ifc-lite-wasm 4.5.1

WebAssembly bindings for IFC-Lite
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use wasm_bindgen::prelude::*;

/// A single 2D polyline for symbolic representations (Plan, Annotation, FootPrint)
/// Points are stored as [x1, y1, x2, y2, ...] in 2D coordinates
#[wasm_bindgen]
pub struct SymbolicPolyline {
    express_id: u32,
    ifc_type: String,
    /// 2D points: [x1, y1, x2, y2, ...]
    points: Vec<f32>,
    /// Whether this is a closed loop
    is_closed: bool,
    /// World-Y (elevation in world meters) sampled from the placement chain
    /// or the polyline's own 3D IfcCartesianPoint Z component. Lets the JS
    /// hook bucket annotations by elevation instead of by storey id —
    /// important for files like 3DEXPERIENCE's IFC_Annotation.ifc whose
    /// IfcRelAggregates leaves storeys orphaned but encodes the elevation
    /// on each item's geometry.
    world_y: f32,
    /// Representation identifier: "Plan", "Annotation", "FootPrint", "Axis"
    rep_identifier: String,
}

#[wasm_bindgen]
impl SymbolicPolyline {
    /// Get express ID of the parent element
    #[wasm_bindgen(getter, js_name = expressId)]
    pub fn express_id(&self) -> u32 {
        self.express_id
    }

    /// Get IFC type name (e.g., "IfcDoor", "IfcWindow")
    #[wasm_bindgen(getter, js_name = ifcType)]
    pub fn ifc_type(&self) -> String {
        self.ifc_type.clone()
    }

    /// Get 2D points as Float32Array [x1, y1, x2, y2, ...]
    #[wasm_bindgen(getter)]
    pub fn points(&self) -> js_sys::Float32Array {
        js_sys::Float32Array::from(&self.points[..])
    }

    /// Get number of points
    #[wasm_bindgen(getter, js_name = pointCount)]
    pub fn point_count(&self) -> usize {
        self.points.len() / 2
    }

    /// Check if this is a closed loop
    #[wasm_bindgen(getter, js_name = isClosed)]
    pub fn is_closed(&self) -> bool {
        self.is_closed
    }

    /// Get representation identifier ("Plan", "Annotation", "FootPrint", "Axis")
    #[wasm_bindgen(getter, js_name = repIdentifier)]
    pub fn rep_identifier(&self) -> String {
        self.rep_identifier.clone()
    }

    /// World-Y elevation captured from the placement chain (or first 3D
    /// point's Z component). JS uses this as the canonical bucket key.
    #[wasm_bindgen(getter, js_name = worldY)]
    pub fn world_y(&self) -> f32 {
        self.world_y
    }
}

impl SymbolicPolyline {
    /// Create a new symbolic polyline
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        express_id: u32,
        ifc_type: String,
        points: Vec<f32>,
        is_closed: bool,
        world_y: f32,
        rep_identifier: String,
    ) -> Self {
        Self {
            express_id,
            ifc_type,
            points,
            is_closed,
            world_y,
            rep_identifier,
        }
    }
}

/// A 2D circle/arc for symbolic representations
#[wasm_bindgen]
pub struct SymbolicCircle {
    express_id: u32,
    ifc_type: String,
    /// Center point [x, y]
    center_x: f32,
    center_y: f32,
    /// Radius
    radius: f32,
    /// World-Y elevation (see SymbolicPolyline.world_y).
    world_y: f32,
    /// Start angle in radians (0 for full circle)
    start_angle: f32,
    /// End angle in radians (2*PI for full circle)
    end_angle: f32,
    /// Representation identifier
    rep_identifier: String,
}

#[wasm_bindgen]
impl SymbolicCircle {
    #[wasm_bindgen(getter, js_name = expressId)]
    pub fn express_id(&self) -> u32 {
        self.express_id
    }

    #[wasm_bindgen(getter, js_name = ifcType)]
    pub fn ifc_type(&self) -> String {
        self.ifc_type.clone()
    }

    #[wasm_bindgen(getter, js_name = centerX)]
    pub fn center_x(&self) -> f32 {
        self.center_x
    }

    #[wasm_bindgen(getter, js_name = centerY)]
    pub fn center_y(&self) -> f32 {
        self.center_y
    }

    #[wasm_bindgen(getter)]
    pub fn radius(&self) -> f32 {
        self.radius
    }

    #[wasm_bindgen(getter, js_name = startAngle)]
    pub fn start_angle(&self) -> f32 {
        self.start_angle
    }

    #[wasm_bindgen(getter, js_name = endAngle)]
    pub fn end_angle(&self) -> f32 {
        self.end_angle
    }

    #[wasm_bindgen(getter, js_name = repIdentifier)]
    pub fn rep_identifier(&self) -> String {
        self.rep_identifier.clone()
    }

    /// Check if this is a full circle
    #[wasm_bindgen(getter, js_name = isFullCircle)]
    pub fn is_full_circle(&self) -> bool {
        (self.end_angle - self.start_angle - std::f32::consts::TAU).abs() < 0.001
    }

    /// World-Y elevation captured from the placement chain.
    #[wasm_bindgen(getter, js_name = worldY)]
    pub fn world_y(&self) -> f32 {
        self.world_y
    }
}

impl SymbolicCircle {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        express_id: u32,
        ifc_type: String,
        center_x: f32,
        center_y: f32,
        radius: f32,
        world_y: f32,
        start_angle: f32,
        end_angle: f32,
        rep_identifier: String,
    ) -> Self {
        Self {
            express_id,
            ifc_type,
            center_x,
            center_y,
            radius,
            world_y,
            start_angle,
            end_angle,
            rep_identifier,
        }
    }

    /// Create a full circle
    pub fn full_circle(
        express_id: u32,
        ifc_type: String,
        center_x: f32,
        center_y: f32,
        radius: f32,
        world_y: f32,
        rep_identifier: String,
    ) -> Self {
        Self::new(
            express_id,
            ifc_type,
            center_x,
            center_y,
            radius,
            world_y,
            0.0,
            std::f32::consts::TAU,
            rep_identifier,
        )
    }
}

/// A 2D text annotation (IfcTextLiteral / IfcTextLiteralWithExtent).
///
/// Position is in the same 2D coordinate space as `SymbolicPolyline` (i.e. the
/// floor-plan / annotation overlay's local frame after applying placement +
/// RTC). The text-orientation pair `(cos, sin)` rotates the baseline from the
/// `+x` axis. Height is the IFC font height in model units, scaled by the
/// project's length-unit factor so the renderer can convert directly to world
/// units. Alignment is the IFC `BoxAlignment` string verbatim
/// (`top-left`, `center`, `bottom-right`, …) — the renderer can interpret it.
#[wasm_bindgen]
pub struct SymbolicText {
    express_id: u32,
    ifc_type: String,
    /// Anchor point on the text baseline (model units).
    x: f32,
    y: f32,
    /// Baseline orientation as a (cos, sin) pair. Defaults to (1, 0).
    dir_x: f32,
    dir_y: f32,
    /// Font height in model units (already unit-scaled). Defaults to 1.0 when
    /// IfcTextStyle isn't resolvable.
    height: f32,
    /// UTF-8 text content (decoded from IFC's `\X2\…\X0\` escape sequences).
    content: String,
    /// IFC `BoxAlignment` — empty string when absent. Renderer treats absent
    /// as `"bottom-left"`, matching the IFC default.
    alignment: String,
    /// World-Y elevation captured from the placement chain (see
    /// SymbolicPolyline.world_y for the why).
    world_y: f32,
    /// sRGB straight-alpha colour (0..1). Defaults to dark-grey when no
    /// IfcStyledItem chain resolves a colour. The grid-tag emission path
    /// uses this to render white bubble fills + black outlines + black
    /// tags out of the existing text pipeline (free billboard +
    /// screen-pixel scaling).
    color_r: f32,
    color_g: f32,
    color_b: f32,
    color_a: f32,
    /// Per-instance target screen-pixel cap height. 0 = fall back to the
    /// renderer's global default (~14 px for body text). Grid bubble fills
    /// + outlines emit at a larger value (~30 px) so the bubble stays
    /// proportional to the inscribed tag at every zoom level.
    target_px: f32,
    /// "Plan" | "Annotation" | "FootPrint" | "Axis"
    rep_identifier: String,
}

#[wasm_bindgen]
impl SymbolicText {
    #[wasm_bindgen(getter, js_name = expressId)]
    pub fn express_id(&self) -> u32 { self.express_id }
    #[wasm_bindgen(getter, js_name = ifcType)]
    pub fn ifc_type(&self) -> String { self.ifc_type.clone() }
    #[wasm_bindgen(getter)]
    pub fn x(&self) -> f32 { self.x }
    #[wasm_bindgen(getter)]
    pub fn y(&self) -> f32 { self.y }
    #[wasm_bindgen(getter, js_name = dirX)]
    pub fn dir_x(&self) -> f32 { self.dir_x }
    #[wasm_bindgen(getter, js_name = dirY)]
    pub fn dir_y(&self) -> f32 { self.dir_y }
    #[wasm_bindgen(getter)]
    pub fn height(&self) -> f32 { self.height }
    #[wasm_bindgen(getter)]
    pub fn content(&self) -> String { self.content.clone() }
    #[wasm_bindgen(getter)]
    pub fn alignment(&self) -> String { self.alignment.clone() }
    #[wasm_bindgen(getter, js_name = worldY)]
    pub fn world_y(&self) -> f32 { self.world_y }
    #[wasm_bindgen(getter, js_name = colorR)]
    pub fn color_r(&self) -> f32 { self.color_r }
    #[wasm_bindgen(getter, js_name = colorG)]
    pub fn color_g(&self) -> f32 { self.color_g }
    #[wasm_bindgen(getter, js_name = colorB)]
    pub fn color_b(&self) -> f32 { self.color_b }
    #[wasm_bindgen(getter, js_name = colorA)]
    pub fn color_a(&self) -> f32 { self.color_a }
    #[wasm_bindgen(getter, js_name = targetPx)]
    pub fn target_px(&self) -> f32 { self.target_px }
    #[wasm_bindgen(getter, js_name = repIdentifier)]
    pub fn rep_identifier(&self) -> String { self.rep_identifier.clone() }
}

impl SymbolicText {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        express_id: u32,
        ifc_type: String,
        x: f32,
        y: f32,
        dir_x: f32,
        dir_y: f32,
        height: f32,
        content: String,
        alignment: String,
        world_y: f32,
        rep_identifier: String,
    ) -> Self {
        Self::new_styled(
            express_id, ifc_type, x, y, dir_x, dir_y,
            height, content, alignment, world_y,
            [0.05, 0.05, 0.05, 1.0], // default near-black text color
            0.0,                       // 0 → renderer global default target_px
            rep_identifier,
        )
    }

    /// Full constructor with per-instance colour + screen-pixel target.
    /// Used by the grid bubble emission (white fill / black outline) and
    /// by future IfcTextStyle resolution.
    #[allow(clippy::too_many_arguments)]
    pub fn new_styled(
        express_id: u32,
        ifc_type: String,
        x: f32,
        y: f32,
        dir_x: f32,
        dir_y: f32,
        height: f32,
        content: String,
        alignment: String,
        world_y: f32,
        rgba: [f32; 4],
        target_px: f32,
        rep_identifier: String,
    ) -> Self {
        Self {
            express_id,
            ifc_type,
            x,
            y,
            dir_x,
            dir_y,
            height,
            content,
            alignment,
            world_y,
            color_r: rgba[0],
            color_g: rgba[1],
            color_b: rgba[2],
            color_a: rgba[3],
            target_px,
            rep_identifier,
        }
    }
}

/// A 2D filled region (IfcAnnotationFillArea / IfcAnnotationFillAreaOccurrence).
///
/// Stores one outer ring of 2D points plus an offset table indexing inner
/// rings (holes). Both rings are stored flat in `points` so the JS side can
/// view the buffer as one Float32Array. The optional `hatch_*` fields encode
/// IfcFillAreaStyleHatching (line spacing, primary/secondary angles, line
/// width) when the IfcStyledItem chain resolves to a hatching style; absent
/// styles render as a solid fill.
///
/// `holes_offsets` is an inclusive-prefix array describing where each hole
/// begins. The outer ring is implicitly at `points[0..holes_offsets[0]]`
/// (or all points if `holes_offsets` is empty). Each `holes_offsets[i]` is a
/// vertex index, not a byte offset.
#[wasm_bindgen]
pub struct SymbolicFillArea {
    express_id: u32,
    ifc_type: String,
    /// All ring vertices: outer ring, then each hole back-to-back. Format:
    /// [x1, y1, x2, y2, …]
    points: Vec<f32>,
    /// Inclusive prefix of where each hole begins (in vertex indices, not
    /// floats). Empty array = no holes.
    holes_offsets: Vec<u32>,
    /// Fill color (sRGB, 0..1). Defaults to opaque black when no style.
    fill_r: f32,
    fill_g: f32,
    fill_b: f32,
    fill_a: f32,
    /// Whether this fill has a hatching style applied.
    has_hatching: bool,
    /// Hatching primary line spacing in model units. Only valid when has_hatching.
    hatch_spacing: f32,
    /// Hatching primary angle in radians from the +x axis.
    hatch_angle: f32,
    /// Optional secondary angle (cross-hatching). NaN if absent.
    hatch_angle_secondary: f32,
    /// Hatching line width in model units (0 when unspecified).
    hatch_line_width: f32,
    /// World-Y elevation captured from the placement chain or the boundary
    /// curve's IfcCartesianPoint Z components (see SymbolicPolyline.world_y).
    world_y: f32,
    rep_identifier: String,
}

#[wasm_bindgen]
impl SymbolicFillArea {
    #[wasm_bindgen(getter, js_name = expressId)]
    pub fn express_id(&self) -> u32 { self.express_id }
    #[wasm_bindgen(getter, js_name = ifcType)]
    pub fn ifc_type(&self) -> String { self.ifc_type.clone() }
    /// Flattened ring vertices.
    #[wasm_bindgen(getter)]
    pub fn points(&self) -> js_sys::Float32Array {
        js_sys::Float32Array::from(&self.points[..])
    }
    #[wasm_bindgen(getter, js_name = pointCount)]
    pub fn point_count(&self) -> usize { self.points.len() / 2 }
    /// Vertex indices marking the start of each hole. Empty = no holes.
    #[wasm_bindgen(getter, js_name = holesOffsets)]
    pub fn holes_offsets(&self) -> js_sys::Uint32Array {
        js_sys::Uint32Array::from(&self.holes_offsets[..])
    }
    #[wasm_bindgen(getter, js_name = holeCount)]
    pub fn hole_count(&self) -> usize { self.holes_offsets.len() }
    #[wasm_bindgen(getter, js_name = fillR)]
    pub fn fill_r(&self) -> f32 { self.fill_r }
    #[wasm_bindgen(getter, js_name = fillG)]
    pub fn fill_g(&self) -> f32 { self.fill_g }
    #[wasm_bindgen(getter, js_name = fillB)]
    pub fn fill_b(&self) -> f32 { self.fill_b }
    #[wasm_bindgen(getter, js_name = fillA)]
    pub fn fill_a(&self) -> f32 { self.fill_a }
    #[wasm_bindgen(getter, js_name = hasHatching)]
    pub fn has_hatching(&self) -> bool { self.has_hatching }
    #[wasm_bindgen(getter, js_name = hatchSpacing)]
    pub fn hatch_spacing(&self) -> f32 { self.hatch_spacing }
    #[wasm_bindgen(getter, js_name = hatchAngle)]
    pub fn hatch_angle(&self) -> f32 { self.hatch_angle }
    #[wasm_bindgen(getter, js_name = hatchAngleSecondary)]
    pub fn hatch_angle_secondary(&self) -> f32 { self.hatch_angle_secondary }
    #[wasm_bindgen(getter, js_name = hatchLineWidth)]
    pub fn hatch_line_width(&self) -> f32 { self.hatch_line_width }
    #[wasm_bindgen(getter, js_name = worldY)]
    pub fn world_y(&self) -> f32 { self.world_y }
    #[wasm_bindgen(getter, js_name = repIdentifier)]
    pub fn rep_identifier(&self) -> String { self.rep_identifier.clone() }
}

impl SymbolicFillArea {
    #[allow(clippy::too_many_arguments)]
    pub fn new(
        express_id: u32,
        ifc_type: String,
        points: Vec<f32>,
        holes_offsets: Vec<u32>,
        fill_rgba: [f32; 4],
        world_y: f32,
        rep_identifier: String,
    ) -> Self {
        Self {
            express_id,
            ifc_type,
            points,
            holes_offsets,
            fill_r: fill_rgba[0],
            fill_g: fill_rgba[1],
            fill_b: fill_rgba[2],
            fill_a: fill_rgba[3],
            has_hatching: false,
            hatch_spacing: 0.0,
            hatch_angle: 0.0,
            hatch_angle_secondary: f32::NAN,
            hatch_line_width: 0.0,
            world_y,
            rep_identifier,
        }
    }

    /// Builder method: attach a hatching style to an existing fill area.
    pub fn with_hatching(
        mut self,
        spacing: f32,
        angle: f32,
        angle_secondary: Option<f32>,
        line_width: f32,
    ) -> Self {
        self.has_hatching = true;
        self.hatch_spacing = spacing;
        self.hatch_angle = angle;
        self.hatch_angle_secondary = angle_secondary.unwrap_or(f32::NAN);
        self.hatch_line_width = line_width;
        self
    }
}

/// Collection of symbolic representations for an IFC model
#[wasm_bindgen]
pub struct SymbolicRepresentationCollection {
    polylines: Vec<SymbolicPolyline>,
    circles: Vec<SymbolicCircle>,
    texts: Vec<SymbolicText>,
    fills: Vec<SymbolicFillArea>,
}

#[wasm_bindgen]
impl SymbolicRepresentationCollection {
    /// Get all express IDs that have symbolic representations
    #[wasm_bindgen(js_name = getExpressIds)]
    pub fn get_express_ids(&self) -> Vec<u32> {
        let mut ids: Vec<u32> = self
            .polylines
            .iter()
            .map(|p| p.express_id)
            .chain(self.circles.iter().map(|c| c.express_id))
            .chain(self.texts.iter().map(|t| t.express_id))
            .chain(self.fills.iter().map(|f| f.express_id))
            .collect();
        ids.sort_unstable();
        ids.dedup();
        ids
    }

    /// Get number of polylines
    #[wasm_bindgen(getter, js_name = polylineCount)]
    pub fn polyline_count(&self) -> usize {
        self.polylines.len()
    }

    /// Get number of circles/arcs
    #[wasm_bindgen(getter, js_name = circleCount)]
    pub fn circle_count(&self) -> usize {
        self.circles.len()
    }

    /// Get number of text annotations
    #[wasm_bindgen(getter, js_name = textCount)]
    pub fn text_count(&self) -> usize { self.texts.len() }

    /// Get number of fill areas
    #[wasm_bindgen(getter, js_name = fillCount)]
    pub fn fill_count(&self) -> usize { self.fills.len() }

    /// Get total count of all symbolic items
    #[wasm_bindgen(getter, js_name = totalCount)]
    pub fn total_count(&self) -> usize {
        self.polylines.len() + self.circles.len() + self.texts.len() + self.fills.len()
    }

    /// Check if collection is empty
    #[wasm_bindgen(getter, js_name = isEmpty)]
    pub fn is_empty(&self) -> bool {
        self.polylines.is_empty()
            && self.circles.is_empty()
            && self.texts.is_empty()
            && self.fills.is_empty()
    }

    /// Get polyline at index
    #[wasm_bindgen(js_name = getPolyline)]
    pub fn get_polyline(&self, index: usize) -> Option<SymbolicPolyline> {
        self.polylines.get(index).map(|p| SymbolicPolyline {
            express_id: p.express_id,
            ifc_type: p.ifc_type.clone(),
            points: p.points.clone(),
            is_closed: p.is_closed,
            world_y: p.world_y,
            rep_identifier: p.rep_identifier.clone(),
        })
    }

    /// Get circle at index
    #[wasm_bindgen(js_name = getCircle)]
    pub fn get_circle(&self, index: usize) -> Option<SymbolicCircle> {
        self.circles.get(index).map(|c| SymbolicCircle {
            express_id: c.express_id,
            ifc_type: c.ifc_type.clone(),
            center_x: c.center_x,
            center_y: c.center_y,
            radius: c.radius,
            world_y: c.world_y,
            start_angle: c.start_angle,
            end_angle: c.end_angle,
            rep_identifier: c.rep_identifier.clone(),
        })
    }

    /// Get text annotation at index.
    #[wasm_bindgen(js_name = getText)]
    pub fn get_text(&self, index: usize) -> Option<SymbolicText> {
        self.texts.get(index).map(|t| SymbolicText {
            express_id: t.express_id,
            ifc_type: t.ifc_type.clone(),
            x: t.x,
            y: t.y,
            dir_x: t.dir_x,
            dir_y: t.dir_y,
            height: t.height,
            content: t.content.clone(),
            alignment: t.alignment.clone(),
            world_y: t.world_y,
            color_r: t.color_r,
            color_g: t.color_g,
            color_b: t.color_b,
            color_a: t.color_a,
            target_px: t.target_px,
            rep_identifier: t.rep_identifier.clone(),
        })
    }

    /// Get fill area at index.
    #[wasm_bindgen(js_name = getFill)]
    pub fn get_fill(&self, index: usize) -> Option<SymbolicFillArea> {
        self.fills.get(index).map(|f| SymbolicFillArea {
            express_id: f.express_id,
            ifc_type: f.ifc_type.clone(),
            points: f.points.clone(),
            holes_offsets: f.holes_offsets.clone(),
            fill_r: f.fill_r,
            fill_g: f.fill_g,
            fill_b: f.fill_b,
            fill_a: f.fill_a,
            has_hatching: f.has_hatching,
            hatch_spacing: f.hatch_spacing,
            hatch_angle: f.hatch_angle,
            hatch_angle_secondary: f.hatch_angle_secondary,
            hatch_line_width: f.hatch_line_width,
            world_y: f.world_y,
            rep_identifier: f.rep_identifier.clone(),
        })
    }

}

impl SymbolicRepresentationCollection {
    pub fn new() -> Self {
        Self {
            polylines: Vec::new(),
            circles: Vec::new(),
            texts: Vec::new(),
            fills: Vec::new(),
        }
    }

    pub fn with_capacity(polyline_capacity: usize, circle_capacity: usize) -> Self {
        Self {
            polylines: Vec::with_capacity(polyline_capacity),
            circles: Vec::with_capacity(circle_capacity),
            texts: Vec::new(),
            fills: Vec::new(),
        }
    }

    pub fn add_polyline(&mut self, polyline: SymbolicPolyline) {
        self.polylines.push(polyline);
    }

    pub fn add_circle(&mut self, circle: SymbolicCircle) {
        self.circles.push(circle);
    }

    pub fn add_text(&mut self, text: SymbolicText) {
        self.texts.push(text);
    }

    pub fn add_fill(&mut self, fill: SymbolicFillArea) {
        self.fills.push(fill);
    }

    /// Convert from the canonical `ifc_lite_processing::SymbolicData`
    /// (issue #843 follow-up — full parity refactor). The WASM-side
    /// extractor now delegates to the processing crate and converts the
    /// result here so the browser and the HTTP server produce bit-
    /// identical symbol streams from one canonical implementation.
    pub fn from_data(data: ifc_lite_processing::SymbolicData) -> Self {
        let mut collection = Self::with_capacity(data.polylines.len(), data.circles.len());
        for p in data.polylines {
            collection.add_polyline(SymbolicPolyline::new(
                p.express_id,
                p.ifc_type,
                p.points,
                p.closed,
                p.world_y,
                p.representation,
            ));
        }
        for c in data.circles {
            collection.add_circle(SymbolicCircle::new(
                c.express_id,
                c.ifc_type,
                c.center_x,
                c.center_y,
                c.radius,
                c.world_y,
                c.start_angle,
                c.end_angle,
                c.representation,
            ));
        }
        for t in data.texts {
            collection.add_text(SymbolicText::new_styled(
                t.express_id,
                t.ifc_type,
                t.x,
                t.y,
                t.dir_x,
                t.dir_y,
                t.height,
                t.content,
                t.alignment,
                t.world_y,
                t.color,
                t.target_px,
                t.representation,
            ));
        }
        for f in data.fills {
            collection.add_fill(SymbolicFillArea::new(
                f.express_id,
                f.ifc_type,
                f.points,
                f.holes_offsets,
                f.fill_color,
                f.world_y,
                f.representation,
            ));
        }
        collection
    }
}

impl Default for SymbolicRepresentationCollection {
    fn default() -> Self {
        Self::new()
    }
}