A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server
fix(core): point_in_tri_3d tolerance as a distance
pnooyen49b0365c922d
diff --git a/crates/forma-core/src/boolean.rs b/crates/forma-core/src/boolean.rsindex 8ff6653..78ba21c 100644--- a/crates/forma-core/src/boolean.rs+++ b/crates/forma-core/src/boolean.rs@@ -707,7 +707,9 @@ fn point_in_tri_3d(p: Vec3, t: &Tri) -> bool {let c0 = e0.cross(p - t.v[0]).dot(t.normal);let c1 = e1.cross(p - t.v[1]).dot(t.normal);let c2 = e2.cross(p - t.v[2]).dot(t.normal);- c0 >= -1e-7 && c1 >= -1e-7 && c2 >= -1e-7+ // Each `c` is the edge's length times `p`'s distance inside it: the tolerance is a distance,+ // or a short edge would take in points far past it.+ c0 >= -1e-7 * e0.len() && c1 >= -1e-7 * e1.len() && c2 >= -1e-7 * e2.len()}#[derive(Clone, Copy, PartialEq, Eq)]@@ -3073,3 +3075,17 @@ fn self_intersection_pass(mesh: &PolyMesh, frame: Option<[Vec3; 3]>, budget: u64}OverlapCheck::Clear}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn point_in_tri_tolerance_is_a_distance_even_past_a_short_edge() {+ // A long sliver whose short edge, 1e-4 long, closes it at x = 1.+ let t = Tri::from_verts(Vec3::new(0.0, 0.0, 0.0), Vec3::new(1.0, 0.0, 0.0), Vec3::new(1.0, 1e-4, 0.0), 0, 0, 0).unwrap();+ assert!(point_in_tri_3d(Vec3::new(0.999, 0.5e-4, 0.0), &t));+ // 1e-4 past the short edge, within the wedge of the long ones: outside.+ assert!(!point_in_tri_3d(Vec3::new(1.0001, 0.5e-4, 0.0), &t));+ }+}