From eeb2eb17862d2d5c0f1bb80c1a65c76859c844bd Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 10 Oct 2024 19:05:53 +0200 Subject: [PATCH] Add `SurfaceGeom::generate_tri_mesh` --- crates/fj-core/src/geometry/surface.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/fj-core/src/geometry/surface.rs b/crates/fj-core/src/geometry/surface.rs index d7177d8a4..4d784ba02 100644 --- a/crates/fj-core/src/geometry/surface.rs +++ b/crates/fj-core/src/geometry/surface.rs @@ -1,6 +1,6 @@ //! The geometry that defines a surface -use fj_math::{Point, Scalar, Transform, Triangle, Vector}; +use fj_math::{Aabb, Point, Scalar, Transform, Triangle, Vector}; use super::{traits::GenPolyline, Path, Tolerance}; @@ -76,6 +76,30 @@ impl SurfaceGeom { (triangle, barycentric_coords) } + /// # Generated a triangle mesh within the provided boundary + pub fn generate_tri_mesh( + &self, + boundary: Aabb<2>, + tolerance: Tolerance, + ) -> Vec> { + let boundary_curve = [[boundary.min.u], [boundary.max.u]]; + let points_curve = + self.u.generate_polyline(boundary_curve.into(), tolerance); + + points_curve + .iter() + .copied() + .map(|point| [point.t, Scalar::ZERO]) + .chain( + points_curve + .iter() + .copied() + .map(|point| [point.t, self.v.magnitude()]), + ) + .map(Point::from) + .collect() + } + /// Convert a point in surface coordinates to model coordinates pub fn point_from_surface_coords( &self,