chore: Cleanup bounds related code
This commit is contained in:
parent
5311b80197
commit
866e143073
|
@ -146,10 +146,7 @@ pub fn hit_test<'gc>(
|
|||
false,
|
||||
)?;
|
||||
if let Some(other) = other {
|
||||
return Ok(other
|
||||
.world_bounds()
|
||||
.intersects(&movie_clip.world_bounds())
|
||||
.into());
|
||||
return Ok(movie_clip.hit_test_object(other).into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -187,8 +187,7 @@ fn pixel_bounds<'gc>(
|
|||
clip: MovieClip<'gc>,
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
// This is equivalent to `clip.getBounds()`.
|
||||
let to_global_matrix = clip.local_to_global_matrix();
|
||||
let bounds = clip.bounds_with_transform(&to_global_matrix);
|
||||
let bounds = clip.world_bounds();
|
||||
|
||||
// Return Rectangle object.
|
||||
let args = [
|
||||
|
|
|
@ -507,19 +507,12 @@ pub trait TDisplayObject<'gc>:
|
|||
matrix = *display_object.matrix() * matrix;
|
||||
node = display_object.parent();
|
||||
}
|
||||
|
||||
matrix
|
||||
}
|
||||
|
||||
/// Returns the matrix for transforming from global stage to this object's local space.
|
||||
fn global_to_local_matrix(&self) -> Matrix {
|
||||
let mut node = self.parent();
|
||||
let mut matrix = *self.matrix();
|
||||
while let Some(display_object) = node {
|
||||
matrix = *display_object.matrix() * matrix;
|
||||
node = display_object.parent();
|
||||
}
|
||||
|
||||
let mut matrix = self.local_to_global_matrix();
|
||||
matrix.invert();
|
||||
matrix
|
||||
}
|
||||
|
@ -1089,8 +1082,8 @@ pub trait TDisplayObject<'gc>:
|
|||
|
||||
/// Tests if a given object's world bounds intersects with the world bounds
|
||||
/// of this object.
|
||||
fn hit_test_object(&self, rhs: DisplayObject<'gc>) -> bool {
|
||||
self.world_bounds().intersects(&rhs.world_bounds())
|
||||
fn hit_test_object(&self, other: DisplayObject<'gc>) -> bool {
|
||||
self.world_bounds().intersects(&other.world_bounds())
|
||||
}
|
||||
|
||||
/// 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),
|
||||
) -> bool {
|
||||
// Default to using bounding box.
|
||||
self.world_bounds().contains(pos)
|
||||
self.hit_test_bounds(pos)
|
||||
}
|
||||
|
||||
fn mouse_pick(
|
||||
|
|
|
@ -63,17 +63,6 @@ impl<'gc> TDisplayObject<'gc> for Graphic<'gc> {
|
|||
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) {
|
||||
// Noop
|
||||
}
|
||||
|
|
|
@ -1827,10 +1827,6 @@ impl<'gc> TDisplayObject<'gc> for MovieClip<'gc> {
|
|||
self.0.read().drawing.self_bounds()
|
||||
}
|
||||
|
||||
fn hit_test_bounds(&self, point: (Twips, Twips)) -> bool {
|
||||
self.world_bounds().contains(point)
|
||||
}
|
||||
|
||||
fn hit_test_shape(
|
||||
&self,
|
||||
context: &mut UpdateContext<'_, 'gc, '_>,
|
||||
|
|
Loading…
Reference in New Issue