mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implement Servo_ParseTransformIntoMatrix.
DOMMatrix needs to convert a specified transform list into a matrix, so we could rewrite to_transform_3d_matrix by generics for both specified and computed transform lists. Besides, we have to update the test case because we use Transform3D<f64> to compute the matrix, instead of Transform3D<f32>, so the result will be the same as that in Gecko. Using 0.3 may cause floating point issue because (0.3f32 as f64) is not equal to 0.3 (i.e. floating point precision issue), so using 0.25 instead.
This commit is contained in:
parent
ac6e04ebfb
commit
3a38e815ec
16 changed files with 450 additions and 238 deletions
|
@ -4,9 +4,10 @@
|
|||
|
||||
//! Computed angles.
|
||||
|
||||
use euclid::Radians;
|
||||
use num_traits::Zero;
|
||||
use std::{f32, f64};
|
||||
use std::f64::consts::PI;
|
||||
use std::ops::Add;
|
||||
use values::CSSFloat;
|
||||
use values::animated::{Animate, Procedure};
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
@ -64,11 +65,6 @@ impl Angle {
|
|||
radians.min(f64::MAX).max(f64::MIN)
|
||||
}
|
||||
|
||||
/// Returns an angle that represents a rotation of zero radians.
|
||||
pub fn zero() -> Self {
|
||||
Self::from_radians(0.0)
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-transitions/#animtype-number>
|
||||
#[inline]
|
||||
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
|
@ -76,6 +72,45 @@ impl Angle {
|
|||
}
|
||||
}
|
||||
|
||||
impl AsRef<Angle> for Angle {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Angle {
|
||||
type Output = Self;
|
||||
|
||||
#[inline]
|
||||
fn add(self, rhs: Self) -> Self {
|
||||
match (self, rhs) {
|
||||
(Angle::Deg(x), Angle::Deg(y)) => Angle::Deg(x + y),
|
||||
(Angle::Grad(x), Angle::Grad(y)) => Angle::Grad(x + y),
|
||||
(Angle::Turn(x), Angle::Turn(y)) => Angle::Turn(x + y),
|
||||
(Angle::Rad(x), Angle::Rad(y)) => Angle::Rad(x + y),
|
||||
_ => Angle::from_radians(self.radians() + rhs.radians()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Zero for Angle {
|
||||
#[inline]
|
||||
fn zero() -> Self {
|
||||
Angle::from_radians(0.0)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
match *self {
|
||||
Angle::Deg(val) |
|
||||
Angle::Grad(val) |
|
||||
Angle::Turn(val) |
|
||||
Angle::Rad(val) => val == 0.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ComputeSquaredDistance for Angle {
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
|
@ -84,10 +119,3 @@ impl ComputeSquaredDistance for Angle {
|
|||
self.radians64().compute_squared_distance(&other.radians64())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Angle> for Radians<CSSFloat> {
|
||||
#[inline]
|
||||
fn from(a: Angle) -> Self {
|
||||
Radians::new(a.radians())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue