truck_polymesh/
meshing_shape.rs

1use crate::*;
2
3impl<P> PolylineCurve<P> {
4    /// meshing the curve
5    pub fn from_curve<C>(curve: C, range: (f64, f64), tol: f64) -> Self
6    where C: ParameterDivision1D<Point = P> {
7        PolylineCurve(curve.parameter_division(range, tol).1)
8    }
9}
10
11impl StructuredMesh {
12    /// meshing the surface
13    /// # Arguments
14    /// * `bspsurface` - bspline surface to meshed
15    /// * `tol` - standard tolerance for meshing
16    pub fn from_surface<S>(
17        surface: &S,
18        range: ((f64, f64), (f64, f64)),
19        tol: f64,
20    ) -> StructuredMesh
21    where
22        S: ParametricSurface3D + ParameterDivision2D,
23    {
24        let (div0, div1) = surface.parameter_division(range, tol);
25        create_mesh(surface, div0, div1)
26    }
27}
28
29fn create_mesh<S>(surface: &S, div0: Vec<f64>, div1: Vec<f64>) -> StructuredMesh
30where S: ParametricSurface3D {
31    let mut positions = vec![Vec::with_capacity(div1.len()); div0.len()];
32    let mut normals = vec![Vec::with_capacity(div1.len()); div0.len()];
33    div0.iter()
34        .zip(positions.iter_mut().zip(normals.iter_mut()))
35        .for_each(|(u, (prow, nrow))| {
36            div1.iter().for_each(move |v| {
37                prow.push(surface.subs(*u, *v));
38                nrow.push(surface.normal(*u, *v));
39            })
40        });
41    StructuredMesh {
42        positions,
43        uv_division: Some((div0, div1)),
44        normals: Some(normals),
45    }
46}