Skip to content

Commit cabc027

Browse files
authored
Fix Select tool resizing with Shift held allowing the constrained aspect ratio to change when snapping (#2441)
Fix bug in constrained snap
1 parent bd97c15 commit cabc027

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,22 @@ impl SelectedEdges {
206206
}
207207
let snapped_bounds = bounds_to_doc.inverse().transform_point2(snapped.snapped_point_document);
208208

209-
let mut scale_factor = (snapped_bounds - pivot) / (updated - pivot);
209+
let new_from_pivot = snapped_bounds - pivot; // The new vector from the snapped point to the pivot
210+
let original_from_pivot = updated - pivot; // The original vector from the point to the pivot
211+
let mut scale_factor = new_from_pivot / original_from_pivot;
212+
213+
// Constrain should always scale by the same factor in x and y
214+
if constrain {
215+
// When the point is on the pivot, we simply copy the other axis.
216+
if original_from_pivot.x.abs() < 1e-5 {
217+
scale_factor.x = scale_factor.y;
218+
} else if original_from_pivot.y.abs() < 1e-5 {
219+
scale_factor.y = scale_factor.x;
220+
}
221+
222+
debug_assert!((scale_factor.x - scale_factor.y).abs() < 1e-5);
223+
}
224+
210225
if !(self.left || self.right || constrain) {
211226
scale_factor.x = 1.
212227
}

0 commit comments

Comments
 (0)