mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 17:58:11 +08:00
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:
committed by
Keavon Chambers
parent
788552e10c
commit
54b63c3eb5
@@ -964,7 +964,12 @@ impl DAffine2Utils for DAffine2 {
|
||||
}
|
||||
|
||||
fn update_scale_x(self, new_width: f64) -> Self {
|
||||
self * DAffine2::from_scale((new_width / self.scale_x(), 1.).into())
|
||||
let scale_x = self.scale_x();
|
||||
if scale_x != 0. {
|
||||
self * DAffine2::from_scale((new_width / scale_x, 1.).into())
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn scale_y(&self) -> f64 {
|
||||
@@ -972,7 +977,12 @@ impl DAffine2Utils for DAffine2 {
|
||||
}
|
||||
|
||||
fn update_scale_y(self, new_height: f64) -> Self {
|
||||
self * DAffine2::from_scale((1., new_height / self.scale_y()).into())
|
||||
let scale_y = self.scale_y();
|
||||
if scale_y != 0. {
|
||||
self * DAffine2::from_scale((1., new_height / scale_y).into())
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn x(&self) -> f64 {
|
||||
@@ -994,9 +1004,19 @@ impl DAffine2Utils for DAffine2 {
|
||||
}
|
||||
|
||||
fn rotation(&self) -> f64 {
|
||||
let cos = self.matrix2.col(0).x / self.scale_x();
|
||||
let sin = self.matrix2.col(0).y / self.scale_x();
|
||||
sin.atan2(cos)
|
||||
if self.scale_x() != 0. {
|
||||
let cos = self.matrix2.col(0).x / self.scale_x();
|
||||
let sin = self.matrix2.col(0).y / self.scale_x();
|
||||
sin.atan2(cos)
|
||||
} else if self.scale_y() != 0. {
|
||||
let sin = -self.matrix2.col(1).x / self.scale_y();
|
||||
let cos = self.matrix2.col(1).y / self.scale_y();
|
||||
sin.atan2(cos)
|
||||
} else {
|
||||
// Rotation information does not exists anymore in the matrix
|
||||
// return 0 for user experience.
|
||||
0.
|
||||
}
|
||||
}
|
||||
|
||||
fn update_rotation(self, new_rotation: f64) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user