ifc_geometry/compile/window.rs
1//! A kernel's refusal of a station's seam-snapping window (#423), named.
2//!
3//! A station on a basis whose seams lie at arc-length integrals is lowered
4//! with Axiolid's seam-snapping window (`lower::station`, axiolid/kernel#294)
5//! and the kernel snaps it when it resolves the station. Three refusals are
6//! the window's own, each a typed `GeomError::UnsupportedInput` naming its
7//! input: two seams within the window, a seam whose certified position
8//! straddles its edge, and a seam whose distance cannot be certified. The
9//! inputs are `axiolid-evaluate`'s constants, an execution provider this
10//! crate does not link (ADR 0004), so they are repeated here and a test
11//! pins them equal.
12//!
13//! A run's stations carry the same window (#429, axiolid/kernel#301), and
14//! a run adds one refusal of its own: its stations, snapped, no longer
15//! increase strictly in distance, a `GeomError::InvalidInput` whose text
16//! `axiolid-mesh-compile` keeps private; it is repeated here, and a test
17//! that compiles such a run pins it. An offset run continued to its
18//! basis's end, which the kernel measures (#433, axiolid/kernel#303), adds
19//! another: a stated station at or past that end, another private
20//! `GeomError::InvalidInput` text repeated and pinned the same way.
21//! Certifying a seam to the window's tolerance may also exceed the kernel's
22//! panel budget, a `GeomError::BudgetExceeded` whose private resource name
23//! is repeated here and pinned by a test that triggers it (#443).
24
25use axiolid_contracts::GeomError;
26
27/// `axiolid_evaluate::station::SEAM_WINDOW_AMBIGUOUS`.
28pub(crate) const AMBIGUOUS: &str =
29 "a station whose seam-snapping window holds two seams of its basis: its seam side does not \
30 say which one it lies on";
31
32/// `axiolid_evaluate::station::SEAM_WINDOW_STRADDLED`.
33pub(crate) const STRADDLED: &str =
34 "a station whose seam-snapping window has a seam on its edge: the seam's certified position \
35 straddles it, so whether the station lies within the window cannot be told";
36
37/// `axiolid_evaluate::station::UNCERTIFIED_LENGTH`.
38pub(crate) const UNCERTIFIED: &str =
39 "a certified length of a station piece no bound here reaches: an offset of a banked curve, a \
40 3D intrinsic curve with torsion or out of a level plane, a chain's parametric piece or an elevated curve with an intrinsic \
41 profile in a leaning frame; a 3D offset direction that is not vertical beside a \
42 plan-measured or intrinsic base; a base placed in a frame that tilts +Z; a skewed frame; or \
43 a tolerance below the points' rounding";
44
45/// The resource `axiolid-evaluate` names when certifying a piece's length
46/// to a window's tolerance needs more panels than its budget allows
47/// (`station::certify`, private there): a `GeomError::BudgetExceeded`.
48pub(crate) const CERTIFICATION_BUDGET: &str = "certified length panels";
49
50/// `axiolid-mesh-compile`'s refusal of an offset run whose stations, its
51/// basis's ends resolved, do not increase (`station::RESOLVED_NOT_INCREASING`,
52/// private there).
53pub(crate) const PAST_BASIS_END: &str =
54 "station: the run's stations, its stations at the basis's ends measured by the kernel, do \
55 not increase strictly in distance: a stated station at or past the basis's end";
56
57/// `axiolid-mesh-compile`'s refusal of a run whose snapped stations no
58/// longer increase (`station::SNAPPED_NOT_INCREASING`, private there).
59pub(crate) const NOT_INCREASING: &str =
60 "station: the run's stations, snapped onto seams within their windows, no longer increase \
61 strictly in distance: two snapped onto one seam, or one snapped past its neighbour";
62
63/// Why the kernel refused a station's seam-snapping window (#423), or a
64/// run's (#429).
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66#[non_exhaustive]
67pub enum SeamWindowRefusal {
68 /// The window holds two seams of the basis, so the station's seam side
69 /// does not say which one it lies on. The model's precision is coarser
70 /// than the distance between two seams.
71 Ambiguous,
72 /// A seam's certified position straddles the window's edge, so whether
73 /// the station lies on it within precision cannot be told.
74 Straddled,
75 /// A seam's distance cannot be certified (an offset of a banked or a 3D
76 /// intrinsic curve, a tolerance below the points' rounding, and the
77 /// other cases the kernel names). An offset by distances along an
78 /// ellipse or a B-spline is certified since `axiolid-evaluate` 0.3.15
79 /// (axiolid/kernel#307, #443).
80 UncertifiedLength,
81 /// A run's stations, snapped onto seams within their windows, no
82 /// longer increase strictly in distance: two snapped onto one seam, or
83 /// one past its neighbour (#429). The model's precision is coarser
84 /// than the distance between them.
85 NotIncreasing,
86 /// An offset run continued to its basis's end, whose distance the
87 /// kernel measures (#433), states a station at or past that end, so its
88 /// stations do not increase strictly once the end is resolved. IFC4.3
89 /// ADD2 (8.9.3.42.3) continues the offsets only where they stop short
90 /// of the end; one stated within the model's precision of it is
91 /// refused too, since this crate cannot tell it from the end.
92 PastBasisEnd,
93 /// Certifying a seam's distance to the window's tolerance (a thousandth
94 /// of it) needs more panels than the kernel's budget allows: a piece
95 /// whose length is a quadrature, before the window or reaching it,
96 /// whose derivatives the kernel bounds only coarsely for so fine a
97 /// tolerance (#443). Since `axiolid-evaluate` 0.3.15 refines its panels
98 /// adaptively (axiolid/kernel#307), an ordinary curve certifies to
99 /// `1e-8` relative and below within the budget.
100 CertificationBudgetExceeded,
101}
102
103impl SeamWindowRefusal {
104 /// The refusal `error` is, if it is one of a window's.
105 pub(crate) fn of(error: &GeomError) -> Option<Self> {
106 if let GeomError::BudgetExceeded { resource } = error {
107 return (*resource == CERTIFICATION_BUDGET)
108 .then_some(Self::CertificationBudgetExceeded);
109 }
110 if let GeomError::InvalidInput(detail) = error {
111 return if detail == NOT_INCREASING {
112 Some(Self::NotIncreasing)
113 } else if detail == PAST_BASIS_END {
114 Some(Self::PastBasisEnd)
115 } else {
116 None
117 };
118 }
119 let GeomError::UnsupportedInput { input, .. } = error else {
120 return None;
121 };
122 if *input == AMBIGUOUS {
123 Some(Self::Ambiguous)
124 } else if *input == STRADDLED {
125 Some(Self::Straddled)
126 } else if *input == UNCERTIFIED {
127 Some(Self::UncertifiedLength)
128 } else {
129 None
130 }
131 }
132}
133
134impl std::fmt::Display for SeamWindowRefusal {
135 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
136 f.write_str(match self {
137 Self::Ambiguous => {
138 "the window holds two seams of the basis curve, so the station's seam side does \
139 not say which one it lies on"
140 }
141 Self::Straddled => {
142 "a seam's certified position straddles the window's edge, so whether the \
143 station lies on it within precision cannot be told"
144 }
145 Self::UncertifiedLength => {
146 "the distance of a seam of the basis curve cannot be certified to the window"
147 }
148 Self::NotIncreasing => {
149 "the run's stations, snapped onto seams within the window, no longer increase \
150 strictly in distance"
151 }
152 Self::CertificationBudgetExceeded => {
153 "the distance of a seam of the basis curve cannot be certified to the window \
154 within the kernel's panel budget"
155 }
156 Self::PastBasisEnd => {
157 "the offset run states a station at or past its basis's end, which the kernel \
158 measures, so its stations do not increase strictly in distance"
159 }
160 })
161 }
162}
163
164#[cfg(test)]
165mod tests {
166 use super::*;
167
168 /// The inputs are the kernel's own (repeated because it is not linked).
169 #[test]
170 fn the_inputs_are_the_kernels() {
171 use axiolid_evaluate::station::{
172 SEAM_WINDOW_AMBIGUOUS, SEAM_WINDOW_STRADDLED, UNCERTIFIED_LENGTH,
173 };
174 assert_eq!(AMBIGUOUS, SEAM_WINDOW_AMBIGUOUS);
175 assert_eq!(STRADDLED, SEAM_WINDOW_STRADDLED);
176 assert_eq!(UNCERTIFIED, UNCERTIFIED_LENGTH);
177 assert_eq!(
178 crate::constraint::placement::derive::WINDOW_CERTIFICATION,
179 axiolid_evaluate::station::window::WINDOW_CERTIFICATION
180 );
181 }
182}