Skip to main content

axiolid_core/
operation.rs

1//! Small operation values shared by representation and algorithm contracts.
2
3/// Regularized boolean set operation on solids.
4///
5/// The operand set matches `axiolid-overlay`'s planar contract so 2D and 3D
6/// booleans describe the same algebra. It is deliberately *not* a mirror of any
7/// one backend's operation enum: `SymmetricDifference` exists here because the
8/// set algebra has it, not because a provider offered it.
9///
10/// Marked `#[non_exhaustive]` so a future operand cannot break downstream
11/// `match` arms.
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13#[non_exhaustive]
14pub enum BooleanOperator {
15    /// Points in either operand.
16    Union,
17    /// Points in both operands.
18    Intersection,
19    /// Ordered: points in the subject and not in the tool.
20    Difference,
21    /// Points in exactly one operand, equal to `(A ∪ B) \ (A ∩ B)`.
22    SymmetricDifference,
23}
24
25impl BooleanOperator {
26    /// Every operand in a stable, declared order.
27    ///
28    /// Conformance suites iterate this so a new operand is automatically
29    /// covered rather than silently untested.
30    pub const ALL: [Self; 4] = [
31        Self::Union,
32        Self::Intersection,
33        Self::Difference,
34        Self::SymmetricDifference,
35    ];
36
37    /// Whether swapping the operands leaves the result unchanged.
38    ///
39    /// `Difference` is the only ordered operand; the identity is part of the
40    /// public contract because callers rely on it to reorder work.
41    pub const fn is_commutative(self) -> bool {
42        !matches!(self, Self::Difference)
43    }
44}