Skip to main content

ifc_geometry/lower/
swept.rs

1//! Exact swept-solid lowering into the format-neutral geometry DAG.
2//!
3//! Each family has two entry points. The `_node` form appends into a caller-
4//! owned [`LoweringSession`] and returns a [`NodeId`], so a composite parent
5//! (boolean, mapped item, CSG) can reference the result. The non-`_node` form
6//! is the convenience wrapper that opens a session, lowers one item, and
7//! freezes the graph.
8
9use axiolid_core::{Point3, Vec3};
10use axiolid_model::{GeometryNode, Instance, NodeId, Section, SolidOperation};
11use ifc_model::{EntityId, Model};
12
13use crate::error::{GeometryError, GeometryResult};
14use crate::lower::curve::{lower_curve_node, lower_sweep_directrix};
15use crate::lower::session::LoweringSession;
16use crate::lower::{lower_profile_node, LoweredGeometry};
17use crate::resource::placement::axis_placement_transform;
18use crate::slots::Slots;
19use crate::solid::swept::area::{ExtrudedAreaSolidTapered, RevolvedAreaSolidTapered};
20use crate::solid::swept::directrix::{FixedReferenceSweptAreaSolid, SectionedSpine};
21use crate::solid::swept::TrimMeasure;
22use crate::transform::Transform;
23use crate::units::UnitScale;
24
25pub(crate) mod slot {
26    pub const SWEPT_AREA: usize = 0;
27    pub const POSITION: usize = 1;
28    pub const EXTRUDED_DIRECTION: usize = 2;
29    pub const DEPTH: usize = 3;
30    pub const AXIS: usize = 2;
31    pub const ANGLE: usize = 3;
32}
33
34/// Family label used for memoization and chain diagnostics.
35const EXTRUSION: &str = "extruded area solid";
36/// Family label used for memoization and chain diagnostics.
37const REVOLUTION: &str = "revolved area solid";
38/// Memo/chain kind for `IfcExtrudedAreaSolidTapered`.
39const TAPERED_EXTRUSION: &str = "tapered extruded area solid";
40/// Memo/chain kind for `IfcRevolvedAreaSolidTapered`.
41const TAPERED_REVOLUTION: &str = "tapered revolved area solid";
42/// Memo/chain kind for `IfcFixedReferenceSweptAreaSolid`.
43const FIXED_REFERENCE: &str = "fixed reference swept area solid";
44/// Memo/chain kind for `IfcDirectrixDerivedReferenceSweptAreaSolid`.
45const DIRECTRIX_DERIVED: &str = "directrix derived reference swept area solid";
46/// IFC type of the fixed-reference sweep, named in its refusals.
47const FIXED_REFERENCE_TYPE: &str = "IFCFIXEDREFERENCESWEPTAREASOLID";
48/// IFC type of the IFC4X3 directrix-derived sweep, named in its refusals.
49const DIRECTRIX_DERIVED_TYPE: &str = "IFCDIRECTRIXDERIVEDREFERENCESWEPTAREASOLID";
50/// Memo/chain kind for `IfcSectionedSpine`.
51const SECTIONED_SPINE: &str = "sectioned spine";
52
53/// Lower one `IfcExtrudedAreaSolid` into an exact profile plus extrusion node.
54pub fn lower_extruded_area_solid(
55    model: &Model,
56    id: EntityId,
57    world: Transform,
58    units: &UnitScale,
59) -> GeometryResult<LoweredGeometry> {
60    let mut session = LoweringSession::new(model, units);
61    let root = lower_extruded_area_solid_node(&mut session, id, world)?;
62    session.finish(root)
63}
64
65/// Lower one `IfcRevolvedAreaSolid` into an exact profile plus revolution node.
66pub fn lower_revolved_area_solid(
67    model: &Model,
68    id: EntityId,
69    world: Transform,
70    units: &UnitScale,
71) -> GeometryResult<LoweredGeometry> {
72    let mut session = LoweringSession::new(model, units);
73    let root = lower_revolved_area_solid_node(&mut session, id, world)?;
74    session.finish(root)
75}
76
77/// Append one `IfcExtrudedAreaSolid` to a shared session.
78pub fn lower_extruded_area_solid_node(
79    session: &mut LoweringSession<'_>,
80    id: EntityId,
81    world: Transform,
82) -> GeometryResult<NodeId> {
83    if let Some(node) = session.memoized(id, EXTRUSION, world) {
84        return Ok(node);
85    }
86    session.enter(id, "swept solid")?;
87    let result = extrusion_node(session, id, world);
88    session.exit(id);
89    let node = result?;
90    session.memoize(id, EXTRUSION, world, node);
91    Ok(node)
92}
93
94/// Append one `IfcRevolvedAreaSolid` to a shared session.
95pub fn lower_revolved_area_solid_node(
96    session: &mut LoweringSession<'_>,
97    id: EntityId,
98    world: Transform,
99) -> GeometryResult<NodeId> {
100    if let Some(node) = session.memoized(id, REVOLUTION, world) {
101        return Ok(node);
102    }
103    session.enter(id, "swept solid")?;
104    let result = revolution_node(session, id, world);
105    session.exit(id);
106    let node = result?;
107    session.memoize(id, REVOLUTION, world, node);
108    Ok(node)
109}
110
111/// Append one `IfcExtrudedAreaSolidTapered` to a shared session.
112pub fn lower_tapered_extrusion_node(
113    session: &mut LoweringSession<'_>,
114    id: EntityId,
115    world: Transform,
116) -> GeometryResult<NodeId> {
117    if let Some(node) = session.memoized(id, TAPERED_EXTRUSION, world) {
118        return Ok(node);
119    }
120    session.enter(id, "swept solid")?;
121    let result = tapered_extrusion_node(session, id, world);
122    session.exit(id);
123    let node = result?;
124    session.memoize(id, TAPERED_EXTRUSION, world, node);
125    Ok(node)
126}
127
128/// Append one `IfcRevolvedAreaSolidTapered` to a shared session.
129pub fn lower_tapered_revolution_node(
130    session: &mut LoweringSession<'_>,
131    id: EntityId,
132    world: Transform,
133) -> GeometryResult<NodeId> {
134    if let Some(node) = session.memoized(id, TAPERED_REVOLUTION, world) {
135        return Ok(node);
136    }
137    session.enter(id, "swept solid")?;
138    let result = tapered_revolution_node(session, id, world);
139    session.exit(id);
140    let node = result?;
141    session.memoize(id, TAPERED_REVOLUTION, world, node);
142    Ok(node)
143}
144
145/// Append one `IfcFixedReferenceSweptAreaSolid` to a shared session.
146pub fn lower_fixed_reference_sweep_node(
147    session: &mut LoweringSession<'_>,
148    id: EntityId,
149    world: Transform,
150) -> GeometryResult<NodeId> {
151    if let Some(node) = session.memoized(id, FIXED_REFERENCE, world) {
152        return Ok(node);
153    }
154    session.enter(id, "swept solid")?;
155    let result = fixed_reference_sweep_node(session, id, world, FIXED_REFERENCE_TYPE);
156    session.exit(id);
157    let node = result?;
158    session.memoize(id, FIXED_REFERENCE, world, node);
159    Ok(node)
160}
161
162/// Append one IFC4X3 `IfcDirectrixDerivedReferenceSweptAreaSolid`.
163///
164/// IFC4.3 defines it as behaving exactly like its supertype
165/// `IfcFixedReferenceSweptAreaSolid` "except when the Directrix not only
166/// defines a tangent direction but a tangent plane for each point on the
167/// curve", for example an `IfcSegmentedReferenceCurve`, where the tangent
168/// plane's change in Y direction is added to the fixed reference. So:
169///
170/// - a directrix that defines only a tangent lowers to the same exact
171///   `FixedReferenceSweep` its supertype does;
172/// - a directrix that defines a tangent plane is refused as
173///   [`crate::GeometryError::Unsupported`] with
174///   [`DIRECTRIX_DERIVED_TANGENT_PLANE`]: the neutral `FixedReferenceSweep`
175///   carries one constant reference direction and no law that rotates it
176///   with the directrix's own frame, and composing that rotation here would
177///   mean evaluating the curve.
178///
179/// Which directrices count: the directrix, or anything it references at any
180/// depth, is a segment-built curve (`IfcCurveSegment`, `IfcGradientCurve`,
181/// `IfcSegmentedReferenceCurve`, `IfcOffsetCurveByDistances`) or a curve on a
182/// surface.
183pub fn lower_directrix_derived_reference_sweep_node(
184    session: &mut LoweringSession<'_>,
185    id: EntityId,
186    world: Transform,
187) -> GeometryResult<NodeId> {
188    if let Some(node) = session.memoized(id, DIRECTRIX_DERIVED, world) {
189        return Ok(node);
190    }
191    session.enter(id, "swept solid")?;
192    let result = directrix_derived_reference_sweep_node(session, id, world);
193    session.exit(id);
194    let node = result?;
195    session.memoize(id, DIRECTRIX_DERIVED, world, node);
196    Ok(node)
197}
198
199/// Why an `IfcDirectrixDerivedReferenceSweptAreaSolid` is refused: the
200/// reason the dispatch registry states for its refused variant.
201pub const DIRECTRIX_DERIVED_TANGENT_PLANE: &str =
202    "kernel: the directrix defines a tangent plane (it is built from \
203     IfcCurveSegment placements or lies on a surface), so the derived \
204     reference adds that plane's rotation to FixedReference; the neutral \
205     FixedReferenceSweep carries only a constant reference direction";
206
207/// Curve families that give every point a tangent PLANE, not only a tangent.
208///
209/// `IfcCurveSegment` places its parent curve by an `IfcPlacement`, so a curve
210/// built from segments (`IfcGradientCurve`, `IfcSegmentedReferenceCurve`, an
211/// IFC4X3 `IfcCompositeCurve` of curve segments) carries the segment frame,
212/// cant included. A curve on a surface carries the surface's tangent plane.
213/// `IfcOffsetCurveByDistances` is positioned in its basis curve's frame.
214const TANGENT_PLANE_CURVES: &[&str] = &[
215    "IFCCURVESEGMENT",
216    "IFCGRADIENTCURVE",
217    "IFCSEGMENTEDREFERENCECURVE",
218    "IFCOFFSETCURVEBYDISTANCES",
219    "IFCPCURVE",
220    "IFCSURFACECURVE",
221    "IFCINTERSECTIONCURVE",
222    "IFCSEAMCURVE",
223    "IFCCOMPOSITECURVEONSURFACE",
224    "IFCBOUNDARYCURVE",
225    "IFCOUTERBOUNDARYCURVE",
226];
227
228/// Does this directrix define a tangent plane at each point?
229///
230/// Conservative by construction: true when the directrix, or anything it
231/// references at any depth, is one of [`TANGENT_PLANE_CURVES`]. A trimmed or
232/// composite curve over a segment-built basis is therefore caught, and a
233/// directrix this cannot classify is refused rather than assumed tangent-only.
234/// The walk keeps a visited set, so a reference cycle terminates.
235pub(crate) fn defines_tangent_plane(model: &Model, directrix: EntityId) -> bool {
236    let mut visited = std::collections::BTreeSet::new();
237    let mut pending = vec![directrix];
238    while let Some(id) = pending.pop() {
239        if !visited.insert(id) {
240            continue;
241        }
242        let Some(entity) = model.get(id) else {
243            continue;
244        };
245        if TANGENT_PLANE_CURVES.iter().any(|name| entity.is_type(name)) {
246            return true;
247        }
248        pending.extend(entity.references());
249    }
250    false
251}
252
253/// Append one `IfcSectionedSpine` to a shared session.
254pub fn lower_sectioned_spine_node(
255    session: &mut LoweringSession<'_>,
256    id: EntityId,
257    world: Transform,
258) -> GeometryResult<NodeId> {
259    if let Some(node) = session.memoized(id, SECTIONED_SPINE, world) {
260        return Ok(node);
261    }
262    session.enter(id, "sectioned spine")?;
263    let result = sectioned_spine_node(session, id, world);
264    session.exit(id);
265    let node = result?;
266    session.memoize(id, SECTIONED_SPINE, world, node);
267    Ok(node)
268}
269
270fn extrusion_node(
271    session: &mut LoweringSession<'_>,
272    id: EntityId,
273    world: Transform,
274) -> GeometryResult<NodeId> {
275    let model = session.model();
276    let units = session.units();
277    let entity = session.entity(id, id)?;
278    let slots = Slots::new(id, entity);
279
280    let profile_ref = slots.req_ref(slot::SWEPT_AREA, "SweptArea")?;
281    let depth = units.length(slots.req_f64(slot::DEPTH, "Depth")?);
282    if depth <= 0.0 {
283        return Err(slots.degenerate("extrusion depth is not positive"));
284    }
285    let direction = Vec3::from_array(direction_ratios(
286        model,
287        slots.req_ref(slot::EXTRUDED_DIRECTION, "ExtrudedDirection")?,
288    )?);
289    let placement = compose_placement(model, &slots, world, units)?.to_geom();
290
291    let profile = lower_profile_node(session, profile_ref)?;
292    let operation = session.node_for(
293        id,
294        GeometryNode::SolidOperation(SolidOperation::Extrusion {
295            profile,
296            direction,
297            depth,
298        }),
299    )?;
300    session.node_for(
301        id,
302        GeometryNode::Instance(Instance {
303            source: operation,
304            transform: placement,
305        }),
306    )
307}
308
309fn revolution_node(
310    session: &mut LoweringSession<'_>,
311    id: EntityId,
312    world: Transform,
313) -> GeometryResult<NodeId> {
314    let model = session.model();
315    let units = session.units();
316    let entity = session.entity(id, id)?;
317    let slots = Slots::new(id, entity);
318
319    let profile_ref = slots.req_ref(slot::SWEPT_AREA, "SweptArea")?;
320    let angle = units.angle(id, slots.req_f64(slot::ANGLE, "Angle")?)?;
321    if angle <= 0.0 {
322        return Err(slots.degenerate("revolution angle is not positive"));
323    }
324
325    let axis_id = slots.req_ref(slot::AXIS, "Axis")?;
326    let axis = session.entity(id, axis_id)?;
327    let axis_slots = Slots::new(axis_id, axis);
328    let axis_origin = Point3::from_array(point_coords(
329        model,
330        axis_slots.req_ref(0, "Location")?,
331        units,
332    )?);
333    let axis_direction = Vec3::from_array(match axis_slots.opt_ref(1) {
334        Some(direction) => direction_ratios(model, direction)?,
335        None => [0.0, 0.0, 1.0],
336    });
337    let placement = compose_placement(model, &slots, world, units)?.to_geom();
338
339    let profile = lower_profile_node(session, profile_ref)?;
340    let operation = session.node_for(
341        id,
342        GeometryNode::SolidOperation(SolidOperation::Revolution {
343            profile,
344            axis_origin,
345            axis_direction,
346            angle,
347        }),
348    )?;
349    session.node_for(
350        id,
351        GeometryNode::Instance(Instance {
352            source: operation,
353            transform: placement,
354        }),
355    )
356}
357
358fn compose_placement(
359    model: &Model,
360    slots: &Slots<'_>,
361    world: Transform,
362    units: &UnitScale,
363) -> GeometryResult<Transform> {
364    match slots.opt_ref(slot::POSITION) {
365        Some(position_id) => {
366            let position = model.get(position_id).ok_or(GeometryError::MissingEntity {
367                referrer: slots.id(),
368                missing: position_id,
369            })?;
370            let local = to_metres(
371                axis_placement_transform(model, position_id, position)?,
372                units,
373            );
374            Ok(world.compose(&local))
375        }
376        None => Ok(world),
377    }
378}
379
380fn to_metres(transform: Transform, units: &UnitScale) -> Transform {
381    transform.to_metres(units)
382}
383
384fn direction_ratios(model: &Model, id: EntityId) -> GeometryResult<[f64; 3]> {
385    let entity = model.get(id).ok_or(GeometryError::MissingEntity {
386        referrer: id,
387        missing: id,
388    })?;
389    let slots = Slots::new(id, entity);
390    let ratios = slots.req_f64_list(0, "DirectionRatios")?;
391    match ratios.as_slice() {
392        [x, y] => Ok([*x, *y, 0.0]),
393        [x, y, z] => Ok([*x, *y, *z]),
394        _ => Err(slots.degenerate("direction must have 2 or 3 ratios")),
395    }
396}
397
398fn point_coords(model: &Model, id: EntityId, units: &UnitScale) -> GeometryResult<[f64; 3]> {
399    let entity = model.get(id).ok_or(GeometryError::MissingEntity {
400        referrer: id,
401        missing: id,
402    })?;
403    let slots = Slots::new(id, entity);
404    let coordinates = slots.req_f64_list(0, "Coordinates")?;
405    match coordinates.as_slice() {
406        [x, y] => Ok([units.length(*x), units.length(*y), 0.0]),
407        [x, y, z] => Ok([units.length(*x), units.length(*y), units.length(*z)]),
408        _ => Err(slots.degenerate("point must have 2 or 3 coordinates")),
409    }
410}
411
412/// Lower an `IfcExtrudedAreaSolidTapered` into a `TaperedExtrusion`.
413///
414/// The end profile is the whole point: reusing `SweptArea` for both ends
415/// yields a prism that builds, renders, and silently discards the taper.
416fn tapered_extrusion_node(
417    session: &mut LoweringSession<'_>,
418    id: EntityId,
419    world: Transform,
420) -> GeometryResult<NodeId> {
421    let model = session.model();
422    let units = session.units();
423    let entity = session.entity(id, id)?;
424    let slots = Slots::new(id, entity);
425    let view = ExtrudedAreaSolidTapered::new(id, entity);
426
427    let start_ref = slots.req_ref(slot::SWEPT_AREA, "SweptArea")?;
428    let end_ref = view.end_swept_area()?;
429    let depth = units.length(slots.req_f64(slot::DEPTH, "Depth")?);
430    if depth <= 0.0 {
431        return Err(slots.degenerate("extrusion depth is not positive"));
432    }
433    let direction = Vec3::from_array(direction_ratios(
434        model,
435        slots.req_ref(slot::EXTRUDED_DIRECTION, "ExtrudedDirection")?,
436    )?);
437    let placement = compose_placement(model, &slots, world, units)?.to_geom();
438
439    let start_profile = lower_profile_node(session, start_ref)?;
440    let end_profile = lower_profile_node(session, end_ref)?;
441    let operation = session.node_for(
442        id,
443        GeometryNode::SolidOperation(SolidOperation::TaperedExtrusion {
444            start_profile,
445            end_profile,
446            direction,
447            depth,
448        }),
449    )?;
450    session.node_for(
451        id,
452        GeometryNode::Instance(Instance {
453            source: operation,
454            transform: placement,
455        }),
456    )
457}
458
459/// Lower an `IfcRevolvedAreaSolidTapered` into a `TaperedRevolution`.
460fn tapered_revolution_node(
461    session: &mut LoweringSession<'_>,
462    id: EntityId,
463    world: Transform,
464) -> GeometryResult<NodeId> {
465    let model = session.model();
466    let units = session.units();
467    let entity = session.entity(id, id)?;
468    let slots = Slots::new(id, entity);
469    let view = RevolvedAreaSolidTapered::new(id, entity);
470
471    let start_ref = slots.req_ref(slot::SWEPT_AREA, "SweptArea")?;
472    let end_ref = view.end_swept_area()?;
473    // Angle is an IfcPlaneAngleMeasure in the file's declared unit, very often
474    // degrees. units.angle applies that conversion exactly once.
475    let angle = units.angle(id, slots.req_f64(slot::ANGLE, "Angle")?)?;
476    if angle <= 0.0 {
477        return Err(slots.degenerate("revolution angle is not positive"));
478    }
479
480    let axis_id = slots.req_ref(slot::AXIS, "Axis")?;
481    let axis = session.entity(id, axis_id)?;
482    let axis_slots = Slots::new(axis_id, axis);
483    let axis_origin = Point3::from_array(point_coords(
484        model,
485        axis_slots.req_ref(0, "Location")?,
486        units,
487    )?);
488    let axis_direction = Vec3::from_array(match axis_slots.opt_ref(1) {
489        Some(direction) => direction_ratios(model, direction)?,
490        None => [0.0, 0.0, 1.0],
491    });
492    let placement = compose_placement(model, &slots, world, units)?.to_geom();
493
494    let start_profile = lower_profile_node(session, start_ref)?;
495    let end_profile = lower_profile_node(session, end_ref)?;
496    let operation = session.node_for(
497        id,
498        GeometryNode::SolidOperation(SolidOperation::TaperedRevolution {
499            start_profile,
500            end_profile,
501            axis_origin,
502            axis_direction,
503            angle,
504        }),
505    )?;
506    session.node_for(
507        id,
508        GeometryNode::Instance(Instance {
509            source: operation,
510            transform: placement,
511        }),
512    )
513}
514
515/// A directrix sweep's trim as parameters in the directrix's own space.
516///
517/// An IFC4X3 trim may be an `IfcLengthMeasure`, a distance along the
518/// directrix (#210). Turning that into the directrix's parameter needs its
519/// arc length, which is evaluation, not lowering; and the kernel's range is a
520/// parameter range. A length trim is therefore refused as `Unsupported`,
521/// never passed on as if it were a parameter.
522pub(crate) fn directrix_parameter_trims(
523    session: &LoweringSession<'_>,
524    sweep: EntityId,
525    sweep_type: &str,
526    start: Option<TrimMeasure>,
527    end: Option<TrimMeasure>,
528) -> GeometryResult<(Option<f64>, Option<f64>)> {
529    let parameter = |trim: Option<TrimMeasure>| match trim {
530        None => Ok(None),
531        Some(TrimMeasure::Parameter(value)) => Ok(Some(value)),
532        Some(_) => Err(session.unsupported(
533            sweep,
534            sweep_type,
535            "an IfcLengthMeasure StartParam/EndParam is a distance along the directrix; \
536             lowering takes curve parameters and does not evaluate arc length",
537        )),
538    };
539    Ok((parameter(start)?, parameter(end)?))
540}
541
542/// Lower an `IfcFixedReferenceSweptAreaSolid` into a `FixedReferenceSweep`.
543///
544/// The fixed reference is what distinguishes this from an ordinary directrix
545/// sweep: the section keeps a constant orientation relative to that direction
546/// instead of rotating with the curve's Frenet frame. Dropping it produces a
547/// sweep that twists through bends.
548fn fixed_reference_sweep_node(
549    session: &mut LoweringSession<'_>,
550    id: EntityId,
551    world: Transform,
552    sweep_type: &str,
553) -> GeometryResult<NodeId> {
554    let model = session.model();
555    let units = session.units();
556    let entity = session.entity(id, id)?;
557    let slots = Slots::new(id, entity);
558    let view = FixedReferenceSweptAreaSolid::new(id, entity);
559
560    let profile_ref = slots.req_ref(slot::SWEPT_AREA, "SweptArea")?;
561    let reference_direction = Vec3::from_array(direction_ratios(model, view.fixed_reference()?)?);
562    let placement = compose_placement(model, &slots, world, units)?.to_geom();
563
564    // StartParam/EndParam live in the DIRECTRIX's parameterisation: an angle
565    // on a conic, the accumulated parametric length on a composite. Same rule
566    // as IfcSweptDiskSolid; see lower_sweep_directrix.
567    let (start, end) = directrix_parameter_trims(
568        session,
569        id,
570        sweep_type,
571        view.start_param()?,
572        view.end_param()?,
573    )?;
574    let (directrix, parameter_range) = lower_sweep_directrix(
575        session,
576        id,
577        sweep_type,
578        view.directrix()?,
579        world,
580        start,
581        end,
582    )?;
583
584    let profile = lower_profile_node(session, profile_ref)?;
585    let operation = session.node_for(
586        id,
587        GeometryNode::SolidOperation(SolidOperation::FixedReferenceSweep {
588            profile,
589            directrix,
590            reference_direction,
591            parameter_range,
592        }),
593    )?;
594    session.node_for(
595        id,
596        GeometryNode::Instance(Instance {
597            source: operation,
598            transform: placement,
599        }),
600    )
601}
602
603/// Lower an `IfcDirectrixDerivedReferenceSweptAreaSolid` whose directrix
604/// defines only a tangent, exactly as its supertype; refuse the rest.
605///
606/// The attribute layout is the supertype's: the subtype declares nothing.
607fn directrix_derived_reference_sweep_node(
608    session: &mut LoweringSession<'_>,
609    id: EntityId,
610    world: Transform,
611) -> GeometryResult<NodeId> {
612    let entity = session.entity(id, id)?;
613    let directrix = FixedReferenceSweptAreaSolid::new(id, entity).directrix()?;
614    if defines_tangent_plane(session.model(), directrix) {
615        return Err(session.unsupported(
616            id,
617            DIRECTRIX_DERIVED_TYPE,
618            DIRECTRIX_DERIVED_TANGENT_PLANE,
619        ));
620    }
621    fixed_reference_sweep_node(session, id, world, DIRECTRIX_DERIVED_TYPE)
622}
623
624/// Lower an `IfcSectionedSpine` into a `SectionedSpine`.
625///
626/// # No Position to compose
627///
628/// Unlike the swept-area family this subtypes `IfcGeometricRepresentationItem`
629/// directly: there is no inherited `Position`, so the world frame applies to
630/// the spine curve and each section placement rather than to a wrapper
631/// `Instance`.
632fn sectioned_spine_node(
633    session: &mut LoweringSession<'_>,
634    id: EntityId,
635    world: Transform,
636) -> GeometryResult<NodeId> {
637    let entity = session.entity(id, id)?;
638    let view = SectionedSpine::new(id, entity);
639
640    let spine = lower_curve_node(session, view.spine_curve()?, world)?;
641
642    // checked_sections rejects a length mismatch between CrossSections and
643    // CrossSectionPositions. A plain zip would truncate to the shorter list,
644    // producing a solid quietly missing its tail.
645    let paired = view.checked_sections()?;
646    let mut sections = Vec::with_capacity(paired.len());
647    for (profile_ref, position_ref) in paired {
648        let position = session.entity(id, position_ref)?;
649        // to_metres converts the placement ORIGIN once; the rotation basis is
650        // dimensionless and must not be scaled.
651        let placement = axis_placement_transform(session.model(), position_ref, position)?
652            .to_metres(session.units());
653        let profile = lower_profile_node(session, profile_ref)?;
654        sections.push(Section {
655            profile,
656            placement: world.compose(&placement).to_geom(),
657        });
658    }
659
660    session.node_for(
661        id,
662        GeometryNode::SolidOperation(SolidOperation::SectionedSpine { spine, sections }),
663    )
664}