From 2bc3b02ea18d26e85647ff016e384b0f77c4a53d Mon Sep 17 00:00:00 2001 From: NetterSilver <133535268+Silvertree2010@users.noreply.github.com> Date: Sat, 24 Oct 2026 07:51:21 +0200 Subject: [PATCH] Make LISP angtof honour its units argument (#1949) * Make LISP angtof honour its units argument Found while testing crates/engine/src/lisp/drawing.rs:962-966 Co-Authored-By: Claude Haiku 5.5 Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Claude Sonnet 5.5 * angtof: a units argument outside 0..=4 gives nil instead of reading degrees (CodeRabbit) Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Haiku 5.5 Co-authored-by: Brandon Thomas --- crates/engine/src/lisp/drawing.rs | 9 ++++++++- crates/engine/src/lisp/tests.rs | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/lisp/drawing.rs b/crates/engine/src/lisp/drawing.rs index 7e85dd67..b4076fce 100644 --- a/crates/engine/src/lisp/drawing.rs +++ b/crates/engine/src/lisp/drawing.rs @@ -1069,7 +1069,14 @@ pub fn distof(_ctx: &mut Ctx<'_>, a: Vec) -> Result { pub fn angtof(ctx: &mut Ctx<'_>, a: Vec) -> Result { arity(&a, 1, 2)?; let s = string(&a[0])?; - Ok(Flow::Value(ctx.s.angle_settings().direction(&s).map(Value::Real).unwrap_or_default())) + let mut settings = ctx.s.angle_settings(); + // AUNITS 0..=4; any other units argument is an error in AutoCAD, nil here. + match a.get(1) { + None | Some(Value::Nil) => {} + Some(Value::Int(u)) if (0..=4).contains(u) => settings.aunits = i64::from(*u), + Some(_) => return Ok(Flow::Value(Value::Nil)), + } + Ok(Flow::Value(settings.direction(&s).map(Value::Real).unwrap_or_default())) } /// `(trans pt from to [disp])`: points are in the world system throughout (no UCS yet). diff --git a/crates/engine/src/lisp/tests.rs b/crates/engine/src/lisp/tests.rs index b3a09e79..bee6d7d3 100644 --- a/crates/engine/src/lisp/tests.rs +++ b/crates/engine/src/lisp/tests.rs @@ -782,3 +782,12 @@ fn a_panic_inside_a_routine_ends_it_with_an_error() { assert!(s.log.iter().any(|l| l.contains("internal error")), "{:?}", s.log); assert_eq!(ok(&mut s, "(+ 1 2)"), "3"); } + +#[test] +fn angtof_reads_the_string_in_the_given_units() { + let mut s = Session::new(); + assert_eq!(ok(&mut s, "(angtof \"1.5\" 3)"), "1.5"); + assert_eq!(ok(&mut s, "(angtof \"180\" 0)"), "3.14159"); + assert_eq!(ok(&mut s, "(angtof \"180\" 7)"), "nil"); + assert_eq!(ok(&mut s, "(angtof \"180\" \"x\")"), "nil"); +}