diff --git a/editor/src/messages/tool/common_functionality/shape_editor.rs b/editor/src/messages/tool/common_functionality/shape_editor.rs index 25af562a..73d3ac9a 100644 --- a/editor/src/messages/tool/common_functionality/shape_editor.rs +++ b/editor/src/messages/tool/common_functionality/shape_editor.rs @@ -358,10 +358,17 @@ impl ShapeEditor { }; let (in_handle, out_handle) = if already_sharp { + let is_closed = manipulator_groups.last().filter(|group| group.is_close()).is_some(); + // Grab the next and previous manipulator groups by simply looking at the next / previous index - // TODO: Wrapping around on a closed path - let previous_position = index.checked_sub(1).and_then(|index| manipulator_groups.by_index(index)).and_then(|group| group.points[0].as_ref()); - let next_position = manipulator_groups.by_index(index + 1).and_then(|group| group.points[0].as_ref()); + let mut previous_position = index.checked_sub(1).and_then(|index| manipulator_groups.by_index(index)).and_then(|group| group.points[0].as_ref()); + let mut next_position = manipulator_groups.by_index(index + 1).and_then(|group| group.points[0].as_ref()); + + // Wrapping around closed path (assuming format is point elements then a single close path) + if is_closed { + previous_position = previous_position.or_else(|| manipulator_groups.iter().nth_back(1).and_then(|group| group.points[0].as_ref())); + next_position = next_position.or_else(|| manipulator_groups.first().and_then(|group| group.points[0].as_ref())); + } // To find the length of the new tangent we just take the distance to the anchor and divide by 3 (pretty arbitrary) let length_previous = previous_position.map(|point| (point.position - anchor_position).length() / 3.); diff --git a/graphene/src/layers/vector/subpath.rs b/graphene/src/layers/vector/subpath.rs index 163b3e3d..e733d4b1 100644 --- a/graphene/src/layers/vector/subpath.rs +++ b/graphene/src/layers/vector/subpath.rs @@ -616,10 +616,17 @@ impl> From for Subpath { /// Create a Subpath from a [BezPath]. fn from(path: T) -> Self { let mut subpath = Subpath::new(); + let mut closed = false; for path_el in path { + if closed { + warn!("Verbs appear after the close path in a subpath. This will probably cause crashes."); + } match path_el { PathEl::MoveTo(p) => { subpath.manipulator_groups_mut().push_end(ManipulatorGroup::new_with_anchor(kurbo_point_to_dvec2(p))); + if !subpath.0.is_empty() { + warn!("A move to path element appears part way through a subpath. This will be treated as a line to verb."); + } } PathEl::LineTo(p) => { subpath.manipulator_groups_mut().push_end(ManipulatorGroup::new_with_anchor(kurbo_point_to_dvec2(p))); @@ -635,6 +642,7 @@ impl> From for Subpath { } PathEl::ClosePath => { subpath.manipulator_groups_mut().push_end(ManipulatorGroup::closed()); + closed = true; } } }