Skip to content

armgit / forma

Public Imported from GitHub
0

A 1.2 MB pure-Rust rewrite of headless Blender built for AI agents — 3D B-rep modeling engine, CLI, and MCP server

Merge remote-tracking branch 'origin/main' into pr-98

wrong-nebula75a6c4e870b3
diff --cc crates/forma-core/tests/kernel_tests.rs
index b8da137,920b49f..4b1e90f
--- a/crates/forma-core/tests/kernel_tests.rs
+++ b/crates/forma-core/tests/kernel_tests.rs
@@@ -1151,56 -1157,141 +1157,195 @@@ fn test_deform_curve_on_3d_bezier_has_n
assert!(inv.is_valid_solid());
}
+#[test]
+fn test_issue_93_open_top_requires_flat_top_face() {
+ let sph = forma_core::primitives::make_sphere(1.0, 24, 16, 1);
+ let err = forma_core::ops::shell_solid(&sph, 0.1, true, 2).unwrap_err();
+ assert!(err.contains("open_top=true"), "expected open_top error on sphere, got {err}");
+ let err2 = forma_core::deform::solidify_mesh(&sph, 0.1, -1.0, true, 3).unwrap_err();
+ assert!(err2.contains("open_top=true"), "expected open_top error on solidify sphere, got {err2}");
+
+ let mut hcyl = forma_core::primitives::make_cylinder(1.0, 3.0, 24, 4);
+ hcyl.rotate_deg(0.0, 90.0, 0.0);
+ assert!(forma_core::ops::shell_solid(&hcyl, 0.1, true, 5).is_err());
+
+ // Closed shell (open_top=false) on sphere still works cleanly
+ let closed = forma_core::ops::shell_solid(&sph, 0.1, false, 6).unwrap();
+ let cinv = MeshInvariants::compute(&closed);
+ assert!(cinv.is_valid_solid() && cinv.components == 2);
+}
+
+#[test]
+fn test_issue_94_bevel_general_polyhedron_is_deterministic() {
+ let build = || -> Vec<u8> {
+ let mut m = forma_core::primitives::make_box(2.0, 1.0, 1.0, 1);
+ m = forma_core::ops::bevel_edges(&m, &EdgeSelector::All, 0.1, 1, 2).unwrap();
+ let stats = forma_core::uv::unwrap_lscm(&mut m, 45.0, 0.01).unwrap();
+ assert_eq!(stats.inverted_tris, 0);
+ forma_core::export::write_glb_bytes(&m, true).unwrap()
+ };
+ let first = build();
+ for _ in 0..8 {
+ assert_eq!(build(), first, "bevel(all) + unwrap() must produce byte-identical GLB");
+ }
+}
+
+#[test]
+fn test_issue_81_remesh_voxel_preserves_center_all_axes() {
+ for &vs in &[0.03, 0.05, 0.1] {
+ let b = forma_core::primitives::make_box(1.0, 1.0, 1.0, 1);
+ let r = forma_core::remesh::remesh_voxel(&b, vs, 2).unwrap();
+ let c = r.aabb().center();
+ assert!(
+ c.len() < 1e-3,
+ "voxel_size={vs}: expected center near (0,0,0), got {c:?}"
+ );
+ }
+ let mut b_off = forma_core::primitives::make_box(1.0, 1.0, 1.0, 3);
+ b_off.translate(Vec3::new(10.0, 10.0, 10.0));
+ let r_off = forma_core::remesh::remesh_voxel(&b_off, 0.1, 4).unwrap();
+ let c_off = r_off.aabb().center();
+ assert!(
+ (c_off - Vec3::new(10.0, 10.0, 10.0)).len() < 1e-3,
+ "translated box center shifted to {c_off:?}"
+ );
+}
++
+ #[test]
+ fn test_issue_78_high_res_twisted_loft_shell_and_cut() {
+ use forma_core::boolean::has_self_intersections;
+ use std::f64::consts::PI;
+
+ let side = 0.20_f64;
+ let r_corner = 0.03_f64;
+ let inr = side / (2.0 * 3.0_f64.sqrt());
+ let cd = 2.0 * (inr - r_corner);
+ let levels = [0.0_f64, 0.10, 0.20, 0.30];
+
+ // Exact rounded-equilateral-triangle polar radius sampler from issue #78
+ let polar_radii = |n: usize, flip: bool, rr: f64| -> Vec<f64> {
+ let samples = 240usize;
+ let mut boundary: Vec<(f64, f64)> = Vec::with_capacity(3 * samples);
+ for k in 0..3 {
+ let t = (90.0 + 120.0 * (k as f64) + if flip { 180.0 } else { 0.0 }).to_radians();
+ let (cx, cy) = (cd * t.cos(), cd * t.sin());
+ for j in 0..samples {
+ let a = t - 60.0_f64.to_radians() + 120.0_f64.to_radians() * (j as f64) / (samples as f64);
+ boundary.push((cx + rr * a.cos(), cy + rr * a.sin()));
+ }
+ }
+ let m = boundary.len();
+ (0..n)
+ .map(|i| {
+ let phi = 2.0 * PI * (i as f64) / (n as f64);
+ let (dx, dy) = (phi.cos(), phi.sin());
+ let mut best = f64::INFINITY;
+ for j in 0..m {
+ let (x1, y1) = boundary[j];
+ let (x2, y2) = boundary[(j + 1) % m];
+ let (ex, ey) = (x2 - x1, y2 - y1);
+ let den = dx * ey - dy * ex;
+ if den.abs() < 1e-15 {
+ continue;
+ }
+ let t = (x1 * ey - y1 * ex) / den;
+ let u = (x1 * dy - y1 * dx) / den;
+ if t > 0.0 && (-1e-9..=1.0 + 1e-9).contains(&u) && t < best {
+ best = t;
+ }
+ }
+ best
+ })
+ .collect()
+ };
+
+ let build_sections = |n: usize, sub: usize, rr: f64, z0: f64, ztop: f64| -> Vec<(f64, Vec<(f64, f64)>)> {
+ let ra = polar_radii(n, false, rr);
+ let rb = polar_radii(n, true, rr);
+ let mut raw: Vec<(f64, Vec<f64>)> = Vec::new();
+ for l in 0..3 {
+ let (a, b) = if l % 2 == 0 { (&ra, &rb) } else { (&rb, &ra) };
+ for s in 0..sub {
+ let f = (s as f64) / (sub as f64);
+ let w = 0.5 - 0.5 * (PI * f).cos();
+ let zl = (levels[l] + f * (levels[l + 1] - levels[l])).max(z0);
+ let rs: Vec<f64> = (0..n).map(|i| a[i] * (1.0 - w) + b[i] * w).collect();
+ raw.push((zl, rs));
+ }
+ }
+ raw.push((if ztop > levels[3] { ztop } else { levels[3] }, rb));
+ let mut dedup: Vec<(f64, Vec<f64>)> = Vec::new();
+ for (z, r) in raw {
+ if let Some(prev) = dedup.last_mut() {
+ if (prev.0 - z).abs() < 1e-9 {
+ *prev = (z, r);
+ continue;
+ }
+ }
+ dedup.push((z, r));
+ }
+ dedup
+ .into_iter()
+ .map(|(z, rs)| {
+ let z_r = (z * 1e5).round() * 1e-5;
+ let poly: Vec<(f64, f64)> = (0..n)
+ .map(|i| {
+ let phi = 2.0 * PI * (i as f64) / (n as f64);
+ let x = (rs[i] * phi.cos() * 1e5).round() * 1e-5;
+ let y = (rs[i] * phi.sin() * 1e5).round() * 1e-5;
+ (x, y)
+ })
+ .collect();
+ (z_r, poly)
+ })
+ .collect()
+ };
+
+ // Part 1: shell(0.01) must succeed even when vertical section spacing dz <= thickness (SUB >= 9..15)
+ for (n, sub) in [(48usize, 9usize), (48, 10), (48, 12), (48, 15), (96, 12)] {
+ let outer = forma_core::primitives::make_loft(&build_sections(n, sub, r_corner, 0.0, 0.30), n, 1).unwrap();
+ for open_top in [true, false] {
+ let shelled = forma_core::ops::shell_solid(&outer, 0.01, open_top, 2)
+ .unwrap_or_else(|e| panic!("shell(0.01, open_top={open_top}) failed at N={n} SUB={sub}: {e}"));
+ let inv = MeshInvariants::compute(&shelled);
+ assert!(
+ inv.is_valid_solid() && inv.genus == 0 && !has_self_intersections(&shelled),
+ "invalid shell(0.01, open_top={open_top}) at N={n} SUB={sub}: {inv:?}"
+ );
+ }
+ }
+ // Excessive thickness (> 30 mm corner radius) must still be cleanly rejected
+ let outer_48 = forma_core::primitives::make_loft(&build_sections(48, 12, r_corner, 0.0, 0.30), 48, 3).unwrap();
+ assert!(
+ forma_core::ops::shell_solid(&outer_48, 0.045, true, 4).is_err(),
+ "shell exceeding corner radius must still return Err"
+ );
+
+ // Part 2: outer_loft | cut(inner_loft) across previously failing (N, SUB) combinations
+ for (n, sub) in [
+ (32usize, 8usize),
+ (32, 12),
+ (48, 12),
+ (64, 6),
+ (64, 10),
+ (64, 12),
+ (96, 6),
+ (96, 8),
+ (96, 10),
+ (96, 11),
+ (96, 12),
+ (128, 6),
+ (128, 10),
+ (128, 12),
+ ] {
+ let outer = forma_core::primitives::make_loft(&build_sections(n, sub, r_corner, 0.0, 0.30), n, 10).unwrap();
+ let inner = forma_core::primitives::make_loft(&build_sections(n, sub, r_corner - 0.01, 0.01, 0.32), n, 11).unwrap();
+ let vase = forma_core::boolean::boolean_op(&outer, &inner, BoolOp::Difference, None, 12)
+ .unwrap_or_else(|e| panic!("loft cut failed at N={n} SUB={sub}: {e}"));
+ let inv = MeshInvariants::compute(&vase);
+ assert!(
+ inv.is_valid_solid() && inv.genus == 0 && !has_self_intersections(&vase),
+ "invalid loft cut at N={n} SUB={sub}: {inv:?}"
+ );
+ }
+ }