[][src]Module plexus::builder

Incremental polygonal mesh construction.

This module provides traits for incrementally constructing mesh data structures. This API allows for meshes to be constructed in a way that is agnostic to the specific data structure used to represent the mesh.

Buildable is the primary trait of this API. It is implemented by mesh data structures and exposes various associated types for their associated data. Buildable exposes a builder type via its builder function. This builder type in turn provides additional builders that can be used to construct a mesh from surfaces and facets.

Examples

A function that generates a triangle from point geometry using builders:

use nalgebra::Point2;
use plexus::buffer::MeshBuffer3;
use plexus::builder::Buildable;
use plexus::geometry::FromGeometry;
use plexus::graph::MeshGraph;
use plexus::prelude::*;

type E2 = Point2<f64>;

fn trigon<B, T>(points: [T; 3]) -> Result<B, B::Error>
where
    B: Buildable,
    B::Vertex: FromGeometry<T>,
{
    let mut builder = B::builder();
    builder.surface_with(|builder| {
        let [a, b, c] = points;
        let a = builder.insert_vertex(a)?;
        let b = builder.insert_vertex(b)?;
        let c = builder.insert_vertex(c)?;
        builder.facets_with(|builder| builder.insert_facet(&[a, b, c], B::Facet::default()))
    })?;
    builder.build()
}

// `MeshBuffer` and `MeshGraph` implement the `Buildable` trait.
let graph: MeshGraph<E2> = trigon([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0)]).unwrap();
let buffer: MeshBuffer3<usize, E2> = trigon([(0.0, 0.0), (0.0, 1.0), (1.0, 1.0)]).unwrap();

Traits

Buildable

Polygonal mesh data structure that can be built incrementally.

FacetBuilder
MeshBuilder

Incremental polygonal mesh builder.

SurfaceBuilder