Skip to main content

axiolid_primitive/
half_space.rs

1//! Unbounded half-space representation and explicit mesh clipping policy.
2
3use axiolid_core::{Plane3, Scalar};
4
5/// One side of an infinite plane.
6#[derive(Debug, Clone, Copy, PartialEq)]
7#[cfg_attr(
8    feature = "serde",
9    derive(serde::Serialize, serde::Deserialize),
10    serde(deny_unknown_fields)
11)]
12pub struct HalfSpace {
13    /// Boundary plane.
14    pub boundary: Plane3,
15    /// `true` selects the normal side, `false` the opposite side.
16    pub agreement: bool,
17}
18
19/// Relative amount by which a subject bound is expanded before an unbounded
20/// half-space participates in a finite mesh operation.
21#[derive(Debug, Clone, Copy, PartialEq)]
22pub struct ClipMargin(Scalar);
23
24impl ClipMargin {
25    /// Construct a positive relative margin.
26    pub fn new(factor: Scalar) -> Option<Self> {
27        (factor.is_finite() && factor > 0.0).then_some(Self(factor))
28    }
29
30    /// Relative factor.
31    pub const fn factor(self) -> Scalar {
32        self.0
33    }
34}