Fix crashes related to 0-scale shapes (#777)

* Fix crashes when dragging the bounding box/transform cage of a 0-scale shape.

* Fix crashes when dragging the pivot point of a 0-scale shape

* Fix rotation computation on DAffine2 when scale.x is 0, avoids Nan display

* remove remaining log::info that I introduced in earlier commit

* Fix crash when updating the scale of a transform that was already 0.

* Fix NumberInput behaviour when the requested value changed is does not happen.

* Fix rotation computation when Scale X and Scale Y are both 0. Display 0. This also fixes crashes when modifying the rotation in such case
This commit is contained in:
Boutillier
2022-09-12 01:46:11 -07:00
committed by GitHub
parent 74737bc13d
commit 74624bb531
4 changed files with 41 additions and 11 deletions
@@ -158,9 +158,12 @@ impl Pivot {
for layer_path in document.selected_visible_layers() {
if let Ok(layer) = document.graphene_document.layer(layer_path) {
let transform = Self::get_layer_pivot_transform(layer_path, layer, document, font_cache);
let pivot = transform.inverse().transform_point2(position).into();
let layer_path = layer_path.to_owned();
responses.push_back(Operation::SetPivot { layer_path, pivot }.into());
let pivot = transform.inverse().transform_point2(position);
// Only update the pivot when computed position is finite. Infinite can happen when scale is 0.
if pivot.is_finite() {
let layer_path = layer_path.to_owned();
responses.push_back(Operation::SetPivot { layer_path, pivot: pivot.into() }.into());
}
}
}
}
@@ -130,7 +130,13 @@ impl SelectedEdges {
/// Calculates the required scaling to resize the bounding box
pub fn bounds_to_scale_transform(&self, position: DVec2, size: DVec2) -> (DAffine2, DVec2) {
let enlargement_factor = size / (self.bounds[1] - self.bounds[0]);
let mut enlargement_factor = size / (self.bounds[1] - self.bounds[0]);
if enlargement_factor.x.is_nan() {
enlargement_factor.x = 0.;
}
if enlargement_factor.y.is_nan() {
enlargement_factor.y = 0.;
}
let mut pivot = (self.bounds[0] * enlargement_factor - position) / (enlargement_factor - DVec2::splat(1.));
if pivot.x.is_nan() {
pivot.x = 0.;