Skip to main content

ifc_geometry/lower/
station.rs

1//! IFC4X3 distance-along-curve geometry onto Axiolid stations (#307).
2//!
3//! `IfcPointByDistanceExpression` (IFC4.3 ADD2 8.9.3.48) names a point by a
4//! distance along a basis curve plus three offsets; `IfcAxis2PlacementLinear`
5//! (8.9.3.4) frames one; `IfcOffsetCurveByDistances` (8.9.3.42) runs through
6//! several; `IfcSectionedSolidHorizontal` (8.8.3.35) and
7//! `IfcSectionedSurface` (8.8.3.37) stand cross sections at them. Resolving
8//! a distance to a point is curve evaluation, which this crate never does
9//! (ADR 0004): each lowers to Axiolid's station relations (`axiolid-model`
10//! 0.3.5, ADR 0082), stored exactly, which a kernel resolves.
11//!
12//! # Convention map
13//!
14//! Every row is the same in IFC4.3 ADD2 and in ADR 0082, so nothing is
15//! converted. Each is pinned by a test that resolves the lowered station
16//! through `axiolid-reference` (tests only).
17//!
18//! | IFC4.3 ADD2 | Axiolid |
19//! | --- | --- |
20//! | `DistanceAlong` as `IfcLengthMeasure`, from the basis curve's start | `Station::distance` |
21//! | on an `IfcGradientCurve`, the `BaseCurve`'s parameter: plan arc length (8.9.3.34.1 "the value of the parameter equals the parameter value of BaseCurve") | plan distance on `Curve3::Elevated` |
22//! | on any other curve, its arc length | arc length |
23//! | `OffsetLateral`, "positive values indicate to the left of the basis curve as facing in the positive parametrization direction" | `StationOffsets::lateral`, positive to the left |
24//! | `OffsetVertical`, "perpendicular to the tangent at DistanceAlong in the plane of the tangent perpendicular to the global XY plane" | `vertical` along the section up of `StationFrame::Section`: the reference-up frame, leaning back with the grade |
25//! | `OffsetLongitudinal`, "parallel to the basis curve after applying DistanceAlong, OffsetLateral, and OffsetVertical" | `longitudinal` along the tangent |
26//! | `IfcAxis2PlacementLinear` local `X`, `Y`, `Z` with `Axis`/`RefDirection` absent: the curve's tangent, left and up (8.9.3.4.1 "relative to the curve ... maintaining the relationship to the tangent") | the base frame `(tangent, lateral, up)` |
27//! | `Axis`: "the exact direction of the local Z Axis"; `RefDirection` determines local `X`, adjusted to stay orthogonal to `Axis` | `StationOrientation { axis, ref_direction }`, components in the base frame, Gram-Schmidt with the axis primary |
28//! | WR2: `Axis` and `RefDirection` not parallel | refused at push within `ORIENTATION_TOLERANCE`; checked here first and refused by name |
29//!
30//! `IfcParameterValue` distances are refused: IFC4.3 ADD2 states no
31//! parameterisation for most bases, and a station is a distance.
32//! `OffsetVertical` along the tangent-normal is contested
33//! (buildingSMART/IFC4.x-development#1151 proposes global Z); this follows
34//! the ADD2 text.
35//!
36//! # Tangent discontinuities (#346)
37//!
38//! 8.9.3.48.3, on `OffsetLateral`: "If DistanceAlong coincides with a point
39//! of tangential discontinuity (within precision limits), then the tangent
40//! of the previous segment governs." Axiolid states the same choice since
41//! `axiolid-model` 0.3.6 (ADR 0082 amendment, axiolid/kernel#263): a
42//! station carries a `SeamSide`, and `SeamSide::Incoming` reads the piece
43//! that ends at the seam. So a station on a seam is lowered at the seam's own distance with
44//! the incoming side: an `IfcAxis2PlacementLinear` as an
45//! `OrientedCurveStation` with `SeamSide::Incoming`, an
46//! `IfcPointByDistanceExpression` as the unturned oriented station
47//! `CurveStation::with_seam_side(SeamSide::Incoming)` gives (a plain
48//! `CurveStation` always reads the outgoing piece). Off a seam nothing
49//! changes. `OffsetLongitudinal`, which IFC offers "to reach locations for
50//! the case of a tangentially discontinuous basis curve", then runs along
51//! the incoming tangent.
52//!
53//! **Which stations are on a seam.** "Within precision limits" is the
54//! model's declared `Precision`, capped at 1 mm (`Basis::tolerance`; the
55//! same cap `ifc_alignment::SeamTolerance` applies), or rounding,
56//! `1e-9 * max(1, |s|)`, where that is larger. Axiolid reads a station on a
57//! seam within `ARC_LENGTH_TOLERANCE * max(1, s)` with `ARC_LENGTH_TOLERANCE
58//! = 1e-12`, a window inside ours. The two are reconciled by snapping: a
59//! station within our window is stored at the seam's distance, read from
60//! the same stored data Axiolid reads it from (`seams`), so the kernel finds
61//! it on the seam and reads the side stated. Without the snap a station
62//! 0.5 mm past a corner in a model of millimetre precision would be on the
63//! corner for IFC and on the outgoing leg for the kernel.
64//!
65//! **Runs.** Sections and offsets need no side. IFC 8.8.3.35.1: "If the
66//! directrix is not tangent continuous, the resulting solid is created by a
67//! miter at half angle between the two segments" (8.8.3.37.1 says the same
68//! of the surface), and Axiolid mitres a run across a seam in the plane normal to the bisector of the two
69//! tangents (`Mitre`, ADR 0082 amendment). A station of a run within
70//! precision of a seam is snapped to it too, so the kernel stands that
71//! section in the mitre plane instead of refusing a section the mitre would
72//! cut. "Very sharp edges may result in nearly impossible miter": a seam
73//! where the curve turns back on itself (the cosine of half the turn at most
74//! Axiolid's `MITRE_TOLERANCE`, `seams::MITRE_TOLERANCE`) inside a run is
75//! refused by name.
76//!
77//! **Relation bases.** A plain `IfcCompositeCurve`, an `IfcTrimmedCurve`
78//! and segments placed at stations lower to a curve relation, along which
79//! Axiolid measures a station end to end through its pieces since
80//! `axiolid-model` 0.3.7 (axiolid/kernel#285, ADR 0082 amendment): each
81//! piece in its own curve's convention, every joint a seam whose
82//! `SeamSide::Incoming` reads the piece that ends there, IFC's previous
83//! segment. The joints' distances are read from the stored relation
84//! (`relation`), and a station within precision of one is snapped onto it
85//! and reads that side, as on an atomic basis. A relation joining a
86//! gradient curve with arc-length pieces is refused by name; a gap or an
87//! undeclared reversed piece is refused by the kernel.
88//!
89//! **Offset bases** (#414). `IfcOffsetCurve2D`, `IfcOffsetCurve3D` and
90//! `IfcOffsetCurveByDistances` lower to `CurveRelation::Offset` and
91//! `OffsetByStations`, which Axiolid measures a station along since
92//! `axiolid-mesh-compile` 0.3.19 (axiolid/kernel#289, ADR 0082 amendment
93//! 2026-10-10): in the offset's OWN length from its start, not its basis's
94//! (the station names a place along the curve it references), one offset
95//! piece per span of the basis between its seams and, by distances, between
96//! its stations, every piece boundary a joint read by the same seam rule.
97//! IFC states an offset curve's parameterisation, "from the basis curve"
98//! (IFC4.3 ADD2 8.9.3.40.1), but not a distance along it other than its
99//! length. The joints' distances are the closed forms `relation::offset`
100//! states, and where it states none (an offset whose length is a
101//! quadrature) the kernel snaps the station (below); an offset of an
102//! offset, a trim of an offset and a collapsed circle are refused by name,
103//! and an offset across a corner of its basis,
104//! whose sides do not meet (IFC: the basis "shall have a well-defined
105//! tangent direction at every point"), is refused by the kernel.
106//!
107//! **Bases whose seams are quadratures** (#423). The seams are read from
108//! stored data, never by evaluation. Where they lie at an arc-length
109//! integral -- an offset beside a gradient curve, a spiral, a B-spline or
110//! an ellipse, a relation with an ellipse or a B-spline piece, a B-spline's
111//! corner knot -- this crate cannot place a station within precision of
112//! one, and hands the snapping to the kernel instead: the station is
113//! stored at its own distance as an `OrientedCurveStation` reading
114//! `SeamSide::Incoming`, with the window this crate snaps within (the
115//! declared precision, `Basis::tolerance`) as its seam-snapping window
116//! (`OrientedCurveStation::with_seam_window`, `axiolid-model` 0.3.9,
117//! axiolid/kernel#294, ADR 0082 amendment). Resolving it, the kernel reads
118//! a station within that window of exactly one seam whose frame may jump
119//! ON that seam, from the incoming side, at its own certified distance, and
120//! refuses by name a window holding two seams (`SEAM_WINDOW_AMBIGUOUS`), a
121//! seam whose certified position straddles its edge
122//! (`SEAM_WINDOW_STRADDLED`) and a seam it cannot certify
123//! (`UNCERTIFIED_LENGTH`); `crate::compile` names the station in a
124//! [`GeometryError::StationSeamWindowRefused`](crate::GeometryError).
125//! A station on a basis whose seams are stored data keeps the snapping
126//! above, so its graph is unchanged (no window, wire format 1.0 content).
127//!
128//! **Runs along such a basis** (#429). A run's stations carry the same
129//! window and side since `axiolid-model` 0.3.11 (axiolid/kernel#301, ADR
130//! 0082 amendment): a section of `IfcSectionedSolidHorizontal` or
131//! `IfcSectionedSurface` as `SectionAtStation::with_seam_window(w)` and
132//! `with_seam_side(SeamSide::Incoming)` (`Basis::run_place`), `w` the
133//! same `Basis::tolerance`. The kernel snaps each onto the one seam
134//! within its window, at the seam's certified distance, and reads the run
135//! at the snapped distances: an interior station snapped onto a seam
136//! where the tangent turns stands in the mitre plane (its side is not
137//! read), the first and last keep the run's own reading, and a side is
138//! read only on a seam where the tangents agree and the frame may jump.
139//! Snapped distances that no longer increase strictly are refused by the
140//! kernel by name, as are the window's own refusals; `crate::compile`
141//! names the run (`GeometryError::RunSeamWindowRefused`), which
142//! `ProvenanceMap::seam_window_runs` lists. A reversal at such a seam,
143//! which this crate cannot see, is refused by the kernel's mitre. A run
144//! along a basis whose seams are stored data keeps the snapping above and
145//! carries no window, so its graph is unchanged (wire format 1.0 content);
146//! only the runs that used to be refused carry windows (format 1.2). An
147//! `IfcOffsetCurveByDistances` along such a basis continues its offsets to
148//! the basis's end, a quadrature, which the kernel measures (`offset`,
149//! #433, `RunStation::at_basis_end`, axiolid/kernel#303; format 1.3). A
150//! station along such a run (`OffsetsAtStations`) carries the window too
151//! (#443, `relation::offset::by_stations`); the reference kernel
152//! certifies an offset law that varies along an ellipse or a B-spline
153//! since `axiolid-evaluate` 0.3.15 (axiolid/kernel#307), so such a window
154//! resolves.
155//!
156//! # Frames
157//!
158//! The basis is lowered under the item's frame, like every curve here. Only
159//! a frame that is rigid and keeps world `Z` is admitted: a scale changes
160//! the measure along the curve, a mirror swaps left and right, and a tilt
161//! moves "the global XY plane" the vertical offset is read against.
162
163use axiolid_model::{CurveStation, GeometryNode, NodeId, OrientedCurveStation, SeamSide, Station};
164use ifc_model::EntityId;
165
166use crate::error::GeometryResult;
167use crate::lower::curve::gradient::keeps_vertical;
168use crate::lower::curve::lower_curve_node;
169use crate::lower::session::LoweringSession;
170use crate::transform::Transform;
171
172pub(crate) mod axes;
173pub(crate) mod offset;
174pub(crate) mod read;
175pub(crate) mod relation;
176pub(crate) mod seams;
177#[cfg(test)]
178mod tests;
179
180/// IFC type of the point.
181pub(crate) const POINT: &str = "IFCPOINTBYDISTANCEEXPRESSION";
182/// IFC type of the linear placement.
183pub(crate) const PLACEMENT: &str = "IFCAXIS2PLACEMENTLINEAR";
184
185/// Family label used for memoization.
186const KIND: &str = "station";
187
188/// Why a frame that is not rigid and vertical is refused.
189const FRAME: &str = "a station is measured along its basis curve and offset left and up in \
190                     its frame; only a frame that is rigid and keeps world Z keeps that \
191                     measure, its left and the global XY plane the vertical offset is read \
192                     against";
193
194/// A lowered basis curve with what stations along it are checked against.
195#[derive(Debug, Clone)]
196pub(crate) struct Basis {
197    /// The basis curve's node.
198    pub node: NodeId,
199    /// Where its tangent may be discontinuous, or why that is unknown.
200    seams: Result<Vec<seams::Seam>, &'static str>,
201    /// Its length, when stated by its data; `None` when unbounded or not
202    /// stated.
203    pub length: Option<f64>,
204    /// Whether it is bounded but its length is not stated, an arc-length
205    /// integral the kernel measures (an ellipse, a B-spline, a relation
206    /// with a piece measured by quadrature): a run along it is continued
207    /// to the kernel's end (#433, `offset`).
208    pub measured_end: bool,
209    /// The model's precision in metres; see [`Basis::tolerance`].
210    precision: f64,
211}
212
213impl Basis {
214    /// Lower `curve` under `frame` as the basis of `owner`.
215    pub(crate) fn lower(
216        session: &mut LoweringSession<'_>,
217        owner: EntityId,
218        owner_type: &str,
219        curve: EntityId,
220        frame: Transform,
221    ) -> GeometryResult<Self> {
222        if !keeps_vertical(&frame) {
223            return Err(session.unsupported(owner, owner_type, FRAME));
224        }
225        let precision = seams::precision(session, owner, owner_type)?;
226        let node = lower_curve_node(session, curve, frame)?;
227        let (seams, length, measured) = match session.atomic_curve(node) {
228            Some(curve) => (
229                seams::tangent_seams(curve),
230                seams::stated_length(curve),
231                seams::measured_length(curve),
232            ),
233            None => match relation::relation_seams(session, node) {
234                Ok((seams, length)) => (Ok(seams), Some(length), false),
235                // A relation's length is stated unless a piece's is a
236                // quadrature, the reasons its stations carry a window.
237                Err(reason) => (Err(reason), None, WINDOWED.contains(&reason)),
238            },
239        };
240        if let Err(reason) = seams {
241            // Refused whatever the station: no station along such a basis
242            // resolves, or the kernel reads its frame unlike IFC.
243            if [
244                seams::BANKED,
245                relation::UNSUPPORTED,
246                relation::TOO_DEEP,
247                relation::MIXED,
248                relation::TRIM_OF_OFFSET,
249                relation::OFFSET_OF_OFFSET,
250                relation::PLANAR_3D,
251                relation::COLLAPSE,
252            ]
253            .contains(&reason)
254            {
255                return Err(session.unsupported(owner, owner_type, reason));
256            }
257        }
258        Ok(Self {
259            node,
260            seams,
261            length,
262            measured_end: length.is_none() && measured,
263            precision,
264        })
265    }
266
267    /// How far apart two distances may be and still name the same place:
268    /// the declared precision, or rounding at the distance's magnitude.
269    pub(crate) fn tolerance(&self, distance: f64) -> f64 {
270        seams::window(self.precision, distance)
271    }
272
273    /// Refuse a distance outside the curve, by name.
274    pub(crate) fn check_on_curve(
275        &self,
276        session: &LoweringSession<'_>,
277        owner: EntityId,
278        owner_type: &str,
279        distance: f64,
280    ) -> GeometryResult<()> {
281        if !distance.is_finite() || distance < 0.0 {
282            return Err(session.degenerate(
283                owner,
284                owner_type,
285                format!("DistanceAlong {distance} is before the basis curve's start"),
286            ));
287        }
288        if let Some(length) = self.length {
289            if distance > length + self.tolerance(length) {
290                return Err(session.degenerate(
291                    owner,
292                    owner_type,
293                    format!("DistanceAlong {distance} is beyond the basis curve's length {length}"),
294                ));
295            }
296        }
297        Ok(())
298    }
299
300    /// The seams, or a refusal naming why they are unknown.
301    fn known_seams(
302        &self,
303        session: &LoweringSession<'_>,
304        owner: EntityId,
305        owner_type: &str,
306    ) -> GeometryResult<&[seams::Seam]> {
307        self.seams
308            .as_deref()
309            .map_err(|why| session.unsupported(owner, owner_type, why))
310    }
311
312    /// How a station at `distance` is read (module documentation): on a
313    /// seam stated by the data, snapped to it; clear of every such seam,
314    /// as it is; on a basis whose seams are quadratures, with the kernel's
315    /// seam-snapping window.
316    fn reading(
317        &self,
318        session: &LoweringSession<'_>,
319        owner: EntityId,
320        owner_type: &str,
321        distance: f64,
322    ) -> GeometryResult<Reading> {
323        match &self.seams {
324            Ok(seams) => Ok(match seams::nearest(seams, distance, self.precision) {
325                Some(seam) => Reading::OnSeam(seam.distance),
326                None => Reading::Clear,
327            }),
328            Err(reason) if WINDOWED.contains(reason) => {
329                Ok(Reading::Window(self.tolerance(distance)))
330            }
331            Err(reason) => Err(session.unsupported(owner, owner_type, reason)),
332        }
333    }
334
335    /// Where a station of a run is stored (module documentation): at the
336    /// seam's own distance when it lies on one the data states, so the
337    /// kernel stands its section in the mitre plane; at its own distance,
338    /// with the kernel's seam-snapping window, where the seams are
339    /// quadratures.
340    pub(crate) fn run_place(
341        &self,
342        session: &LoweringSession<'_>,
343        owner: EntityId,
344        owner_type: &str,
345        distance: f64,
346    ) -> GeometryResult<RunPlace> {
347        Ok(match self.reading(session, owner, owner_type, distance)? {
348            Reading::Clear => RunPlace {
349                distance,
350                window: None,
351            },
352            Reading::OnSeam(seam) => RunPlace {
353                distance: seam,
354                window: None,
355            },
356            Reading::Window(window) => RunPlace {
357                distance,
358                window: Some(window),
359            },
360        })
361    }
362
363    /// Refuse a run over `[from, to]`, both ends included, across a seam
364    /// where the curve turns back on itself: IFC's half-angle mitre
365    /// (8.8.3.35.1) has no plane there.
366    pub(crate) fn check_run(
367        &self,
368        session: &LoweringSession<'_>,
369        owner: EntityId,
370        owner_type: &str,
371        from: f64,
372        to: f64,
373    ) -> GeometryResult<()> {
374        let seams = match &self.seams {
375            // The seams are quadratures: the kernel's mitre refuses a
376            // reversal by name when it reads the run.
377            Err(reason) if WINDOWED.contains(reason) => return Ok(()),
378            _ => self.known_seams(session, owner, owner_type)?,
379        };
380        let reversal = seams.iter().any(|seam| {
381            seam.reverses
382                && seam.distance >= from - self.tolerance(from)
383                && seam.distance <= to + self.tolerance(to)
384        });
385        if reversal {
386            Err(session.unsupported(owner, owner_type, REVERSAL))
387        } else {
388            Ok(())
389        }
390    }
391}
392
393/// The reasons a basis's seams are unknown for which a station carries
394/// the kernel's seam-snapping window instead (module documentation): its
395/// seams lie at arc-length integrals.
396const WINDOWED: [&str; 2] = [relation::INEXACT, seams::SPLINE];
397
398/// How a station is read against its basis's seams.
399#[derive(Debug, Clone, Copy, PartialEq)]
400enum Reading {
401    /// Clear of every seam: stored as it is.
402    Clear,
403    /// Within precision of the seam at this distance: stored there,
404    /// reading the incoming side.
405    OnSeam(f64),
406    /// On a basis whose seams are quadratures: stored as it is, reading
407    /// the incoming side of any seam within this window, which the kernel
408    /// snaps to.
409    Window(f64),
410}
411
412/// Where a station of a run is stored: [`Basis::run_place`].
413#[derive(Debug, Clone, Copy, PartialEq)]
414pub(crate) struct RunPlace {
415    /// The distance stored: a seam's own when the station lies on one the
416    /// data states, else the station's.
417    pub distance: f64,
418    /// The kernel's seam-snapping window, on a basis whose seams are
419    /// quadratures (#429).
420    pub window: Option<f64>,
421}
422
423/// Why a run across a reversal is refused.
424pub(crate) const REVERSAL: &str =
425    "the run crosses a tangent discontinuity where the basis curve turns back on itself; \
426     IFC4.3 ADD2 (8.8.3.35.1) mitres at half angle there and warns that \"very sharp edges \
427     may result in nearly impossible miter\", and the half-angle plane would stretch a \
428     section without bound";
429
430/// Lower an `IfcPointByDistanceExpression` into a `CurveStation`, or, on a
431/// tangent discontinuity of its basis, into the unturned
432/// `OrientedCurveStation` reading the incoming side (module documentation).
433pub fn lower_point_by_distance_node(
434    session: &mut LoweringSession<'_>,
435    id: EntityId,
436    frame: Transform,
437) -> GeometryResult<NodeId> {
438    memoized(session, id, frame, |session| {
439        let (basis, station, reading) = located(session, id, POINT, id, frame)?;
440        let station = CurveStation::new(basis.node, station);
441        let node = match reading {
442            Reading::Clear => GeometryNode::CurveStation(station),
443            _ => GeometryNode::OrientedCurveStation(read_at(station.into(), reading)),
444        };
445        session.node_for(id, node)
446    })
447}
448
449/// Lower an `IfcAxis2PlacementLinear` into an `OrientedCurveStation`.
450///
451/// Its `Location` is the station (WR1); `Axis` and `RefDirection` become
452/// the orientation, read in the station's base frame. On a tangent
453/// discontinuity it reads the incoming side (see the module documentation).
454pub fn lower_axis2_placement_linear_node(
455    session: &mut LoweringSession<'_>,
456    id: EntityId,
457    frame: Transform,
458) -> GeometryResult<NodeId> {
459    memoized(session, id, frame, |session| {
460        let oriented = linear_placement_station(session, id, frame)?;
461        session.node_for(id, GeometryNode::OrientedCurveStation(oriented))
462    })
463}
464
465/// The `OrientedCurveStation` an `IfcAxis2PlacementLinear` lowers to, as a
466/// value: what places a curve at a station (`InstanceAtStation`, #311).
467pub(crate) fn linear_placement_station(
468    session: &mut LoweringSession<'_>,
469    id: EntityId,
470    frame: Transform,
471) -> GeometryResult<OrientedCurveStation> {
472    let placement = axes::read_placement(session, id)?;
473    let (basis, station, reading) = located(session, id, PLACEMENT, placement.location, frame)?;
474    let orientation = axes::placement_orientation(session, id, &placement)?;
475    let oriented = OrientedCurveStation::new(CurveStation::new(basis.node, station), orientation);
476    Ok(read_at(oriented, reading))
477}
478
479/// `station` reading the incoming side on a seam, with the kernel's
480/// seam-snapping window where the seams are quadratures.
481fn read_at(station: OrientedCurveStation, reading: Reading) -> OrientedCurveStation {
482    match reading {
483        Reading::Clear => station,
484        Reading::OnSeam(_) => station.with_seam_side(SeamSide::Incoming),
485        Reading::Window(window) => station
486            .with_seam_side(SeamSide::Incoming)
487            .with_seam_window(window),
488    }
489}
490
491/// Read the point `point`, lower its basis and place the station on it: at
492/// a seam's own distance, reading the incoming side, when it lies on one
493/// the data states; with the kernel's window where the seams are
494/// quadratures (8.9.3.48.3, module documentation).
495fn located(
496    session: &mut LoweringSession<'_>,
497    owner: EntityId,
498    owner_type: &str,
499    point: EntityId,
500    frame: Transform,
501) -> GeometryResult<(Basis, Station, Reading)> {
502    let expression = read::distance_expression(session, owner, owner_type, point)?;
503    let basis = Basis::lower(session, owner, owner_type, expression.basis, frame)?;
504    basis.check_on_curve(session, owner, owner_type, expression.distance)?;
505    let mut station = expression.station();
506    let reading = basis.reading(session, owner, owner_type, expression.distance)?;
507    match reading {
508        Reading::OnSeam(seam) => station.distance = seam,
509        Reading::Window(_) => session.record_seam_window(owner),
510        Reading::Clear => {}
511    }
512    Ok((basis, station, reading))
513}
514
515fn memoized(
516    session: &mut LoweringSession<'_>,
517    id: EntityId,
518    frame: Transform,
519    build: impl FnOnce(&mut LoweringSession<'_>) -> GeometryResult<NodeId>,
520) -> GeometryResult<NodeId> {
521    if let Some(node) = session.memoized(id, KIND, frame) {
522        return Ok(node);
523    }
524    session.enter(id, KIND)?;
525    let result = build(session);
526    session.exit(id);
527    let node = result?;
528    session.memoize(id, KIND, frame, node);
529    Ok(node)
530}