pub fn calc_triangles(elevation_fn: impl Fn(f64, f64) -> f32, grid: PointCloud) -> Vec<Triangle3D> {
  println!("Triangulating ...");
  let points: Vec<Point> = grid
    .iter()
    .map(|p| Point {
      x: p.x as f64,
      y: p.y as f64,
    })
    .collect();

  let delauney = triangulate(&points).expect("No triangulation exists.");

  // delauney.triangles is flat array,
  // where every 3 values represents the indices of the points of a triangle
  println!("Mapping to Triangle3D ...");
  (0..delauney.triangles.len() / 3)
    .map(|n| {
      let vertices: Vec<Point3> = (3 * n..=3 * n + 2) // indices of delauney.triangles
        .map(|i| delauney.triangles[i]) // indices of points
        .map(|p| points[p].clone()) // the actual points
        .map(|p| {
          // 3D point
          pt3(p.x as f32, p.y as f32, elevation_fn(p.x, p.y))
        })
        .collect();
      Triangle3D { vertices }
    })
    .collect()
}
/// Calculates the Delauney triangulation for the given PointCloud,
/// then maps the 2D points to 3D using an elevation function for the z coodinate.
Calculates the Delauney triangulation for the given PointCloud,
then maps the 2D points to 3D using an elevation function for the z coodinate.
Calculates the Delauney triangulation for the given PointCloud then maps the 2D points to 3D using an elevation function for the z coodinate .
pub fn calc_triangles(elevation_fn: impl Fn(f64, f64) -> f32, grid: PointCloud) -> Vec<Triangle3D> {
  println!("Triangulating ...");
  let points: Vec<Point> = grid
    .iter()
    .map(|p| Point {
      x: p.x as f64,
      y: p.y as f64,
    })
    .collect();
  let delauney = triangulate(&points).expect("No triangulation exists.");
  // delauney.triangles is flat array,
  // where every 3 values represents the indices of the points of a triangle
  println!("Mapping to Triangle3D ...");
  (0..delauney.triangles.len() / 3)
    .map(|n| {
      let vertices: Vec<Point3> = (3 * n..=3 * n + 2) // indices of delauney.triangles
        .map(|i| delauney.triangles[i]) // indices of points
        .map(|p| points[p].clone()) // the actual points
        .map(|p| {
          // 3D point
          pt3(p.x as f32, p.y as f32, elevation_fn(p.x, p.y))
        })
        .collect();
      Triangle3D { vertices }
    })
    .collect()
}
pub fn calc_triangles ( elevation_fn : impl Fn ( f64 , f64 ) -> f32 , grid : PointCloud ) -> Vec < Triangle3D > { println ! ( " " ) ; let points : Vec < Point > = grid . iter ( ) . map ( | p | Point { x : p . x as f64 , y : p . y as f64 , } ) . collect ( ) ; let delauney = triangulate ( & points ) . expect ( " " ) ; // delauney.triangles is flat array, // where every 3 values represents the indices of the points of a triangle println ! ( " " ) ; ( 0 .. delauney . triangles . len ( ) / 3 ) . map ( | n | { let vertices : Vec < Point3 > = ( 3 * n ..= 3 * n + 2 ) // indices of delauney.triangles . map ( | i | delauney . triangles [ i ] ) // indices of points . map ( | p | points [ p ] . clone ( ) ) // the actual points . map ( | p | { // 3D point pt3 ( p . x as f32 , p . y as f32 , elevation_fn ( p . x , p . y ) ) } ) . collect ( ) ; Triangle3D { vertices } } ) . collect ( ) }
Calculates the Delauney triangulation for the given PointCloud,
then maps the 2D points to 3D using an elevation function for the z coodinate.
Calculates the Delauney triangulation for the given PointCloud then maps the 2D points to 3D using an elevation function for the z coodinate .
elevation_fn
impl Fn(f64, f64) -> f32
grid
PointCloud