mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 02:46:51 -06:00
Fix LISP getangle subtracting ANGBASE in degrees from radians (#1883)
Found while testing crates/engine/src/lisp/input.rs:256-258 (lisp_angbase, used at :127 and :183); cause is crates/engine/src/sysvars.rs:141 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0299a3eaa0
commit
2c59eb19c5
@@ -260,7 +260,7 @@ fn keyword(keywords: &[String], t: &str) -> Option<String> {
|
||||
impl Session {
|
||||
/// ANGBASE (radians).
|
||||
fn lisp_angbase(&self) -> f64 {
|
||||
crate::sysvars::get(self, "ANGBASE").and_then(|v| v.as_f64()).unwrap_or(0.0)
|
||||
self.doc().map(|d| d.header.f64("ANGBASE", 0.0)).unwrap_or(0.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -497,6 +497,24 @@ fn interactive_routine_waits_for_the_user() {
|
||||
assert!(s.doc().unwrap().model.iter().any(|e| matches!(&e.kind, cadcraft_doc::EntityKind::Circle(c) if c.center.x == 50.0 && c.radius == 2.0)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getangle_is_relative_to_angbase() {
|
||||
let mut s = session();
|
||||
s.cmdline("(setvar \"ANGBASE\" 90)").unwrap();
|
||||
// A picked point at 180° in world terms is 90° from ANGBASE.
|
||||
s.cmdline("(setq a (getangle '(0 0)))").unwrap();
|
||||
s.input(crate::Input::Point(cadcraft_geom::Vec2::new(-1.0, 0.0))).unwrap();
|
||||
assert_eq!(to_text(&s.lisp_var("A"), true), "1.5708");
|
||||
// getorient ignores ANGBASE.
|
||||
s.cmdline("(setq o (getorient '(0 0)))").unwrap();
|
||||
s.input(crate::Input::Point(cadcraft_geom::Vec2::new(-1.0, 0.0))).unwrap();
|
||||
assert_eq!(to_text(&s.lisp_var("O"), true), "3.14159");
|
||||
// A typed angle is already measured from ANGBASE.
|
||||
s.cmdline("(setq t2 (getangle))").unwrap();
|
||||
s.cmdline("180").unwrap();
|
||||
assert_eq!(to_text(&s.lisp_var("T2"), true), "3.14159");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn appload_and_load() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user