style: Return an infinite perspective in TransformOperation::Perspective::to_animated_zero

Differential Revision: https://phabricator.services.mozilla.com/D122919
This commit is contained in:
Matt Woodrow 2023-05-22 14:37:04 +02:00 committed by Oriol Brufau
parent 26c5db6a6e
commit 79893116e7
3 changed files with 11 additions and 7 deletions

View file

@ -1112,8 +1112,12 @@ impl Animate for ComputedTransformOperation {
let decomposed = decompose_3d_matrix(interpolated)?; let decomposed = decompose_3d_matrix(interpolated)?;
let perspective_z = decomposed.perspective.2; let perspective_z = decomposed.perspective.2;
let used_value = if perspective_z == 0. { // Clamp results outside of the -1 to 0 range so that we get perspective
0. // function values between 1 and infinity.
let used_value = if perspective_z >= 0. {
std::f32::INFINITY
} else if perspective_z <= -1. {
1.
} else { } else {
-1. / perspective_z -1. / perspective_z
}; };

View file

@ -516,8 +516,8 @@ impl ToAnimatedZero for TransformOperation {
generic::TransformOperation::Rotate(_) => { generic::TransformOperation::Rotate(_) => {
Ok(generic::TransformOperation::Rotate(Angle::zero())) Ok(generic::TransformOperation::Rotate(Angle::zero()))
}, },
generic::TransformOperation::Perspective(ref l) => Ok( generic::TransformOperation::Perspective(_) => Ok(
generic::TransformOperation::Perspective(l.to_animated_zero()?), generic::TransformOperation::Perspective(Length::new(std::f32::INFINITY))
), ),
generic::TransformOperation::AccumulateMatrix { .. } | generic::TransformOperation::AccumulateMatrix { .. } |
generic::TransformOperation::InterpolateMatrix { .. } => { generic::TransformOperation::InterpolateMatrix { .. } => {

View file

@ -583,10 +583,10 @@ impl<T: ToMatrix> Transform<T> {
/// Return the transform matrix from a perspective length. /// Return the transform matrix from a perspective length.
#[inline] #[inline]
pub fn create_perspective_matrix(d: CSSFloat) -> Transform3D<CSSFloat> { pub fn create_perspective_matrix(d: CSSFloat) -> Transform3D<CSSFloat> {
if d < 0.0 { if d.is_finite() {
Transform3D::identity()
} else {
Transform3D::perspective(d.max(1.)) Transform3D::perspective(d.max(1.))
} else {
Transform3D::identity()
} }
} }