core: Avoid panic when display objects are manipulated in clearly invalid ways.
This commit is contained in:
parent
990401a09c
commit
3225cd40e2
|
@ -528,7 +528,7 @@ pub trait TDisplayObject<'gc>:
|
|||
/// Returned by the ActionScript `_width`/`width` properties.
|
||||
fn width(&self) -> f64 {
|
||||
let bounds = self.local_bounds();
|
||||
(bounds.x_max - bounds.x_min).to_pixels()
|
||||
(bounds.x_max.saturating_sub(bounds.x_min)).to_pixels()
|
||||
}
|
||||
|
||||
/// Sets the pixel width of this display object in local space.
|
||||
|
@ -567,7 +567,7 @@ pub trait TDisplayObject<'gc>:
|
|||
/// Returned by the ActionScript `_height`/`height` properties.
|
||||
fn height(&self) -> f64 {
|
||||
let bounds = self.local_bounds();
|
||||
(bounds.y_max - bounds.y_min).to_pixels()
|
||||
(bounds.y_max.saturating_sub(bounds.y_min)).to_pixels()
|
||||
}
|
||||
/// Sets the pixel height of this display object in local space.
|
||||
/// Set by the ActionScript `_height`/`height` properties.
|
||||
|
|
|
@ -95,6 +95,10 @@ impl Twips {
|
|||
pub fn to_pixels(self) -> f64 {
|
||||
f64::from(self.0) / Self::TWIPS_PER_PIXEL
|
||||
}
|
||||
|
||||
pub fn saturating_sub(self, rhs: Self) -> Self {
|
||||
Self(self.0.saturating_sub(rhs.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add for Twips {
|
||||
|
|
Loading…
Reference in New Issue