b557f22f97
* Sketch: a construction line with a length can be a normal line (#10258) `construction: false` on a construction line command that has a `length` makes the segment a normal sketch line, ready to close a profile, instead of construction geometry. The default stays construction, and an infinite line is always construction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sketch: a length box in the construction line tools (#10258) The horizontal, vertical, parallel and perpendicular construction line tools show a Length box beside the pointer from the start. It stays empty (shown as infinite) and leaves the keyboard to the tool's shortcuts until a digit is typed; then the box takes the keyboard. Without a length the tools work as before: one click, an infinite line. With a length the first click sets the start and a second click the side the segment runs to, sent as the command's `length` and `near`, so the segment gets its length dimension. The angle tool has a Length box beside its Angle box. A typed length keeps the start's snap, and the preview draws the segment the click will create. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sketch: a construction/normal switch in the construction line tools (#10258) A Construction | Normal switch sits under the Length box of the construction line tools. Normal sends `construction: false`, so a segment with a length becomes a normal sketch line, ready to close a profile, without converting it afterwards. The switch starts at Construction with each start of a tool. An infinite line is always construction, so without a length the switch is greyed out and its tooltip says why. It belongs to the tool alone: the Sketch Palette's drawing line type (X) is left as it is. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
2.8 KiB
Rust
62 lines
2.8 KiB
Rust
use serde_json::json;
|
|
|
|
use super::{SplineReverseParams, SplineReverseResult};
|
|
use crate::Session;
|
|
use crate::schema::tests::{assert_keys, assert_strict_keeps_todays_errors, conforms};
|
|
use crate::schema::{ParamCheck, input_schema_for, output_schema_for};
|
|
|
|
#[test]
|
|
fn schemas_and_the_key_check_agree() {
|
|
assert_keys(input_schema_for::<SplineReverseParams>(), &["curve", "sketch"]);
|
|
}
|
|
|
|
#[test]
|
|
fn strict_keeps_todays_errors() {
|
|
assert_strict_keeps_todays_errors(&[
|
|
("sketch.spline.reverse", json!({"curve": 5})),
|
|
("sketch.spline.reverse", json!({"curve": null})),
|
|
("sketch.spline.reverse", json!({"curve": "nope"})),
|
|
("sketch.spline.reverse", json!({"curve": "l1"})),
|
|
]);
|
|
}
|
|
|
|
#[test]
|
|
fn spline_reverse_reply_matches_its_schema() {
|
|
let mut s = Session { param_check: ParamCheck::Warn, ..Session::default() };
|
|
let run = |s: &mut Session, id: &str, p: serde_json::Value| s.execute(id, &p).unwrap_or_else(|e| panic!("{id}: {e}"));
|
|
run(&mut s, "sketch.create", json!({"plane": "XY"}));
|
|
let c = run(&mut s, "sketch.spline.fit_point", json!({"points": [[0, 0], [10, 5], [20, 0]]}));
|
|
let spline = c["curves"][0].as_str().unwrap_or_else(|| panic!("{c}")).to_string();
|
|
let schema = output_schema_for::<SplineReverseResult>();
|
|
let schema = schema.as_value();
|
|
let r = run(&mut s, "sketch.spline.reverse", json!({"curve": spline}));
|
|
assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");
|
|
assert!(r.get("param_warnings").is_none(), "{r}");
|
|
let r = run(&mut s, "sketch.spline.reverse", json!({"curve": spline, "unknown": 1}));
|
|
assert!(conforms(schema, schema, &r), "{r} doesn't match {schema}");
|
|
assert!(r["param_warnings"].as_array().is_some_and(|w| !w.is_empty()), "{r}");
|
|
}
|
|
|
|
#[test]
|
|
fn construction_line_contracts_and_replies_match() {
|
|
use super::{ConstructionLineParams, ConstructionLineResult};
|
|
assert_keys(
|
|
input_schema_for::<ConstructionLineParams>(),
|
|
&["alternate", "angle", "at", "construction", "curve", "curve2", "length", "mode", "near", "sketch", "solution", "through"],
|
|
);
|
|
let schema = output_schema_for::<ConstructionLineResult>();
|
|
let schema = schema.as_value();
|
|
let mut s = Session { param_check: ParamCheck::Strict, ..Session::default() };
|
|
s.execute("sketch.create", &json!({"plane":"XY"})).unwrap();
|
|
for (id, p) in [
|
|
("sketch.construction_line", json!({"at":[0,0],"through":[5,5]})),
|
|
("sketch.construction_line.horizontal", json!({"at":[0,10]})),
|
|
("sketch.construction_line.angle", json!({"at":[10,10],"angle":30})),
|
|
("sketch.construction_line.vertical", json!({"at":[20,0],"length":"12 mm","near":[20,-5]})),
|
|
] {
|
|
let r = s.execute(id, &p).unwrap();
|
|
assert!(conforms(schema, schema, &r), "{r}");
|
|
}
|
|
assert!(s.execute("sketch.construction_line", &json!({"at":[0,0],"mode":"unknown"})).is_err());
|
|
}
|