pub mod manifold;
use crate::error::Result;
use crate::geom::Aabb;
use crate::mesh::TriMesh;
use crate::stock::StockShape;
use crate::sweep::SweptVolume;
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SolidSummary {
pub bounds: Aabb,
pub signed_volume: f64,
pub triangles: usize,
}
impl SolidSummary {
pub fn volume(&self) -> f64 {
self.signed_volume.abs()
}
}
pub trait Kernel: Send + Sync {
type Solid: Clone + Send + Sync;
fn name(&self) -> &'static str;
fn make_stock(&self, shape: &StockShape, chord_tolerance: f64) -> Result<Self::Solid>;
fn make_mesh(&self, mesh: &TriMesh, merge_tolerance: f64) -> Result<Self::Solid>;
fn offset(&self, solid: &Self::Solid, distance: f64, chord_tolerance: f64) -> Result<Self::Solid>;
fn make_swept(&self, volume: &SweptVolume) -> Result<Self::Solid>;
fn make_swept_pieces(&self, volume: &SweptVolume) -> Result<Vec<Self::Solid>> {
Ok(vec![self.make_swept(volume)?])
}
fn difference(&self, a: &Self::Solid, b: &Self::Solid) -> Result<Self::Solid>;
fn intersection(&self, a: &Self::Solid, b: &Self::Solid) -> Result<Self::Solid>;
fn union_all(&self, solids: &[Self::Solid]) -> Result<Self::Solid>;
fn volume(&self, solid: &Self::Solid) -> f64;
fn triangle_count(&self, solid: &Self::Solid) -> usize;
fn simplify(&self, solid: &Self::Solid, tolerance: f64) -> Result<Self::Solid>;
fn is_empty(&self, solid: &Self::Solid) -> bool;
fn components(&self, solid: &Self::Solid) -> Vec<Self::Solid>;
fn compose(&self, parts: &[Self::Solid]) -> Result<Self::Solid>;
fn mesh(&self, solid: &Self::Solid) -> TriMesh;
fn summary(&self, solid: &Self::Solid) -> SolidSummary {
let mesh = self.mesh(solid);
SolidSummary {
bounds: mesh.bounds(),
signed_volume: mesh.signed_volume(),
triangles: mesh.triangle_count(),
}
}
fn validate(&self, solid: &Self::Solid) -> Result<()>;
fn with_fresh_id(&self, solid: &Self::Solid) -> (Self::Solid, u32);
fn mesh_with_sources(&self, solid: &Self::Solid) -> (TriMesh, Vec<u32>);
}