Skip to content

Commit d0031ba

Browse files
0HyperCubeKeavon
authored andcommitted
Improve transforms
1 parent a677964 commit d0031ba

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

editor/src/messages/tool/tool_messages/path_tool.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,17 @@ impl PathToolData {
478478
return None; // Do not allow selections of multiple points to count.
479479
}
480480
let selected_handle = selection.selected().next()?.as_handle()?; // Only count selected handles
481+
let layer_to_document = document.metadata().transform_to_document(*layer);
481482
let vector_data = document.network_interface.compute_modified_vector(*layer)?;
482-
let handle_position = selected_handle.to_manipulator_point().get_position(&vector_data)?;
483+
484+
let handle_position_local = selected_handle.to_manipulator_point().get_position(&vector_data)?;
483485
let anchor_id = selected_handle.to_manipulator_point().get_anchor(&vector_data)?;
484-
let anchor_position = vector_data.point_domain.position_from_id(anchor_id)?;
486+
let anchor_position_local = vector_data.point_domain.position_from_id(anchor_id)?;
487+
488+
let handle_position_document = layer_to_document.transform_point2(handle_position_local);
489+
let anchor_position_document = layer_to_document.transform_point2(anchor_position_local);
485490

486-
Some((handle_position, anchor_position))
491+
Some((handle_position_document, anchor_position_document))
487492
}
488493

489494
fn calculate_handle_angle(&mut self, handle_vector: DVec2, lock_angle: bool, snap_angle: bool) -> f64 {
@@ -516,7 +521,7 @@ impl PathToolData {
516521
) -> DVec2 {
517522
let snap_point = SnapCandidatePoint::handle_neighbors(new_handle_position, [anchor_position]);
518523

519-
if using_angle_constraints {
524+
document.metadata().document_to_viewport.transform_vector2(if using_angle_constraints {
520525
let direction = handle_direction.normalize_or_zero();
521526
let snap_constraint = SnapConstraint::Line { origin: anchor_position, direction };
522527
let snap_result = self
@@ -529,7 +534,7 @@ impl PathToolData {
529534
let snap_result = self.snap_manager.free_snap(&SnapData::new(document, input), &snap_point, SnapTypeConfiguration::default());
530535
self.snap_manager.update_indicator(snap_result.clone());
531536
snap_result.snapped_point_document - handle_position
532-
}
537+
})
533538
}
534539

535540
fn drag(
@@ -557,7 +562,7 @@ impl PathToolData {
557562
let constrained_target = anchor_pos + constrained_direction * projected_length;
558563
let constrained_delta = constrained_target - handle_pos;
559564

560-
self.apply_snapping(constrained_direction, handle_pos + constrained_delta, anchor_pos, true, handle_pos, document, input)
565+
self.apply_snapping(constrained_direction, handle_pos + constrained_delta, anchor_pos, lock_angle || snap_angle, handle_pos, document, input)
561566
} else {
562567
shape_editor.snap(&mut self.snap_manager, &self.snap_cache, document, input, previous_mouse)
563568
};

0 commit comments

Comments
 (0)