* Sketch: Remove Spline Point takes one fit point out of a spline (#10783) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Sketch: Remove Spline Point takes one point out of a spline (#10783) sketch.spline.remove_point takes one fit or control point out of a spline. The spline keeps its id and runs through its other points, which stay where they are. The point goes with the constraints on it, unless another curve uses it. A closed spline's closing point, an end joined to other geometry, the last 2 points (3 when closed), and projected, offset or patterned splines are refused with a message. The right-click menu of a spline point, picked alone, offers it beside Reverse Spline Direction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
84 lines
4.4 KiB
Rust
84 lines
4.4 KiB
Rust
use serde_json::json;
|
|
|
|
use super::{SplineRemovePointParams, SplineRemovePointResult, 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"]);
|
|
assert_keys(input_schema_for::<SplineRemovePointParams>(), &["curve", "point", "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"})),
|
|
("sketch.spline.remove_point", json!({"curve": 5, "point": "p1"})),
|
|
("sketch.spline.remove_point", json!({"curve": "nope", "point": "p1"})),
|
|
("sketch.spline.remove_point", json!({"curve": "l1", "point": 3})),
|
|
("sketch.spline.remove_point", json!({"curve": "l1"})),
|
|
]);
|
|
}
|
|
|
|
#[test]
|
|
fn spline_remove_point_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": [[5, 0], [10, 5], [20, 0], [30, 5], [40, 0]]}));
|
|
let spline = c["curves"][0].as_str().unwrap_or_else(|| panic!("{c}")).to_string();
|
|
let schema = output_schema_for::<SplineRemovePointResult>();
|
|
let schema = schema.as_value();
|
|
let r = run(&mut s, "sketch.spline.remove_point", json!({"curve": spline, "point": format!("{spline}.start")}));
|
|
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.remove_point", json!({"curve": spline, "point": format!("{spline}.end"), "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 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());
|
|
}
|