ifc_lite_geometry_runtime/
worker_disk_qualification.rs

1// SPDX-License-Identifier: MPL-2.0
2//! Real pipe witnesses for the separate exact-coefficient numerical route.
3use super::qualification::bounds;
4use super::{MeshLimits, SmlibWorker, WorkerError};
5use std::f64::consts::PI;
6impl SmlibWorker {
7    /// Explicitly qualify this incarnation's supported open rational pipe route.
8    /// Source interpretation, closed/hollow paths and rational regions remain
9    /// outside this witness. Feature negotiation alone does not open the gate.
10    pub fn qualify_rational_disks(&mut self) -> Result<Vec<f64>, WorkerError> {
11        self.disks_qualified = false;
12        let incarnation = self.incarnation();
13        if incarnation == 0 {
14            return Err(WorkerError::WrongWorker);
15        }
16        let mut volumes = Vec::new();
17        for curved in [false, true] {
18            let bytes = recipe(curved);
19            let solid = self.create_sweep(&bytes, 2, 1, 1)?;
20            let result = (|| {
21                let volume = self.volume(solid, 1e-8)?;
22                let expected = PI * 0.25 * 0.25 * if curved { 2. * PI } else { 5. };
23                if !self.is_manifold(solid)? || (volume - expected).abs() > expected * 1e-4 {
24                    return Err(WorkerError::Unqualified(
25                        "rational pipe volume/manifold witness failed",
26                    ));
27                }
28                let mesh = self.tessellate(
29                    solid,
30                    0.0001,
31                    5.,
32                    MeshLimits {
33                        max_bytes: 16 * 1024 * 1024,
34                    },
35                )?;
36                let (min, max) = bounds(&mesh.positions);
37                // Straight pipe: independent analytic cylinder bounds.
38                if !curved
39                    && (0..3).any(|i| {
40                        (min[i] - [-0.25, -0.25, 0.][i]).abs() > 0.002
41                            || (max[i] - [0.25, 0.25, 5.][i]).abs() > 0.002
42                    })
43                {
44                    return Err(WorkerError::Unqualified(
45                        "rational pipe bounds witness failed",
46                    ));
47                }
48                Ok(volume)
49            })();
50            let cleanup = self.release(solid);
51            match (result, cleanup) {
52                (Ok(v), Ok(())) => volumes.push(v),
53                (Err(e), _) | (_, Err(e)) => return Err(e),
54            }
55        }
56        if self.incarnation() != incarnation {
57            return Err(WorkerError::WrongWorker);
58        }
59        self.disks_qualified = true;
60        Ok(volumes)
61    }
62}
63fn recipe(curved: bool) -> Vec<u8> {
64    let mut b = Vec::new();
65    for v in [2u32, 1, 1, 0] {
66        b.extend(v.to_le_bytes());
67    }
68    for v in [0.25f64, 0.] {
69        b.extend(v.to_le_bytes());
70    }
71    for v in [
72        4u32,
73        0,
74        if curved { 2 } else { 1 },
75        if curved { 3 } else { 2 },
76        2,
77        0,
78    ] {
79        b.extend(v.to_le_bytes());
80    }
81    for v in [0f64, 1.] {
82        b.extend(v.to_le_bytes());
83    }
84    let controls = if curved {
85        vec![4., 0., 0., 1., 4., 4., 0., 0.5f64.sqrt(), 0., 4., 0., 1.]
86    } else {
87        vec![0., 0., 0., 2., 0., 0., 5., 3.]
88    };
89    for v in controls {
90        b.extend(v.to_le_bytes());
91    }
92    for knot in [0f64, 1.] {
93        b.extend(knot.to_le_bytes());
94        b.extend((if curved { 3u32 } else { 2u32 }).to_le_bytes());
95        b.extend(0u32.to_le_bytes());
96    }
97    b
98}