#10726: knots carried on don't toggle; the target test keeps its selection; reversed and committed joins tested

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GbuSKAS2k5248LGFEapMUR
This commit is contained in:
Claude committed 2026-11-03 06:05:00 +00:00
1 parent 3bdfdea33a
commit eb6cf17f5a
2 files changed
+46 -2

No files matched your search

+40 -1
View File
@@ -308,6 +308,43 @@ fn a_smooth_endpoint_carried_on_stays_smooth() {
let (a, b) = ([anchor[0] - in_ctrl[0], anchor[1] - in_ctrl[1]], [out_ctrl[0] - anchor[0], out_ctrl[1] - anchor[1]]);
assert!(b[0].hypot(b[1]) > 1.0, "the outgoing handle bends into the new segment: {out_ctrl:?}");
assert!((a[0] * b[1] - a[1] * b[0]).abs() < 1e-6 && a[0] * b[0] + a[1] * b[1] > 0.0, "in line: {knots:?}");
// CodeRabbit on #10744: committed, the join is stored as a smooth knot.
crate::vector_ui::pen_commit(&mut app, false);
let work = work_path(&app);
assert_eq!(work.subpaths.len(), 1, "the same subpath, extended");
assert!(work.subpaths[0].knots[1].smooth, "{:?}", work.subpaths[0].knots[1]);
}
/// CodeRabbit on #10744: a curved path carried on from its first endpoint runs backwards, each
/// knot's handles swapped, and that endpoint keeps the handle it had towards the path.
#[test]
fn a_curved_path_carries_on_from_its_first_endpoint_with_its_handles_swapped() {
use photocraft_doc::vector::{Knot, Subpath};
use photocraft_geom::Point;
let mut app = app(Tool::CurvaturePen);
let start = Knot::smooth(Point::new(20.0, 20.0), Point::new(10.0, 30.0), Point::new(30.0, 10.0));
set_work_path(&mut app, vec![Subpath { closed: false, knots: vec![start, Knot::corner(80.0, 80.0)], op: Default::default() }]);
select_anchor(&mut app, crate::direct_select::PathRef::Work, [0, 0]);
click(&mut app, 0.0, 100.0);
let pen = app.ui.pen.as_ref().expect("the path is carried on");
assert_eq!(pen.resumes.as_ref().map(|r| r.index), Some(0));
let anchors: Vec<[f64; 2]> = pen.knots.iter().map(|k| k[0]).collect();
assert_eq!(anchors, [[80.0, 80.0], [20.0, 20.0], [0.0, 100.0]], "backwards, then the new anchor");
assert_eq!(pen.knots[1][1], [30.0, 10.0], "the endpoint's handle towards the path: its old outgoing one");
}
/// CodeRabbit on #10744: a double-click on a knot of the path carried on (not the endpoint it
/// carries on from) changes nothing: those knots keep their handles.
#[test]
fn toggling_a_carried_knot_changes_nothing() {
use photocraft_doc::vector::Subpath;
let mut app = app(Tool::CurvaturePen);
set_work_path(&mut app, vec![Subpath::polyline(&[(20.0, 20.0), (80.0, 20.0), (80.0, 80.0)])]);
select_anchor(&mut app, crate::direct_select::PathRef::Work, [0, 2]);
click(&mut app, 140.0, 120.0);
let before = app.ui.pen.as_ref().map(|p| p.unlinked.clone());
crate::vector_ui::curvature_toggle(&mut app, 80.0, 20.0);
assert_eq!(app.ui.pen.as_ref().map(|p| p.unlinked.clone()), before, "the old corner stays as it was");
}
/// CodeRabbit on #10744: in Path mode the Pen carries on the work path, so an endpoint selected
@@ -326,8 +363,10 @@ fn an_endpoint_on_another_path_than_the_pen_draws_on_starts_a_new_one() {
// The Paths panel on no path: the Pen draws on the work path, not the layer's.
app.ui.selected_path = None;
set_work_path(&mut app, vec![Subpath::polyline(&[(200.0, 20.0), (80.0, 80.0)])]);
select_anchor(&mut app, crate::direct_select::PathRef::Layer(shape), [0, 1]);
// The tool first: switching tools drops a Direct Selection selection.
app.ui.tool = Tool::CurvaturePen;
select_anchor(&mut app, crate::direct_select::PathRef::Layer(shape), [0, 1]);
assert!(crate::direct_select::selected_open_end(&app).is_some(), "the shape's endpoint is selected");
click(&mut app, 140.0, 150.0);
let pen = app.ui.pen.as_ref().expect("a new path");
assert!(pen.resumes.is_none() && pen.knots.len() == 1, "{pen:?}");
@@ -15,7 +15,7 @@ pub(super) fn curvature_refresh(pen: &mut PenPath, closed: bool) {
for (i, was) in pen.fixed.iter().enumerate() {
let Some(k) = pen.knots.get_mut(i) else { break };
let (keep_in, keep_out) = (!(closed && i == 0), !(extended && i == last));
let smooth = !pen.unlinked.contains(&i);
let smooth = !corners.get(i).copied().unwrap_or(false);
k[0] = was[0];
if keep_in {
k[1] = was[1];
@@ -135,6 +135,11 @@ pub fn curvature_toggle(app: &mut PhotocraftApp, x: f64, y: f64) {
cancel_stale_pen(app);
let Some(i) = curvature_hit(app, x, y) else { return };
let Some(pen) = app.ui.pen.as_mut() else { return };
// The knots of a path carried on keep their handles (`curvature_refresh`), but for the
// endpoint drawing carries on from: toggling one of the others would change nothing.
if i + 1 < pen.fixed.len() {
return;
}
if let Some(at) = pen.unlinked.iter().position(|&c| c == i) {
pen.unlinked.remove(at);
} else {