Kernel rig: the ellipse length's Simpson weights as a named step

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jyviko
2026-10-29 16:59:59 -04:00
committed by Irakli Kourtis
parent 67dd8892f1
commit 235645db50
+18 -2
View File
@@ -361,7 +361,13 @@ fn dxf_layers(text: &str) -> Value {
let n = 4096;
let speed = |t: f64| (a * t.sin()).hypot(b * t.cos());
let h = sweep / n as f64;
let sum: f64 = (0..=n).map(|k| speed(t0 + k as f64 * h) * if k == 0 || k == n { 1.0 } else if k % 2 == 1 { 4.0 } else { 2.0 }).sum();
let weight = |k: usize| match k {
0 => 1.0,
k if k == n => 1.0,
k if k % 2 == 1 => 4.0,
_ => 2.0,
};
let sum: f64 = (0..=n).map(|k| speed(t0 + k as f64 * h) * weight(k)).sum();
Some(sum * h / 3.0)
}
_ => None,
@@ -809,7 +815,17 @@ mod tests {
vec![("0", "ARC"), ("8", "OUTLINE"), ("10", "0"), ("20", "0"), ("40", "2"), ("50", "270"), ("51", "0")],
vec![("0", "CIRCLE"), ("8", "CUT"), ("10", "5"), ("20", "5"), ("40", "1")],
vec![("0", "LWPOLYLINE"), ("8", "BEND_UP"), ("90", "2"), ("70", "128"), ("10", "0"), ("20", "1"), ("10", "10"), ("20", "1")],
vec![("0", "ELLIPSE"), ("8", "CUT"), ("10", "0"), ("20", "0"), ("11", "10"), ("21", "0"), ("40", "1"), ("41", "0"), ("42", "6.283185307179586")],
vec![
("0", "ELLIPSE"),
("8", "CUT"),
("10", "0"),
("20", "0"),
("11", "10"),
("21", "0"),
("40", "1"),
("41", "0"),
("42", "6.283185307179586"),
],
] {
for (c, v) in e {
t += &pair(c, v);