Tests: the extruded ellipse is checked by its area, not its face count

free_form_profiles_extrude_exactly asked for an ellipse extrusion of exactly
3 faces and a spline-and-line extrusion of at most 5: how many pieces the
kernel cuts a closed side into. It now checks that the sides are exact.

Ellipse a = 10, b = 4, extruded 5: area = 2 pi a b + 5 P, P = 4a E(e),
e^2 = 1 - b^2/a^2. By the Gauss-Kummer series, P = pi (a + b) sum_k
(binom(1/2, k))^2 h^k, h = ((a - b)/(a + b))^2 = 9/49: P = 46.026225191330
(a 200000-point midpoint integral of sqrt(a^2 sin^2 + b^2 cos^2) agrees to
1e-13). A = 80 pi + 230.131126 = 481.458538 mm^2, asserted to 1e-4; a faceted
side would be short of it. Only the top and bottom are planes
(face_types.plane = 2, merged pieces counted once).

The fit spline closed by a line: the planes are its top, bottom and the line's
side (face_types.plane = 3); its volume stays checked against the profile
area.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jyviko
2026-10-30 06:38:11 -04:00
committed by Irakli Kourtis
parent 978ae1d512
commit 2be7b1b6fa
+7 -2
View File
@@ -1259,8 +1259,12 @@ fn free_form_profiles_extrude_exactly() {
run(&mut s, "solid.extrude", json!({"distance": 5}));
let v = vol(&mut s);
assert!((v - pi * 40.0 * 5.0).abs() / (pi * 200.0) < 2e-4, "{v}");
// An exact ellipse: its side's area is h times the perimeter, 4a E(e), e² = 1 − b²/a²
// (by the Gauss–Kummer series, P = 46.026225), and only the top and bottom are planes.
let m = run(&mut s, "inspect.measure", json!({}));
assert_eq!(m["bodies"][0]["faces"], 3, "an exact ellipse: top, bottom and one side ({m})");
let area = m["bodies"][0]["area_mm2"].as_f64().unwrap_or(f64::NAN);
assert!((area - (2.0 * pi * 40.0 + 5.0 * 46.026_225_191_329_7)).abs() < 1e-4, "{area} ({m})");
assert_eq!(m["bodies"][0]["face_types"]["plane"], 2, "{m}");
// A region closed by a fit spline and a line.
let mut s = new_sketch();
let sp = ids(&run(&mut s, "sketch.spline.fit_point", json!({"points": [[0, 0], [10, 8], [20, 0]]}))["curves"])[0].clone();
@@ -1270,8 +1274,9 @@ fn free_form_profiles_extrude_exactly() {
run(&mut s, "solid.extrude", json!({"distance": 2}));
let v = vol(&mut s);
assert!((v - a * 2.0).abs() / (a * 2.0) < 2e-4, "{v} vs {}", a * 2.0);
// Exact: the spline's side is curved, the planes are the top, the bottom and the line's side.
let m = run(&mut s, "inspect.measure", json!({}));
assert!(m["bodies"][0]["faces"].as_u64().unwrap() <= 5, "{m}");
assert_eq!(m["bodies"][0]["face_types"]["plane"], 3, "{m}");
}
#[test]