Convert typed ellipse arc angles to ellipse parameters (#82) (#143)

This commit is contained in:
MarekSpodBiedry 2026-10-10 18:12:41 +02:00 committed by GitHub
parent 3ef52e31d8
commit 279c1bed6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View File

@ -822,7 +822,10 @@ impl Interactive for EllipseM {
ge.param_of(p)
}
Input::Text(t) => {
crate::units::parse_angle(&t).ok_or_else(|| crate::EngineError::Other("Requires an angle.".into()))? + e.major.angle()
// A typed angle is a true angle from the major axis; convert it to an ellipse parameter like a picked point.
let a = crate::units::parse_angle(&t).ok_or_else(|| crate::EngineError::Other("Requires an angle.".into()))?;
let ge = Ellipse { start: 0.0, end: cadcraft_geom::TAU, ..e };
ge.param_of(e.center + Vec2::from_angle(a + e.major.angle()))
}
_ => return Ok(Step::Continue),
};

View File

@ -237,6 +237,17 @@ fn ellipse_axis_and_arc() {
assert!(matches!(last(&s), EntityKind::Ellipse(e) if (e.end - e.start).abs() > 0.1 && (e.end - e.start).abs() < 6.0));
}
#[test]
fn ellipse_arc_typed_angles_are_true_angles() {
let want = 2f64.atan2(1.0);
// Horizontal and rotated major axis, ratio 0.5: typed 0 and 45 degrees match the JSON form.
for line in ["ellipse.arc 0,0 10,0 2.5 0 45", "ellipse.arc 5,-5 5,5 2.5 0 45"] {
let mut s = Session::new();
s.cmdline(line).unwrap();
assert!(matches!(last(&s), EntityKind::Ellipse(e) if e.start.abs() < 1e-9 && (e.end - want).abs() < 1e-9), "{line}");
}
}
// ---------------- DIVIDE / MEASURE ----------------
#[test]