SETVAR accepts point objects for SNAPBASE, LIMMIN, LIMMAX and INSBASE (#485) (#575)

Squash of PR #575 by @MarekSpodBiedry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MarekSpodBiedry 2026-10-11 19:40:10 +02:00 committed by GitHub
parent 40aa4fbf49
commit a5a9e3ef63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -279,7 +279,7 @@ pub fn set(s: &mut Session, name: &str, v: &Value) -> Result<()> {
},
},
Value::Bool(b) => cadcraft_doc::HVal::Int(i64::from(*b)),
Value::Array(_) => cadcraft_doc::HVal::Point(as_pt(v).ok_or_else(bad)?.to3(0.0)),
Value::Array(_) | Value::Object(_) => cadcraft_doc::HVal::Point(as_pt(v).ok_or_else(bad)?.to3(0.0)),
_ => return Err(bad()),
};
// Keep the header type stable for known numeric vars.

View File

@ -440,6 +440,19 @@ fn zoom_extents_fits_drawing() {
assert!(v.height >= 50.0);
}
#[test]
fn setvar_point_variables_take_point_objects() {
let mut s = Session::new();
for name in ["SNAPBASE", "LIMMIN", "LIMMAX", "INSBASE"] {
// GETVAR's own value (an object with z) writes back, and an {x, y} object equals the array form.
let got = sysvars::get(&s, name).unwrap();
s.execute("setvar", &json!({"name": name, "value": got})).unwrap();
s.execute("setvar", &json!({"name": name, "value": {"x": 5, "y": 7}})).unwrap();
assert_eq!(sysvars::get(&s, name), Some(json!({"x": 5.0, "y": 7.0, "z": 0.0})), "{name}");
assert!(s.execute("setvar", &json!({"name": name, "value": {"x": "a", "y": 1}})).is_err());
}
}
#[test]
fn sysvars_roundtrip() {
let mut s = Session::new();