Skip to main content

neco_geometry/
chart_patch.rs

1use core::cmp::Ordering;
2
3use neco_algnum::{AlgnumError, RealAlgebraic};
4use neco_bigint::BigInt;
5
6use crate::{
7    GeometryFailure, ParametricSurfaceChart2, SurfaceParameterDomain, TrimmedSurfaceDeclaration,
8};
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
11pub struct DiskConstraint;
12
13impl DiskConstraint {
14    pub fn contains(&self, u: &RealAlgebraic, v: &RealAlgebraic) -> Result<bool, GeometryFailure> {
15        let one = RealAlgebraic::from_integer(BigInt::one().map_err(AlgnumError::from)?)?;
16        let squared_radius = u.mul(u)?.add(&v.mul(v)?)?;
17        Ok(matches!(
18            squared_radius.compare(&one)?,
19            Ordering::Less | Ordering::Equal
20        ))
21    }
22}
23
24#[derive(Debug, Eq, PartialEq)]
25pub enum ChartPatch {
26    Full {
27        chart: ParametricSurfaceChart2,
28        domain: SurfaceParameterDomain,
29        disk: Option<DiskConstraint>,
30    },
31    Trimmed {
32        declaration: TrimmedSurfaceDeclaration,
33    },
34}
35
36impl ChartPatch {
37    pub fn chart(&self) -> &ParametricSurfaceChart2 {
38        match self {
39            Self::Full { chart, .. } => chart,
40            Self::Trimmed { declaration } => declaration.chart(),
41        }
42    }
43
44    pub fn domain(&self) -> &SurfaceParameterDomain {
45        match self {
46            Self::Full { domain, .. } => domain,
47            Self::Trimmed { declaration } => declaration.domain(),
48        }
49    }
50
51    pub fn disk_constraint(&self) -> Option<&DiskConstraint> {
52        match self {
53            Self::Full { disk, .. } => disk.as_ref(),
54            Self::Trimmed { .. } => None,
55        }
56    }
57
58    pub fn trimmed(&self) -> Option<&TrimmedSurfaceDeclaration> {
59        match self {
60            Self::Full { .. } => None,
61            Self::Trimmed { declaration } => Some(declaration),
62        }
63    }
64}