Skip to main content

kernel_api/
pmi.rs

1//! Semantic annotations exchanged without kernel topology. Probes name
2//! the controlled faces; the caller specifies their coordinate frame.
3
4/// Semantic annotations of one body. Workbenches answer in world
5/// coordinates; export receives probes in the body's own frame.
6#[derive(Debug, Clone, Default, PartialEq)]
7pub struct SemanticPmi {
8    pub tolerances: Vec<PmiTolerance>,
9    pub datums: Vec<PmiDatum>,
10    pub dimensions: Vec<PmiDimension>,
11}
12
13impl SemanticPmi {
14    pub fn is_empty(&self) -> bool {
15        self.tolerances.is_empty() && self.datums.is_empty() && self.dimensions.is_empty()
16    }
17
18    /// Move every face probe into another frame.
19    pub fn map_points(&mut self, point: impl Fn([f64; 3]) -> [f64; 3]) {
20        for at in self
21            .tolerances
22            .iter_mut()
23            .map(|t| &mut t.at)
24            .chain(self.datums.iter_mut().map(|d| &mut d.at))
25            .chain(self.dimensions.iter_mut().flat_map(|d| &mut d.features))
26        {
27            for p in at {
28                *p = point(*p);
29            }
30        }
31    }
32}
33
34#[derive(Debug, Clone, Default, PartialEq)]
35pub struct PmiTolerance {
36    /// AP242 entity word without `_tolerance`, such as `flatness`.
37    pub kind: String,
38    pub name: String,
39    /// Zone width in millimetres.
40    pub magnitude: f64,
41    /// Datum labels in precedence order, primary first.
42    pub datums: Vec<String>,
43    /// Material and zone modifiers, using the AP242 words.
44    pub modifiers: Vec<String>,
45    /// Modifiers of each reference, in the same order as `datums`.
46    pub datum_modifiers: Vec<Vec<String>>,
47    pub at: Vec<[f64; 3]>,
48}
49
50#[derive(Debug, Clone, Default, PartialEq)]
51pub struct PmiDatum {
52    pub label: String,
53    pub at: Vec<[f64; 3]>,
54}
55
56#[derive(Debug, Clone, Default, PartialEq)]
57pub struct PmiDimension {
58    /// The dimensional characteristic, e.g. `diameter` or `linear distance`.
59    pub name: String,
60    /// True for radians; false for millimetres. Allowances use the same unit.
61    pub angular: bool,
62    pub nominal: f64,
63    pub plus: Option<f64>,
64    /// Signed lower allowance, normally negative.
65    pub minus: Option<f64>,
66    /// One probe group for a size, two ordered groups for a location.
67    pub features: Vec<Vec<[f64; 3]>>,
68}