Skip to content

Commit f3b1179

Browse files
committed
fix the arrow tool to show arrow in viewport space
Signed-off-by: krVatsal <[email protected]>
1 parent 989f4ba commit f3b1179

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

editor/src/messages/tool/common_functionality/graph_modification_utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ pub fn get_arc_id(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInt
363363
NodeGraphLayer::new(layer, network_interface).upstream_node_id_from_name("Arc")
364364
}
365365

366+
pub fn get_arrow_id(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<NodeId> {
367+
NodeGraphLayer::new(layer, network_interface).upstream_node_id_from_name("Arrow")
368+
}
369+
366370
pub fn get_spiral_id(layer: LayerNodeIdentifier, network_interface: &NodeNetworkInterface) -> Option<NodeId> {
367371
NodeGraphLayer::new(layer, network_interface).upstream_node_id_from_name("Spiral")
368372
}

editor/src/messages/tool/common_functionality/shapes/arrow_shape.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ impl Arrow {
5656
start_viewport + direction * head_length + perpendicular * (head_width * 0.5),
5757
];
5858

59+
// Get the layer's transform to convert viewport coordinates to layer-local coordinates
60+
let viewport_to_layer = document.metadata().transform_to_viewport(layer).inverse();
61+
62+
// Convert viewport coordinates to layer-local coordinates
63+
let local_anchors: Vec<DVec2> = viewport_anchors.iter().map(|&viewport_pos| viewport_to_layer.transform_point2(viewport_pos)).collect();
64+
5965
let vector = document.network_interface.compute_modified_vector(layer);
6066
let existing_point_ids: Vec<PointId> = vector.as_ref().map(|v| v.point_domain.ids().to_vec()).unwrap_or_default();
6167
let existing_segment_ids: Vec<SegmentId> = vector.as_ref().map(|v| v.segment_domain.ids().to_vec()).unwrap_or_default();
@@ -74,7 +80,8 @@ impl Arrow {
7480
});
7581
}
7682

77-
let point_ids: Vec<PointId> = viewport_anchors
83+
// Insert points in layer-local coordinates
84+
let point_ids: Vec<PointId> = local_anchors
7885
.iter()
7986
.map(|&pos| {
8087
let id = PointId::generate();

0 commit comments

Comments
 (0)