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"); +}