Skip to main content

microcad_lang/model/
ops.rs

1// Copyright © 2026 The µcad authors <info@microcad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! `std::ops` impls for Model
5
6use microcad_core::{BooleanOp, Integer};
7use microcad_lang_base::SrcRef;
8
9use crate::{
10    eval::EvalResult,
11    model::{Model, Models},
12};
13
14pub type ModelResult = EvalResult<Model>;
15
16impl std::ops::Sub for Model {
17    type Output = ModelResult;
18
19    fn sub(self, rhs: Self) -> Self::Output {
20        Ok(self.boolean_op(BooleanOp::Subtract, rhs))
21    }
22}
23
24/// Mul: `1 * Circle(r)`;
25impl std::ops::Mul<Model> for Integer {
26    type Output = ModelResult;
27
28    fn mul(self, rhs: Model) -> Self::Output {
29        Ok(Models::from(rhs.multiply(self)).to_multiplicity(SrcRef::none()))
30    }
31}
32
33/// union operator `|`
34impl std::ops::BitOr for Model {
35    type Output = ModelResult;
36
37    fn bitor(self, rhs: Self) -> Self::Output {
38        Ok(self.boolean_op(BooleanOp::Union, rhs))
39    }
40}
41
42/// intersection operator `&`
43impl std::ops::BitAnd for Model {
44    type Output = ModelResult;
45
46    fn bitand(self, rhs: Self) -> Self::Output {
47        Ok(self.boolean_op(BooleanOp::Intersect, rhs))
48    }
49}