Sketch: Remove Spline Point takes one point out of a spline (#10783) (#10793)

* 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>
This commit is contained in:
austin62jake
2026-11-02 00:08:11 +00:00
committed by GitHub
parent afe06a1a3d
commit 3fe2b3386f
9 changed files with 391 additions and 6 deletions
+24 -1
View File
@@ -16,7 +16,7 @@ use super::sketch::{add_c, circumcircle, edit, ids_of, mark_construction, req_pa
use super::sketch_store;
use super::{CommandSpec, in_sketch};
use crate::params::{bad, num, req_vec2, str_, string_list};
use crate::schema::sketch_create::{SplineReverseParams, SplineReverseResult};
use crate::schema::sketch_create::{SplineRemovePointParams, SplineRemovePointResult, SplineReverseParams, SplineReverseResult};
use crate::schema::{TypedContract, output_schema_for};
use crate::{EngineError, Result, Session};
@@ -29,6 +29,7 @@ mod text_move_tests;
mod text_expr_tests;
const SPLINE_REVERSE_CONTRACT: TypedContract<SplineReverseParams> = TypedContract::new();
const SPLINE_REMOVE_POINT_CONTRACT: TypedContract<SplineRemovePointParams> = TypedContract::new();
pub static COMMANDS: &[CommandSpec] = &[
CommandSpec::new("sketch.line.midpoint", "Midpoint Line", midpoint_line)
@@ -88,6 +89,12 @@ pub static COMMANDS: &[CommandSpec] = &[
.icon("spline")
.enabled(in_sketch)
.params("curve: fit point spline id, at: [x,y]: a fit point is inserted where the curve passes nearest to it, between its neighbours (the curve still runs through it and all its old points; constraints on them stay); end?: start|end: `at` becomes the spline's new first or last point instead, and the curve runs on to it (refused when that end is joined to other geometry). Control point splines take no new points yet. Returns point: the new point's id"),
CommandSpec::new("sketch.spline.remove_point", "Remove Spline Point", crate::checked!("sketch.spline.remove_point", spline_remove_point))
.icon("spline")
.enabled(in_sketch)
.contract(&SPLINE_REMOVE_POINT_CONTRACT)
.output(output_schema_for::<SplineRemovePointResult>)
.params("curve: spline id, point: one of its points (a point id, or the curve's start or end such as s1.end): the spline runs through (or over) its other points only, and the point goes with the constraints on it unless another curve uses it. Fit point, control point and closed splines. Refused for a closed spline's closing point, for an end joined to other geometry or held by a constraint, when fewer than 2 points would be left (3 on a closed spline), and for a projected, offset or patterned spline. Returns curve, point: the point's id, deleted: whether the point went too"),
CommandSpec::new("sketch.spline.reverse", "Reverse Spline Direction", crate::checked!("sketch.spline.reverse", spline_reverse))
.icon("spline")
.enabled(in_sketch)
@@ -711,6 +718,22 @@ fn spline_insert_point(s: &mut Session, p: &Value) -> Result<Value> {
Ok(json!({"point": point, "curve": p.get("curve"), "sketch": info}))
}
/// One point taken out of a spline (#10783).
fn spline_remove_point(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "sketch.spline.remove_point";
let id = str_(p, "curve").ok_or_else(|| bad(cmd, "`curve` must be a spline id"))?.to_string();
let point = str_(p, "point").ok_or_else(|| bad(cmd, "`point` must be one of the spline's points"))?.to_string();
let ((point, deleted), info) = edit(s, p, cmd, false, |sk, _| {
let c = sk.curve_index(&id).ok_or_else(|| bad(cmd, format!("unknown curve `{id}`")))?;
let at = sk.resolve_point(&point).ok_or_else(|| bad(cmd, format!("unknown sketch point `{point}`")))?;
let name = sk.points.get(at).map_or(point.clone(), |q| q.id.clone());
let deleted = sk.remove_spline_point(c, at).map_err(|e| bad(cmd, e.to_string()))?;
Ok((name, deleted))
})?;
let reply = SplineRemovePointResult { curve: id, point, deleted, sketch: info, param_warnings: Vec::new() };
serde_json::to_value(reply).map_err(|e| EngineError::Other(e.to_string()))
}
fn spline_reverse(s: &mut Session, p: &Value) -> Result<Value> {
let cmd = "sketch.spline.reverse";
let id = str_(p, "curve").ok_or_else(|| bad(cmd, "`curve` must be a spline id"))?.to_string();
@@ -1492,6 +1492,64 @@ fn a_point_added_to_a_spline_keeps_its_constraints_and_undoes() {
assert_eq!(sketch(&s), unchanged, "refusals change nothing");
}
/// Remove Spline Point (#10783): one fit point goes, with the dimension on it. The spline runs
/// through its other points, which stay where they were, and the line joined to its end stays.
/// Undo puts the point back. The end the line joins, a line and an unknown point are refused; a
/// control point spline gives up a point too.
#[test]
fn a_point_removed_from_a_spline_goes_with_its_dimension_and_undoes() {
let mut s = new_sketch();
let sid =
ids(&run(&mut s, "sketch.spline.fit_point", json!({"points": [[0, 0], [10, 8], [20, 0], [30, 6]], "connect": false}))["curves"])[0].clone();
run(&mut s, "sketch.line", json!({"points": [format!("{sid}.end"), [40, 6]], "connect": false}));
let sk = sketch(&s);
let si = sk.curve_index(&sid).unwrap();
let names: Vec<String> = sk.curves[si].kind.point_ids().iter().map(|i| sk.points[*i].id.clone()).collect();
run(&mut s, "sketch.dimension", json!({"entities": [names[1], names[2]], "value": 12.8}));
let before = sketch(&s);
let at = |sk: &solidcraft_sketch::Sketch, id: &str| sk.point(sk.point_index(id).unwrap()).unwrap();
let r = run(&mut s, "sketch.spline.remove_point", json!({"curve": sid, "point": names[1]}));
assert_eq!((r["curve"].as_str(), r["point"].as_str(), r["deleted"].as_bool()), (Some(sid.as_str()), Some(names[1].as_str()), Some(true)), "{r}");
let after = sketch(&s);
assert!(after.point_index(&names[1]).is_none(), "the point went");
let left: Vec<String> = after.curves[si].kind.point_ids().iter().map(|i| after.points[*i].id.clone()).collect();
assert_eq!(left, [names[0].clone(), names[2].clone(), names[3].clone()]);
let segs = after.exact_segs(si).unwrap();
for id in &left {
let q = at(&after, id);
assert!(q.dist(at(&before, id)) < 1e-9, "{id} stays where it was");
let off = segs.iter().map(|seg| seg.point_at(seg.closest_param(q)).dist(q)).fold(f64::INFINITY, f64::min);
assert!(off < 1e-9, "the curve runs through {id}");
}
assert!(after.constraints.iter().all(|c| c.kind.value().is_none()), "the dimension on the point went");
let joined = after.curves.iter().any(|c| matches!(c.kind, CurveKind::Line { a, .. } if after.points[a].id == names[3]));
assert!(joined, "the line still starts at the spline's end");
run(&mut s, "edit.undo", json!({}));
assert_eq!(sketch(&s), before, "undo puts the point back");
let line = before.curves.iter().find(|c| matches!(c.kind, CurveKind::Line { .. })).unwrap().id.clone();
for (p, why) in [
(json!({"curve": sid, "point": format!("{sid}.end")}), "joined"),
(json!({"curve": line, "point": names[0]}), "spline"),
(json!({"curve": sid, "point": "nope"}), "unknown sketch point"),
(json!({"curve": sid}), "`point`"),
] {
let e = s.execute("sketch.spline.remove_point", &p).unwrap_err().to_string();
assert!(e.contains(why), "{p}: {e}");
}
assert_eq!(sketch(&s), before, "refusals change nothing");
let cv =
ids(&run(&mut s, "sketch.spline.control_point", json!({"points": [[0, 20], [10, 30], [20, 20]], "connect": false}))["curves"])[0].clone();
let r = run(&mut s, "sketch.spline.remove_point", json!({"curve": cv, "point": format!("{cv}.start")}));
assert_eq!(r["deleted"], json!(true), "{r}");
let sk = sketch(&s);
let ci = sk.curve_index(&cv).unwrap();
let left: Vec<Vec2> = sk.curves[ci].kind.point_ids().iter().map(|i| sk.point(*i).unwrap()).collect();
assert_eq!(left, [Vec2::new(10.0, 30.0), Vec2::new(20.0, 20.0)]);
}
/// Reverse Spline Direction (#8224): a fit, a control point and a closed spline each run the
/// other way along the same path, their ends swapped. Their points, the constraints on them and
/// a line joined to an end stay, and undo restores the spline. A line and the source and output