rust-3d

written in Rust source documentation

2D/3D container / algorithm library with IO methods. rust-3d‘s algorithms and most of its containers never use concrete types but abstract traits.
This results in a very generic code base where concrete types can easily be plugged into existing code by implementing the required traits.

Traits within rust-3d

The used traits are minimalistic. It should be very easy to implement them. Therefore there are quite many traits, split depending on the type of access.

HasBoundingBox2D
HasBoundingBox3D
HasCenterOfGravity2D
HasCenterOfGravity3D
HasLength
IsEditable2D
IsEditable3D
IsEditableND
IsBuildable2D
IsBuildable3D
IsBuildableND
Is2D
Is3D
IsRandomAccessible
IsRandomInsertible
IsEditableMesh
IsKNearestSearchable
IsSphereSearchable
IsBox3DSearchable
IsMesh
IsMesh3D
IsTopologyUnit
IsSearchableMesh
IsMovable2D
IsMovable3D
IsNormalized2D
IsNormalized3D
IsOcTree
IsPlane3D
IsProjectionToPlane
IsTree3D
IsVoxelImage
IsTransFormableTo2D
IsTransFormableTo3D
IsFilter
IsFilterRandomAccessible
IsViewBuildable
IsND
IsSortableND
IsSortable2D
IsSortable3D
IsMergeable
HasDistanceTo
IsDirectionField2D
IsDirectionField3D

Traits are also implemented for std containers

Traits of rust-3d are already implemented for the std containers. This makes it possible to directly use the std containers for many algorithms.

impl<T> IsRandomAccessible<T> for Vec<T> {
    fn len(&self) -> usize {
        self.len()
    }
}

impl<T> IsRandomInsertible<T> for Vec<T> {
    fn push(&mut self, x: T) {
        self.push(x)
    }

    fn insert(&mut self, index: usize, x: T) -> Result<()> {
        ...
    }
}

Algorithms depend on as few traits as possible

Since most algorithms are defined for as few traits as possible, this makes it very easy to plug your type into them.

pub fn save_ply_ascii<M, P>(mesh: &M, filepath: &str) -> Result<()> where
    M: IsMesh<P, Face3>,
    P: IsBuildable3D {
    ...
}

pub fn convex_hull_2d<RA, P>(ra: &RA) -> Vec<P> where
    RA: IsRandomAccessible<P>,
    P: Is2D + IsBuildable2D + Clone {
    ...
}

Wrappers or transformers for traits

There’s multiple wrappers or transformers which can lift your type to also implement other traits.

pub struct FilterDirectionField3D<DF> where
    DF: IsDirectionField3D {
        ...
}

impl<DF, P, N> IsFilter<(P, N)> for FilterDirectionField3D<DF> where
    DF: IsDirectionField3D,
    P:  Is3D,
    N:  IsNormalized3D {
    ...
}

Types defined within rust-3d implement as many traits as possible

rust-3d‘s types implement as many traits as possible to make them as useful as possible.

pub struct FilterCircle { ... }

impl FilterCircle { ... }

impl IsND for FilterCircle { ... }

impl Is2D for FilterCircle { ... }

impl IsBuildableND for FilterCircle { ... }

impl IsBuildable2D for FilterCircle { ... }

impl IsEditableND for FilterCircle { ... }

impl IsEditable2D for FilterCircle { ... }

impl HasBoundingBox2D for FilterCircle { ... }

impl<T> IsFilter<T> for FilterCircle where
    T: Is2D { ... }