From af6dae29fc50103a3e85e65a44f03cb3f3c9f3c1 Mon Sep 17 00:00:00 2001 From: 0HyperCube <78500760+0HyperCube@users.noreply.github.com> Date: Mon, 20 May 2024 22:44:24 +0100 Subject: [PATCH] Fix off by one subpath and unrelated crash (#1754) * Fix off by one in subpath code * Fix crash with selected handles and anchor * Sort the correct way I have no idea why the origional code was so overly verbose but it has caused significant confusion and wasted effort --- .../messages/tool/common_functionality/shape_editor.rs | 8 ++++---- node-graph/gcore/src/vector/vector_data/attributes.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index 2bccd226..b5ec042f 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -982,10 +982,10 @@ impl ShapeState { continue; } - selected_points.sort_by(|&a, &b| match a > b { - true => std::cmp::Ordering::Greater, - false => std::cmp::Ordering::Less, - }); + selected_points.sort(); + + // Required to remove duplicates when the handles and anchors are selected + selected_points.dedup(); let mut last_manipulator_index = 0; let mut to_extend_with_last_group: Option>> = None; diff --git a/node-graph/gcore/src/vector/vector_data/attributes.rs b/node-graph/gcore/src/vector/vector_data/attributes.rs index a90fd62d..ed3641d4 100644 --- a/node-graph/gcore/src/vector/vector_data/attributes.rs +++ b/node-graph/gcore/src/vector/vector_data/attributes.rs @@ -324,9 +324,9 @@ impl<'a> Iterator for StrokePathIter<'a> { .take_while(|&(_, start, end)| { let continuous = old_end.is_none() || old_end.is_some_and(|old_end| old_end == start); old_end = Some(end); - count += 1; continuous - }); + }) + .inspect(|_| count += 1); let subpath = self.vector_data.subpath_from_segments(segments_iter); self.segment_index += count;