chore: Cleanup bounds related code

This commit is contained in:
relrelb 2021-03-06 23:41:56 +02:00 committed by Mike Welsh
parent 5311b80197
commit 866e143073
5 changed files with 6 additions and 32 deletions

View File

@ -146,10 +146,7 @@ pub fn hit_test<'gc>(
false, false,
)?; )?;
if let Some(other) = other { if let Some(other) = other {
return Ok(other return Ok(movie_clip.hit_test_object(other).into());
.world_bounds()
.intersects(&movie_clip.world_bounds())
.into());
} }
} }

View File

@ -187,8 +187,7 @@ fn pixel_bounds<'gc>(
clip: MovieClip<'gc>, clip: MovieClip<'gc>,
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
// This is equivalent to `clip.getBounds()`. // This is equivalent to `clip.getBounds()`.
let to_global_matrix = clip.local_to_global_matrix(); let bounds = clip.world_bounds();
let bounds = clip.bounds_with_transform(&to_global_matrix);
// Return Rectangle object. // Return Rectangle object.
let args = [ let args = [

View File

@ -507,19 +507,12 @@ pub trait TDisplayObject<'gc>:
matrix = *display_object.matrix() * matrix; matrix = *display_object.matrix() * matrix;
node = display_object.parent(); node = display_object.parent();
} }
matrix matrix
} }
/// Returns the matrix for transforming from global stage to this object's local space. /// Returns the matrix for transforming from global stage to this object's local space.
fn global_to_local_matrix(&self) -> Matrix { fn global_to_local_matrix(&self) -> Matrix {
let mut node = self.parent(); let mut matrix = self.local_to_global_matrix();
let mut matrix = *self.matrix();
while let Some(display_object) = node {
matrix = *display_object.matrix() * matrix;
node = display_object.parent();
}
matrix.invert(); matrix.invert();
matrix matrix
} }
@ -1089,8 +1082,8 @@ pub trait TDisplayObject<'gc>:
/// Tests if a given object's world bounds intersects with the world bounds /// Tests if a given object's world bounds intersects with the world bounds
/// of this object. /// of this object.
fn hit_test_object(&self, rhs: DisplayObject<'gc>) -> bool { fn hit_test_object(&self, other: DisplayObject<'gc>) -> bool {
self.world_bounds().intersects(&rhs.world_bounds()) self.world_bounds().intersects(&other.world_bounds())
} }
/// Tests if a given stage position point intersects within this object, considering the art. /// Tests if a given stage position point intersects within this object, considering the art.
@ -1100,7 +1093,7 @@ pub trait TDisplayObject<'gc>:
pos: (Twips, Twips), pos: (Twips, Twips),
) -> bool { ) -> bool {
// Default to using bounding box. // Default to using bounding box.
self.world_bounds().contains(pos) self.hit_test_bounds(pos)
} }
fn mouse_pick( fn mouse_pick(

View File

@ -63,17 +63,6 @@ impl<'gc> TDisplayObject<'gc> for Graphic<'gc> {
self.0.read().static_data.bounds.clone() self.0.read().static_data.bounds.clone()
} }
fn world_bounds(&self) -> BoundingBox {
// TODO: Use dirty flags and cache this.
let mut bounds = self.local_bounds();
let mut node = self.parent();
while let Some(display_object) = node {
bounds = bounds.transform(&*display_object.matrix());
node = display_object.parent();
}
bounds
}
fn run_frame(&self, _context: &mut UpdateContext) { fn run_frame(&self, _context: &mut UpdateContext) {
// Noop // Noop
} }

View File

@ -1827,10 +1827,6 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
self.0.read().drawing.self_bounds() self.0.read().drawing.self_bounds()
} }
fn hit_test_bounds(&self, point: (Twips, Twips)) -> bool {
self.world_bounds().contains(point)
}
fn hit_test_shape( fn hit_test_shape(
&self, &self,
context: &mut UpdateContext<'_, 'gc, '_>, context: &mut UpdateContext<'_, 'gc, '_>,