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 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* angtof: a units argument outside 0..=4 gives nil instead of reading degrees (CodeRabbit)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
This commit is contained in:
NetterSilver
2026-10-24 01:51:21 -04:00
committed by GitHub
co-authored by Claude Haiku 5.5 Brandon Thomas
parent 6842b8774b
commit 2bc3b02ea1
2 changed files with 17 additions and 1 deletions
+8 -1
View File
@@ -1069,7 +1069,14 @@ pub fn distof(_ctx: &mut Ctx<'_>, a: Vec<Value>) -> Result<Flow, LispError> {
pub fn angtof(ctx: &mut Ctx<'_>, a: Vec<Value>) -> Result<Flow, LispError> {
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).
+9
View File
@@ -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");
}