#657: a drop that would leave no segment only moves the point

Dropping one end of a 2-point line on the other left a 1-point vector.
This commit is contained in:
bflatastic
2026-10-17 15:06:37 +07:00
parent 22a821c742
commit 58de7d4dab
2 changed files with 15 additions and 1 deletions
+7 -1
View File
@@ -1082,10 +1082,16 @@ impl Session {
else {
return Ok(());
};
let mut merged = net.clone();
ops::merge_vertices(&mut merged, keep, v);
// A merge that would leave no segment (a 2-point line's ends dropped together) only moves.
if merged.segments.is_empty() {
return Ok(());
}
// The preview starts again from the document before the drag: bring the moved layer.
self.preview(|doc, _| {
*doc.get_mut(id)? = moved;
edit(doc, id, |net| ops::merge_vertices(net, keep, v))
edit(doc, id, |net| *net = merged)
})?;
set_state(self, |e| {
e.vertices = vec![if keep > v { keep - 1 } else { keep }];
+8
View File
@@ -300,6 +300,14 @@ fn a_point_dropped_on_another_merges_into_it() {
ex(&mut s, "vector.edit.select", json!({"vertices": []}));
drag(&mut s, (0.0, 100.0), (0.0, 50.0));
assert_eq!(net(&s, id).vertices.len(), 4);
// A 2-point line's end dropped on its other end only moves: no segment would be left.
let mut s = Session::new();
let r = ex(&mut s, "vector.create", json!({"points": [[0, 0], [100, 0]]}));
let id = crate::params::id_of(&r["id"]).unwrap();
ex(&mut s, "vector.edit.begin", json!({"id": id}));
drag(&mut s, (100.0, 0.0), (2.0, 0.0));
let n = net(&s, id);
assert_eq!((n.vertices.len(), n.segments.len()), (2, 1), "still a line: {n:?}");
}
#[test]