ifc_geometry/lower/net.rs
1//! Net product geometry: the Body minus every opening that voids it (#44).
2//!
3//! # Why this is a separate entry point
4//!
5//! A product's Body representation is its GROSS shape. `IfcRelVoidsElement`
6//! says an opening's body is to be removed from it, but the file never authors
7//! the result. Quantity takeoff wants gross; clearances, net areas, ratios and
8//! clash tests through an opening want net. Both must stay reachable, so gross
9//! keeps its existing entry point unchanged and net is asked for explicitly.
10//!
11//! # What the graph looks like
12//!
13//! The host body is lowered as usual, then each opening's Body is lowered
14//! through ITS OWN placement chain (exporters place openings relative to the
15//! host, and the chain resolves that). Exact `Boolean { Difference }` nodes
16//! are appended; nothing is evaluated here.
17//!
18//! A boolean operand must be a solid, and a multi-item Body lowers to a
19//! `Collection` (possibly under an `Instance`), which the graph rejects as an
20//! operand. So both sides are first split into their solid PARTS, with any
21//! enclosing instance transforms carried onto each part. Then, because
22//! `(A u B) - O = (A - O) u (B - O)`, each host part is cut on its own:
23//!
24//! ```text
25//! part_i -> (part_i - o1_a - o1_b) -> (... - o2_a) -> ... for every host part i
26//! step k = Collection(every part's head after opening k) (or the head itself)
27//! root = step of the last opening
28//! ```
29//!
30//! Openings go in ascending id, so the graph is a function of the model's
31//! content.
32//!
33//! # In the host's frame (#388)
34//!
35//! All of the above is lowered in the HOST's frame: the host's items without
36//! its world placement, each opening's by its placement relative to the
37//! host's, composed along the placement chain the two share. The
38//! subtraction then runs where the file's coincidences hold, not 5.6e6 m out
39//! on a georeferenced site, and one `Instance` with the host's world
40//! transform sits above each node [`NetLowering`] reports, so every one of
41//! them is still in world coordinates:
42//!
43//! ```text
44//! gross = Instance(host world, host body)
45//! body_k = Instance(host world, opening k's body relative to the host)
46//! step k = Instance(host world, the host-frame step k above)
47//! ```
48//!
49//! When an opening shares no placement chain with its host, the whole net
50//! body is lowered in world coordinates as before, rather than guessed. The
51//! `frame` module says how the relative placement is composed and when it is
52//! not.
53//!
54//! A host no opening voids is lowered the same way when an item of its Body
55//! is a boolean, a clip or an `IfcCsgSolid` (#655), so `gross` and `root`
56//! are both `Instance(host world, body in its frame)`. Any other opening-less
57//! Body stays in world coordinates. A boolean under an `IfcMappedItem`
58//! already runs in the map's frame under the mapped item's `Instance`.
59//!
60//! # Refusal, not a quiet gross body
61//!
62//! Every per-opening failure becomes [`GeometryError::OpeningNotSubtracted`]
63//! naming the opening. Skipping it would hand back geometry that claims to be
64//! net and is not -- the silent failure this entry point exists to prevent.
65//!
66//! # Reference View openings: taken as applied (#351)
67//!
68//! IFC4 Reference View exports author an `IfcOpeningElement` with only a
69//! `Reference` representation, usually tessellated, against a host whose
70//! `Body` already has the hole in it. The schema says so in the opening's own
71//! definition (IFC4 ADD2 TC1, `IfcOpeningElement`, entity definition): with
72//! a `'Body'` representation the voiding relationship is an implicit Boolean
73//! difference, but "if the IfcShapeRepresentation.RepresentationIdentifier =
74//! 'Reference', then the Reference shape representation of the opening is
75//! not subtracted, it is provided in addition to the hole in the Body shape
76//! representation of the voided element". Its Reference View concept
77//! (*Reference Geometry*, same page) repeats it: "Since there are no Boolean
78//! operations, either as IfcBooleanResult or implicitly by
79//! IfcRelVoidsElement the geometry of the IfcOpeningElement shall not be used
80//! to subtract the opening from the 'Body' shape representation of the voided
81//! element." IFC4.3 keeps both readings (`IfcOpeningElement`, concepts
82//! *Reference Geometry* and *Reference Tessellation Geometry*), and its
83//! *Element Openings* template states that the element's representation
84//! "does account for voids at export".
85//!
86//! Such an opening is therefore neither subtractable nor missing: the host's
87//! gross Body already IS its net Body. [`lower_product_net`] still refuses
88//! it, as it always has, because a caller asking for net geometry has not
89//! said it accepts the exporter's word for the hole. ADR 0014 makes net
90//! geometry an explicit request, so accepting it is explicit too:
91//! [`lower_product_net_with`] with [`NetOptions`] set to
92//! [`ReferenceOnlyOpenings::TakeAsApplied`]. Then the opening is listed in
93//! [`NetLowering::taken_as_applied`] with its relation and the reason, and
94//! nothing is subtracted for it. Nothing is guessed or dropped: the caller
95//! sees every opening either subtracted or taken as applied.
96//!
97//! Only an `IfcOpeningElement` (or IFC4's `IfcOpeningStandardCase`) whose
98//! representations are all, and only, `Reference` qualifies; the clause is
99//! about that entity and that identifier. An opening with no representation
100//! at all, one with any other representation beside `Reference`, a
101//! `Reference`-only `IfcVoidingFeature`, and an opening whose Body cannot be
102//! lowered are refused exactly as without the option.
103
104use axiolid_core::{BooleanOperator, Transform3};
105use axiolid_model::{GeometryNode, Instance, NodeId, SolidOperation};
106use ifc_model::{EntityId, Model};
107
108use crate::error::{GeometryError, GeometryResult};
109use crate::input::openings::voidings_of;
110use crate::input::product::Product;
111use crate::input::representation::{ProductShape, Representation};
112use crate::lower::session::NodeShape;
113use crate::lower::{lower_product_representation, LoweringSession, RepresentationPurpose};
114
115mod boolean_body;
116mod frame;
117
118use frame::NetFrame;
119
120/// One opening removed from a host, with the nodes that express it.
121#[derive(Debug, Clone, Copy, PartialEq, Eq)]
122#[non_exhaustive]
123pub struct Subtraction {
124 /// The voiding element (`IfcOpeningElement`, `IfcVoidingFeature`, ...).
125 pub opening: EntityId,
126 /// The `IfcRelVoidsElement` that authored the subtraction.
127 pub relation: EntityId,
128 /// The opening's lowered Body, placed in world space. Since #388 this is
129 /// usually an `Instance` of the host's world transform above the body
130 /// placed in the host's frame.
131 pub body: NodeId,
132 /// The host with this opening and every earlier one removed.
133 pub result: NodeId,
134}
135
136/// An opening whose void the host's Body already carries (#351).
137///
138/// Nothing is subtracted for it; see the module documentation for the IFC
139/// clauses. Only reported under [`ReferenceOnlyOpenings::TakeAsApplied`].
140#[derive(Debug, Clone, Copy, PartialEq, Eq)]
141#[non_exhaustive]
142pub struct TakenAsApplied {
143 /// The opening element.
144 pub opening: EntityId,
145 /// The `IfcRelVoidsElement` that names it.
146 pub relation: EntityId,
147 /// Why the opening counts as already applied.
148 pub reason: AppliedReason,
149}
150
151/// Why an opening is taken as already applied to its host.
152#[derive(Debug, Clone, Copy, PartialEq, Eq)]
153#[non_exhaustive]
154pub enum AppliedReason {
155 /// Every representation of the opening is `Reference`, which IFC says is
156 /// "not subtracted" but "provided in addition to the hole in the Body".
157 ReferenceRepresentationOnly,
158}
159
160/// What [`lower_product_net_with`] does with an opening that has only a
161/// `Reference` representation (#351).
162#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
163#[non_exhaustive]
164pub enum ReferenceOnlyOpenings {
165 /// Refuse the host with [`GeometryError::OpeningNotSubtracted`], as
166 /// [`lower_product_net`] does. The default.
167 #[default]
168 Refuse,
169 /// Report the opening in [`NetLowering::taken_as_applied`] and subtract
170 /// nothing for it: the host's Body is taken to carry the void already.
171 TakeAsApplied,
172}
173
174/// Options for a net request; [`Default`] is [`lower_product_net`]'s
175/// behaviour.
176#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
177#[non_exhaustive]
178pub struct NetOptions {
179 /// What to do with a `Reference`-only opening.
180 pub reference_only_openings: ReferenceOnlyOpenings,
181}
182
183impl NetOptions {
184 /// Set what to do with a `Reference`-only opening.
185 ///
186 /// Builder-style, because the struct is `#[non_exhaustive]`:
187 /// `NetOptions::default().with_reference_only_openings(policy)`.
188 #[must_use]
189 pub fn with_reference_only_openings(mut self, policy: ReferenceOnlyOpenings) -> Self {
190 self.reference_only_openings = policy;
191 self
192 }
193}
194
195/// A host lowered as net geometry.
196#[derive(Debug, Clone, PartialEq, Eq)]
197#[non_exhaustive]
198pub struct NetLowering {
199 /// The host's gross Body, before any subtraction, in world space. With
200 /// openings to cut, or with a boolean, a clip or an `IfcCsgSolid`
201 /// among its Body's items (#655), usually an `Instance` of the host's world transform above the
202 /// Body lowered in the host's frame.
203 pub gross: NodeId,
204 /// One entry per opening, in the order they are subtracted.
205 pub subtractions: Vec<Subtraction>,
206 /// Openings the host's Body already carries, in ascending opening id.
207 ///
208 /// Always empty unless the caller chose
209 /// [`ReferenceOnlyOpenings::TakeAsApplied`]. Every voiding opening is in
210 /// exactly one of this list and [`Self::subtractions`].
211 pub taken_as_applied: Vec<TakenAsApplied>,
212 /// The net result: the last subtraction, or `gross` when there are none.
213 ///
214 /// With openings to cut, or with a boolean, a clip or an `IfcCsgSolid`
215 /// among its Body's items (#655), usually an `Instance` of the host's world transform above the
216 /// `Difference` nodes, which run in the host's frame; see the module
217 /// documentation.
218 pub root: NodeId,
219}
220
221impl NetLowering {
222 /// The subtracted openings, in subtraction order.
223 pub fn openings(&self) -> Vec<EntityId> {
224 self.subtractions.iter().map(|s| s.opening).collect()
225 }
226}
227
228/// How deep `Collection`/`Instance` nesting may go while splitting a body.
229///
230/// Lowering has already bounded recursion, so this only guards against a
231/// graph built by some future caller that nests without limit.
232const MAX_PART_DEPTH: usize = 64;
233
234/// Lower `product`'s Body with every voiding opening subtracted.
235///
236/// Returns `Ok(None)` when the product has no Body, exactly as the gross path
237/// does; openings of a body-less host have nothing to cut. The same as
238/// [`lower_product_net_with`] with [`NetOptions::default`].
239///
240/// # Errors
241///
242/// Any error lowering the host's own Body is returned as is, and so is a host
243/// Body that contains no solid when it has openings to cut. A failure on an
244/// opening -- its Body does not lower, it has no Body, it holds non-solid
245/// geometry, or it names the host itself -- is
246/// [`GeometryError::OpeningNotSubtracted`] naming the opening.
247pub fn lower_product_net(
248 session: &mut LoweringSession<'_>,
249 product: EntityId,
250) -> GeometryResult<Option<NetLowering>> {
251 lower_product_net_with(session, product, NetOptions::default())
252}
253
254/// [`lower_product_net`] with explicit [`NetOptions`].
255///
256/// Under [`ReferenceOnlyOpenings::TakeAsApplied`], an `IfcOpeningElement`
257/// whose representations are all `Reference` is listed in
258/// [`NetLowering::taken_as_applied`] instead of refusing the host (#351; see
259/// the module documentation). A host whose openings are all taken as applied
260/// lowers to its gross Body, and `root == gross`.
261///
262/// # Errors
263///
264/// As [`lower_product_net`]. An opening with no representation, one with a
265/// representation other than `Reference`, or one whose Body does not lower
266/// is still [`GeometryError::OpeningNotSubtracted`] whatever the options.
267pub fn lower_product_net_with(
268 session: &mut LoweringSession<'_>,
269 product: EntityId,
270 options: NetOptions,
271) -> GeometryResult<Option<NetLowering>> {
272 Ok(lower_net_in_frame(session, product, options, false)?.map(|inner| inner.net))
273}
274
275/// A body lowered in its host's frame, with the placement that takes it to
276/// world coordinates (#455).
277///
278/// `local` is the host's gross Body, or its net Body when openings were
279/// subtracted, as the nodes of the host's own frame: the planes of a layer
280/// stack are stated there, so a cut made on it keeps what the file states.
281#[derive(Debug, Clone)]
282pub(crate) struct LocalBody {
283 /// The body in the host's frame.
284 pub(crate) local: NodeId,
285 /// The host's world transform, `None` when it is the identity.
286 pub(crate) to_world: Option<Transform3>,
287 /// The gross Body in world coordinates.
288 pub(crate) gross: NodeId,
289 /// The net lowering, `None` for a gross request.
290 pub(crate) net: Option<NetLowering>,
291}
292
293/// The Body of `product` in its own frame: gross, or net when `net` is set.
294///
295/// `Ok(None)` when the product has no Body. A net body that falls back to
296/// world coordinates (an opening shares no placement chain with its host) is
297/// [`GeometryError::Unsupported`]: a plane stated in the host's frame is not
298/// moved to another one.
299pub(crate) fn lower_body_in_host_frame(
300 session: &mut LoweringSession<'_>,
301 product: EntityId,
302 net: Option<NetOptions>,
303) -> GeometryResult<Option<LocalBody>> {
304 let Some(options) = net else {
305 let Some(frame) = NetFrame::for_host(session, product, &[])? else {
306 return Ok(None);
307 };
308 let to_world = frame.to_world();
309 let Some(local) = frame.lower_host(session, product)? else {
310 return Ok(None);
311 };
312 let gross = place(session, local, to_world, product)?;
313 return Ok(Some(LocalBody {
314 local,
315 to_world,
316 gross,
317 net: None,
318 }));
319 };
320 let Some(inner) = lower_net_in_frame(session, product, options, true)? else {
321 return Ok(None);
322 };
323 if !inner.host_frame {
324 return Err(GeometryError::Unsupported {
325 entity: product,
326 type_name: type_name_of(session, product),
327 detail: "an opening shares no placement chain with its host, so the net body is \
328 in world coordinates and a layer stack in the host's frame cannot cut it",
329 });
330 }
331 Ok(Some(LocalBody {
332 local: inner.local_root,
333 to_world: inner.to_world,
334 gross: inner.net.gross,
335 net: Some(inner.net),
336 }))
337}
338
339/// A net lowering and what it was lowered in.
340struct NetInner {
341 net: NetLowering,
342 /// The net result in the host's frame (the world root when
343 /// `host_frame` is false).
344 local_root: NodeId,
345 to_world: Option<Transform3>,
346 host_frame: bool,
347}
348
349/// The net lowering of [`lower_product_net_with`], keeping the host-frame
350/// root. `always_host` lowers an opening-less, boolean-less Body in the
351/// host's frame too, instead of in world coordinates.
352fn lower_net_in_frame(
353 session: &mut LoweringSession<'_>,
354 product: EntityId,
355 options: NetOptions,
356 always_host: bool,
357) -> GeometryResult<Option<NetInner>> {
358 let voidings = voidings_of(session.model(), product);
359 // A Body with a boolean or a clip is lowered in the product's frame even
360 // without openings (#655); any other opening-less Body stays in world
361 // coordinates, unchanged.
362 if !always_host
363 && voidings.is_empty()
364 && !boolean_body::body_holds_boolean(session.model(), product)
365 {
366 let Some(gross) =
367 lower_product_representation(session, product, RepresentationPurpose::Body)?
368 else {
369 return Ok(None);
370 };
371 return Ok(Some(NetInner {
372 net: NetLowering {
373 gross,
374 subtractions: Vec::new(),
375 taken_as_applied: Vec::new(),
376 root: gross,
377 },
378 local_root: gross,
379 to_world: None,
380 host_frame: false,
381 }));
382 }
383 // The host's frame when it has no openings (#655) or every opening shares
384 // a placement chain with it, else world coordinates (#388).
385 let Some(frame) = NetFrame::for_host(session, product, &voidings)? else {
386 return Ok(None);
387 };
388 let to_world = frame.to_world();
389 let host_frame = matches!(frame, NetFrame::Host { .. });
390 let Some(local_gross) = frame.lower_host(session, product)? else {
391 return Ok(None);
392 };
393 let mut local_root = local_gross;
394 let gross = place(session, local_gross, to_world, product)?;
395
396 // Split lazily: a host whose openings are all taken as applied has
397 // nothing cut from it, so it needs no solid parts.
398 let mut heads: Option<Vec<NodeId>> = None;
399 let mut subtractions = Vec::with_capacity(voidings.len());
400 let mut taken_as_applied = Vec::new();
401 for voiding in voidings {
402 let refuse = |cause: GeometryError| GeometryError::OpeningNotSubtracted {
403 host: product,
404 opening: voiding.opening,
405 cause: Box::new(cause),
406 };
407 if voiding.opening == product {
408 // A host voiding itself would subtract to nothing. That is a broken
409 // relation, not a request for an empty solid.
410 return Err(refuse(degenerate(
411 session,
412 voiding.relation,
413 "IfcRelVoidsElement names the same element as host and opening",
414 )));
415 }
416 let body = match frame.lower_opening(session, voiding.opening) {
417 Ok(Some(body)) => body,
418 Ok(None) => {
419 if options.reference_only_openings == ReferenceOnlyOpenings::TakeAsApplied
420 && reference_only_opening(session.model(), voiding.opening).map_err(refuse)?
421 {
422 taken_as_applied.push(TakenAsApplied {
423 opening: voiding.opening,
424 relation: voiding.relation,
425 reason: AppliedReason::ReferenceRepresentationOnly,
426 });
427 continue;
428 }
429 return Err(refuse(degenerate(
430 session,
431 voiding.opening,
432 "the opening has no Body representation, so there is nothing to subtract",
433 )));
434 }
435 Err(error) => return Err(refuse(error)),
436 };
437 let tools = solid_parts(session, body, voiding.opening).map_err(refuse)?;
438 let heads = match &mut heads {
439 Some(heads) => heads,
440 None => heads.insert(solid_parts(session, local_gross, product)?),
441 };
442 for head in heads.iter_mut() {
443 for &tool in &tools {
444 // Attributed to the relation: it is the entity that authored the cut.
445 *head = session
446 .node_for(
447 voiding.relation,
448 GeometryNode::SolidOperation(SolidOperation::Boolean {
449 left: *head,
450 right: tool,
451 operator: BooleanOperator::Difference,
452 }),
453 )
454 .map_err(refuse)?;
455 }
456 }
457 let result = match heads.as_slice() {
458 [single] => *single,
459 _ => session
460 .node_for(voiding.relation, GeometryNode::Collection(heads.clone()))
461 .map_err(refuse)?,
462 };
463 local_root = result;
464 subtractions.push(Subtraction {
465 opening: voiding.opening,
466 relation: voiding.relation,
467 body: place(session, body, to_world, voiding.opening).map_err(refuse)?,
468 result: place(session, result, to_world, voiding.relation).map_err(refuse)?,
469 });
470 }
471
472 let root = subtractions.last().map_or(gross, |step| step.result);
473 Ok(Some(NetInner {
474 net: NetLowering {
475 gross,
476 subtractions,
477 taken_as_applied,
478 root,
479 },
480 local_root,
481 to_world,
482 host_frame,
483 }))
484}
485
486/// Is `opening` an `IfcOpeningElement` whose every representation is
487/// `Reference` (#351)?
488///
489/// `false` for an opening with no representation at all: that one carries
490/// no statement that the host is already voided, so it stays refused. A
491/// dangling representation reference is a missing entity, not a `false`.
492fn reference_only_opening(model: &Model, opening: EntityId) -> GeometryResult<bool> {
493 let entity = model.get(opening).ok_or(GeometryError::MissingEntity {
494 referrer: opening,
495 missing: opening,
496 })?;
497 // The clause is IfcOpeningElement's own; IFC4's deprecated
498 // IfcOpeningStandardCase is its subtype. Other feature subtractions
499 // (IfcVoidingFeature) state no such thing.
500 if !(entity.is_type("IFCOPENINGELEMENT") || entity.is_type("IFCOPENINGSTANDARDCASE")) {
501 return Ok(false);
502 }
503 let Some(shape) = Product::new(opening, entity).representation() else {
504 return Ok(false);
505 };
506 let shape_entity = model.get(shape).ok_or(GeometryError::MissingEntity {
507 referrer: opening,
508 missing: shape,
509 })?;
510 let representations = ProductShape::new(shape, shape_entity).representations()?;
511 if representations.is_empty() {
512 return Ok(false);
513 }
514 for representation in representations {
515 let entity = model
516 .get(representation)
517 .ok_or(GeometryError::MissingEntity {
518 referrer: shape,
519 missing: representation,
520 })?;
521 if Representation::new(representation, entity)
522 .identifier()
523 .as_deref()
524 != Some(REFERENCE)
525 {
526 return Ok(false);
527 }
528 }
529 Ok(true)
530}
531
532/// The representation identifier IFC says is "not subtracted".
533const REFERENCE: &str = "Reference";
534
535/// Split a lowered body into nodes the graph accepts as boolean operands.
536///
537/// A solid node is its own single part. A `Collection` contributes each
538/// member's parts. An `Instance` whose chain ends in a solid is already a
539/// valid operand and is kept as is; an `Instance` of a collection is pushed
540/// down, so each part is re-instanced under the composed transform.
541///
542/// Anything else (a curve, a surface, an open shell lowered as a surface
543/// model) bounds no volume, so it is refused naming `owner` rather than
544/// dropped: dropping part of a body would under-cut or over-report.
545pub(crate) fn solid_parts(
546 session: &mut LoweringSession<'_>,
547 root: NodeId,
548 owner: EntityId,
549) -> GeometryResult<Vec<NodeId>> {
550 let mut parts = Vec::new();
551 collect_parts(session, root, None, owner, 0, &mut parts)?;
552 if parts.is_empty() {
553 return Err(degenerate(
554 session,
555 owner,
556 "the Body holds no solid, so there is nothing to subtract with or from",
557 ));
558 }
559 Ok(parts)
560}
561
562fn collect_parts(
563 session: &mut LoweringSession<'_>,
564 node: NodeId,
565 outer: Option<Transform3>,
566 owner: EntityId,
567 depth: usize,
568 parts: &mut Vec<NodeId>,
569) -> GeometryResult<()> {
570 if depth > MAX_PART_DEPTH {
571 return Err(GeometryError::ChainTooDeep {
572 entity: owner,
573 kind: "body part",
574 limit: MAX_PART_DEPTH,
575 });
576 }
577 let shape = session.shape(node).cloned();
578 match shape {
579 Some(NodeShape::Solid) => parts.push(place(session, node, outer, owner)?),
580 Some(NodeShape::Instance { source, transform }) => {
581 if ends_in_solid(session, source) {
582 parts.push(place(session, node, outer, owner)?);
583 } else {
584 // `outer` is applied after this instance's own transform.
585 let composed = outer.map_or(transform, |outer| outer * transform);
586 collect_parts(session, source, Some(composed), owner, depth + 1, parts)?;
587 }
588 }
589 Some(NodeShape::Collection(members)) => {
590 for member in members {
591 collect_parts(session, member, outer, owner, depth + 1, parts)?;
592 }
593 }
594 Some(NodeShape::Other | NodeShape::Curve) | None => {
595 return Err(degenerate(
596 session,
597 owner,
598 "the Body holds geometry that bounds no volume, so it cannot be \
599 used in a boolean subtraction",
600 ));
601 }
602 }
603 Ok(())
604}
605
606/// Does this node's instance chain end in a solid?
607fn ends_in_solid(session: &LoweringSession<'_>, mut node: NodeId) -> bool {
608 for _ in 0..=MAX_PART_DEPTH {
609 match session.shape(node) {
610 Some(NodeShape::Solid) => return true,
611 Some(NodeShape::Instance { source, .. }) => node = *source,
612 _ => return false,
613 }
614 }
615 false
616}
617
618/// `node` under `outer`, or `node` itself when there is no outer transform.
619pub(crate) fn place(
620 session: &mut LoweringSession<'_>,
621 node: NodeId,
622 outer: Option<Transform3>,
623 owner: EntityId,
624) -> GeometryResult<NodeId> {
625 match outer {
626 None => Ok(node),
627 Some(transform) => session.node_for(
628 owner,
629 GeometryNode::Instance(Instance {
630 source: node,
631 transform,
632 }),
633 ),
634 }
635}
636
637fn type_name_of(session: &LoweringSession<'_>, entity: EntityId) -> String {
638 session
639 .model()
640 .get(entity)
641 .map_or_else(String::new, |e| e.type_name.to_string())
642}
643
644pub(crate) fn degenerate(
645 session: &LoweringSession<'_>,
646 entity: EntityId,
647 detail: &str,
648) -> GeometryError {
649 GeometryError::Degenerate {
650 entity,
651 type_name: type_name_of(session, entity),
652 detail: detail.to_string(),
653 }
654}