Convert Topology::triangles into free function

This commit is contained in:
Hanno Braun 2022-03-21 17:24:54 +01:00
parent 7a7eca5788
commit b483a5dd4a
4 changed files with 26 additions and 22 deletions

View File

@ -11,6 +11,7 @@ use std::{collections::HashMap, time::Instant};
use fj_debug::DebugInfo;
use fj_host::Model;
use fj_kernel::algorithms::triangulate;
use fj_math::{Aabb, Scalar, Triangle};
use fj_operations::ToShape as _;
use futures::executor::block_on;
@ -296,10 +297,12 @@ impl ShapeProcessor {
let mut debug_info = DebugInfo::new();
let mut triangles = Vec::new();
shape
.to_shape(tolerance, &mut debug_info)
.topology()
.triangles(tolerance, &mut triangles, &mut debug_info);
triangulate(
shape.to_shape(tolerance, &mut debug_info),
tolerance,
&mut triangles,
&mut debug_info,
);
ProcessedShape {
aabb,

View File

@ -8,6 +8,7 @@ mod sweep;
mod triangulation;
pub use self::{
approximation::Approximation, sweep::sweep_shape,
triangulation::delaunay,
approximation::Approximation,
sweep::sweep_shape,
triangulation::{delaunay, triangulate},
};

View File

@ -1,8 +1,21 @@
use fj_math::Scalar;
use fj_debug::DebugInfo;
use fj_math::{Scalar, Triangle};
use parry2d_f64::utils::point_in_triangle::{corner_direction, Orientation};
use spade::HasPosition;
use crate::geometry;
use crate::{geometry, shape::Shape};
/// Triangulate a shape
pub fn triangulate(
mut shape: Shape,
tolerance: Scalar,
out: &mut Vec<Triangle<3>>,
debug_info: &mut DebugInfo,
) {
for face in shape.topology().faces() {
face.get().triangles(tolerance, out, debug_info);
}
}
/// Create a Delaunay triangulation of all points
pub fn delaunay(

View File

@ -1,7 +1,6 @@
use std::collections::HashSet;
use fj_debug::DebugInfo;
use fj_math::{Point, Scalar, Triangle, Vector};
use fj_math::{Point, Scalar, Vector};
use crate::{
geometry::{Circle, Curve, Line},
@ -238,18 +237,6 @@ impl Topology<'_> {
pub fn faces(&self) -> Iter<Face> {
Iter::new(self.geometry.faces)
}
/// Triangulate the shape
pub fn triangles(
&self,
tolerance: Scalar,
out: &mut Vec<Triangle<3>>,
debug_info: &mut DebugInfo,
) {
for face in &*self.geometry.faces {
face.get().triangles(tolerance, out, debug_info);
}
}
}
#[cfg(test)]