Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make transforms generic #18750

Merged
merged 21 commits into from Nov 2, 2017
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
337d48a
Add generic struct for transform
Manishearth Oct 3, 2017
dcefcc3
Add ToComputedValue and ToCss impls
Manishearth Oct 3, 2017
d6525e0
Add specified and computed variants of Transform/TransformOperation
Manishearth Oct 3, 2017
5449898
Add parsing support for transform
Manishearth Oct 3, 2017
5031d14
Use a generic Matrix3D type
Manishearth Oct 3, 2017
2de3464
Add ToAnimatedZero implementation
Manishearth Oct 3, 2017
5ce2966
Add utilities for converting Transform to euclid types
Manishearth Oct 4, 2017
6631594
Replace old transform code with new generic code
Manishearth Oct 4, 2017
079b25d
Share transform function lists between set_transform and clone_transform
Manishearth Oct 4, 2017
fc29de8
Add support for more functions in Gecko glue
Manishearth Oct 6, 2017
e20c508
Add support for 2D matrices in Gecko glue
Manishearth Oct 30, 2017
e156952
Add support for transform functions with an optional final argument i…
Manishearth Oct 30, 2017
aba00be
Add more operations to animation
Manishearth Oct 30, 2017
f699b8c
Handle animating 2D matrices
Manishearth Oct 31, 2017
9c9a181
Allow cross interpolation between differing translate/scale functions
Manishearth Oct 31, 2017
ca02785
Handle case of empty transform lists
Manishearth Oct 31, 2017
5098948
Handle distance calculation of new variants
Manishearth Oct 31, 2017
6415294
Fix unit tests
Manishearth Oct 31, 2017
1c12e0e
Rustfmt the new files
Manishearth Nov 1, 2017
123bc1d
Update test expectations
Manishearth Nov 2, 2017
cb9645c
Comments and minor fixes
Manishearth Nov 2, 2017
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Handle animating 2D matrices

  • Loading branch information
Manishearth committed Nov 2, 2017
commit f699b8cfb265bdd99bf509bce9bd205ce1923c62
@@ -44,7 +44,7 @@ use values::computed::{LengthOrPercentageOrNone, MaxLength};
use values::computed::{NonNegativeNumber, Number, NumberOrPercentage, Percentage};
use values::computed::length::NonNegativeLengthOrPercentage;
use values::computed::ToComputedValue;
use values::computed::transform::{DirectionVector, Matrix3D};
use values::computed::transform::{DirectionVector, Matrix, Matrix3D};
use values::generics::transform::{Transform, TransformOperation};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
#[cfg(feature = "gecko")] use values::generics::FontSettings as GenericFontSettings;
@@ -1033,7 +1033,14 @@ impl Animate for ComputedTransformOperation {
this.animate(other, procedure)?,
))
},
// XXXManishearth handle 2D matrix
(
&TransformOperation::Matrix(ref this),
&TransformOperation::Matrix(ref other),
) => {
Ok(TransformOperation::Matrix(
this.animate(other, procedure)?,
))
},
(
&TransformOperation::Skew(ref fx, ref fy),
&TransformOperation::Skew(ref tx, ref ty),
@@ -1444,6 +1451,32 @@ impl Animate for Matrix3D {
}
}

impl Animate for Matrix {
#[cfg(feature = "servo")]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
let this = Matrix3D::from(*self);
let other = Matrix3D::from(*other);
let this = MatrixDecomposed2D::from(this);
let other = MatrixDecomposed2D::from(other);
Ok(Matrix3D::from(this.animate(&other, procedure)?).into_2d()?)
}

#[cfg(feature = "gecko")]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {

This comment has been minimized.

@emilio

emilio Nov 1, 2017

Member

Why the difference between servo and Gecko? At least deserves a comment.

This comment has been minimized.

@Manishearth

Manishearth Nov 1, 2017

Author Member

Not my decision, check out the stuff for matrix3d. This is the same thing translated into a 2d version.

Gecko doesn't follow the spec, basically, but we have to match it to pass tests.

This comment has been minimized.

@emilio

emilio Nov 2, 2017

Member

This deserves comments, and links to specs.

let from = decompose_2d_matrix(&(*self).into());
let to = decompose_2d_matrix(&(*other).into());
match (from, to) {
(Ok(from), Ok(to)) => {
Matrix3D::from(from.animate(&to, procedure)?).into_2d()
},
// Matrices can be undecomposable due to couple reasons, e.g.,
// non-invertible matrices. In this case, we should report Err here,
// and let the caller do the fallback procedure.
_ => Err(())
}
}
}

impl ComputeSquaredDistance for Matrix3D {
#[inline]
#[cfg(feature = "servo")]
@@ -63,6 +63,22 @@ impl Matrix3D {
m41: 0., m42: 0., m43: 0., m44: 1.0
}
}

/// Convert to a 2D Matrix
pub fn into_2d(self) -> Result<Matrix, ()> {
if self.m13 == 0. && self.m23 == 0. &&
self.m31 == 0. && self.m32 == 0. &&
self.m33 == 1. && self.m34 == 0. &&
self.m14 == 0. && self.m24 == 0. &&
self.m43 == 0. && self.m44 == 1. {
Ok(Matrix {
a: self.m11, c: self.m21, e: self.m41,
b: self.m12, d: self.m22, f: self.m42,
})
} else {
Err(())
}
}
}

impl PrefixedMatrix3D {
@@ -84,10 +100,21 @@ impl Matrix {
/// Get an identity matrix
pub fn identity() -> Self {
Self {
a: 1., c: 0., /* 0 */e: 0.,
b: 0., d: 1., /* 0 */f: 0.,
a: 1., c: 0., /* 0 0*/
b: 0., d: 1., /* 0 0*/
/* 0 0 1 0 */
/* 0 0 0 1 */
e: 0., f: 0., /* 0 1 */
}
}
}

impl From<Matrix> for Matrix3D {
fn from(m: Matrix) -> Self {
Self {
m11: m.a, m12: m.b, m13: 0.0, m14: 0.0,
m21: m.c, m22: m.d, m23: 0.0, m24: 0.0,
m31: 0.0, m32: 0.0, m33: 1.0, m34: 0.0,
m41: m.e, m42: m.f, m43: 0.0, m44: 1.0
}
}
}
@@ -97,10 +124,10 @@ impl PrefixedMatrix {
/// Get an identity matrix
pub fn identity() -> Self {
Self {
a: 1., c: 0., /* 0 */e: Either::First(0.),
b: 0., d: 1., /* 0 */f: Either::First(0.),
/* 0 0 1 0 */
/* 0 0 0 1 */
a: 1., c: 0., /* 0 0 */
b: 0., d: 1., /* 0 0 */
/* 0 0 1 0 */
e: Either::First(0.), f: Either::First(0.), /* 0 1 */
}
}
}
@@ -240,10 +267,7 @@ impl ToAnimatedZero for TransformOperation {
GenericTransformOperation::Scale3D(..) => {
Ok(GenericTransformOperation::Scale3D(1.0, 1.0, 1.0))
},
GenericTransformOperation::Scale(_, None) => {
Ok(GenericTransformOperation::Scale(1.0, None))
},
GenericTransformOperation::Scale(_, Some(_)) => {
GenericTransformOperation::Scale(_, _) => {
Ok(GenericTransformOperation::Scale(1.0, Some(1.0)))
},
GenericTransformOperation::ScaleX(..) => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.