Skip to content

Commit

Permalink
Fix bug when finding smallest triangle angle
Browse files Browse the repository at this point in the history
  • Loading branch information
Makogan (Makogan) committed Jul 15, 2024
1 parent a79b65a commit 5a1a187
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/transformation/mesh_intersection/mesh_intersection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,14 @@ fn insert_into_set(
fn smallest_angle(points: &[Point3<Real>]) -> Real {
let n = points.len();

let mut worst_cos = 2.0;
let mut worst_cos = -2.0;
for i in 0..points.len() {
let d1 = (points[i].coords - points[(i + 1) % n].coords).normalize();
let d2 = (points[(i + 2) % n].coords - points[(i + 1) % n].coords).normalize();

let cos = d1.dot(&d2);

if cos < worst_cos {
worst_cos = cos.abs();
if cos > worst_cos {
worst_cos = cos;
}
}

Expand All @@ -554,7 +553,7 @@ fn project_point_to_segment(point: &Vector3<Real>, segment: &[Vector3<Real>; 2])
let local = point - segment[0];

let norm = dir.norm();
// restrict the result to the segment portion of the line.
// Restrict the result to the segment portion of the line.
let coeff = (dir.dot(&local) / norm).clamp(0., norm);

segment[0] + coeff * dir.normalize()
Expand Down Expand Up @@ -595,11 +594,7 @@ fn is_triangle_degenerate(
worse_projection_distance.min((proj - triangle[i].coords).norm());
}

if worse_projection_distance < epsilon_distance {
return true;
}

false
worse_projection_distance < epsilon_distance
}

fn merge_triangle_sets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl fmt::Display for MeshIntersectionError {
}
Self::TriTriError => f.pad("internal failure while intersecting two triangles"),
Self::DuplicateVertices => f.pad("internal failure while merging faces resulting from intersections"),
Self::TriangulationError => f.pad("internal failure while triangulating an interseciton face"),
}
}
}
Expand Down

0 comments on commit 5a1a187

Please sign in to comment.