#![warn(missing_docs)]
pub mod shape_processor;
mod difference_2d;
mod group;
mod sketch;
mod sweep;
mod transform;
use fj_interop::debug::DebugInfo;
use fj_kernel::{
objects::{FaceSet, Sketch},
services::Services,
};
use fj_math::Aabb;
pub trait Shape {
type Brep;
fn compute_brep(
&self,
services: &mut Services,
debug_info: &mut DebugInfo,
) -> Self::Brep;
fn bounding_volume(&self) -> Aabb<3>;
}
impl Shape for fj::Shape {
type Brep = FaceSet;
fn compute_brep(
&self,
services: &mut Services,
debug_info: &mut DebugInfo,
) -> Self::Brep {
match self {
Self::Shape2d(shape) => {
shape.compute_brep(services, debug_info).faces().clone()
}
Self::Group(shape) => shape.compute_brep(services, debug_info),
Self::Sweep(shape) => shape
.compute_brep(services, debug_info)
.shells()
.map(|shell| shell.faces().clone())
.reduce(|mut a, b| {
a.extend(b);
a
})
.unwrap_or_default(),
Self::Transform(shape) => shape.compute_brep(services, debug_info),
}
}
fn bounding_volume(&self) -> Aabb<3> {
match self {
Self::Shape2d(shape) => shape.bounding_volume(),
Self::Group(shape) => shape.bounding_volume(),
Self::Sweep(shape) => shape.bounding_volume(),
Self::Transform(shape) => shape.bounding_volume(),
}
}
}
impl Shape for fj::Shape2d {
type Brep = Sketch;
fn compute_brep(
&self,
services: &mut Services,
debug_info: &mut DebugInfo,
) -> Self::Brep {
match self {
Self::Difference(shape) => shape.compute_brep(services, debug_info),
Self::Sketch(shape) => shape.compute_brep(services, debug_info),
}
}
fn bounding_volume(&self) -> Aabb<3> {
match self {
Self::Difference(shape) => shape.bounding_volume(),
Self::Sketch(shape) => shape.bounding_volume(),
}
}
}