From 9f2a9c96d4eb9de965942ae29e0eb3736976ecaf Mon Sep 17 00:00:00 2001 From: James Ryans Date: Mon, 11 Nov 2024 10:04:40 +0700 Subject: [PATCH 1/2] pen should always snap on last anchor Signed-off-by: James Ryans --- editor/src/messages/tool/tool_messages/pen_tool.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/editor/src/messages/tool/tool_messages/pen_tool.rs b/editor/src/messages/tool/tool_messages/pen_tool.rs index 7dbbc9bdfb..94493a3cdd 100644 --- a/editor/src/messages/tool/tool_messages/pen_tool.rs +++ b/editor/src/messages/tool/tool_messages/pen_tool.rs @@ -359,8 +359,16 @@ impl PenToolData { } fn place_anchor(&mut self, snap_data: SnapData, transform: DAffine2, mouse: DVec2, responses: &mut VecDeque) -> Option { + let document = snap_data.document; let relative = self.latest_point().map(|point| point.pos); self.next_point = self.compute_snapped_angle(snap_data, transform, false, mouse, relative, true); + if let Some(last_pos) = relative { + let transform = document.metadata().document_to_viewport * transform; + let on_top = transform.transform_point2(self.next_point).distance_squared(transform.transform_point2(last_pos)) < crate::consts::SNAP_POINT_TOLERANCE.powi(2); + if on_top { + self.next_point = last_pos; + } + } if let Some(handle_end) = self.handle_end.as_mut() { *handle_end = self.next_point; self.next_handle_start = self.next_point; From 0a5b14f21b616fadeddcf989f8cc6679d5546c13 Mon Sep 17 00:00:00 2001 From: James Ryans Date: Tue, 12 Nov 2024 00:08:13 +0700 Subject: [PATCH 2/2] snap anchor on every single connected points Signed-off-by: James Ryans --- .../messages/tool/tool_messages/pen_tool.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/editor/src/messages/tool/tool_messages/pen_tool.rs b/editor/src/messages/tool/tool_messages/pen_tool.rs index 94493a3cdd..484b3c29f3 100644 --- a/editor/src/messages/tool/tool_messages/pen_tool.rs +++ b/editor/src/messages/tool/tool_messages/pen_tool.rs @@ -360,13 +360,21 @@ impl PenToolData { fn place_anchor(&mut self, snap_data: SnapData, transform: DAffine2, mouse: DVec2, responses: &mut VecDeque) -> Option { let document = snap_data.document; + let relative = self.latest_point().map(|point| point.pos); self.next_point = self.compute_snapped_angle(snap_data, transform, false, mouse, relative, true); - if let Some(last_pos) = relative { - let transform = document.metadata().document_to_viewport * transform; - let on_top = transform.transform_point2(self.next_point).distance_squared(transform.transform_point2(last_pos)) < crate::consts::SNAP_POINT_TOLERANCE.powi(2); - if on_top { - self.next_point = last_pos; + + let selected_nodes = document.network_interface.selected_nodes(&[]).unwrap(); + let mut selected_layers = selected_nodes.selected_layers(document.metadata()); + let layer = selected_layers.next().filter(|_| selected_layers.next().is_none())?; + let vector_data = document.network_interface.compute_modified_vector(layer)?; + let transform = document.metadata().document_to_viewport * transform; + for point in vector_data.single_connected_points() { + let Some(pos) = vector_data.point_domain.position_from_id(point) else { continue }; + let transformed_distance_between_squared = transform.transform_point2(pos).distance_squared(transform.transform_point2(self.next_point)); + let snap_point_tolerance_squared = crate::consts::SNAP_POINT_TOLERANCE.powi(2); + if transformed_distance_between_squared < snap_point_tolerance_squared { + self.next_point = pos; } } if let Some(handle_end) = self.handle_end.as_mut() {