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

stylo: Bug 1362896 - Implement ComputeSquaredDistance for TransformList #18086

Merged
merged 4 commits into from Aug 18, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Use f64 for Quaternion.

The unit of gfxQuaternion in Gecko is gfxFloat, which is "double", so
it's better to use f64 to match the precision of Gecko.
  • Loading branch information
BorisChiou committed Aug 17, 2017
commit 03e1794c12f1e98cd859e4655826da2ed9d53dac
@@ -1776,7 +1776,7 @@ pub struct Perspective(f32, f32, f32, f32);
/// A quaternion used to represent a rotation.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Quaternion(f32, f32, f32, f32);
pub struct Quaternion(f64, f64, f64, f64);

/// A decomposed 3d matrix.
#[derive(Clone, Copy, Debug)]
@@ -1914,10 +1914,10 @@ fn decompose_3d_matrix(mut matrix: ComputedMatrix) -> Result<MatrixDecomposed3D,

// Now, get the rotations out
let mut quaternion = Quaternion (
0.5 * ((1.0 + row[0][0] - row[1][1] - row[2][2]).max(0.0)).sqrt(),
0.5 * ((1.0 - row[0][0] + row[1][1] - row[2][2]).max(0.0)).sqrt(),
0.5 * ((1.0 - row[0][0] - row[1][1] + row[2][2]).max(0.0)).sqrt(),
0.5 * ((1.0 + row[0][0] + row[1][1] + row[2][2]).max(0.0)).sqrt()
0.5 * ((1.0 + row[0][0] - row[1][1] - row[2][2]).max(0.0) as f64).sqrt(),
0.5 * ((1.0 - row[0][0] + row[1][1] - row[2][2]).max(0.0) as f64).sqrt(),
0.5 * ((1.0 - row[0][0] - row[1][1] + row[2][2]).max(0.0) as f64).sqrt(),
0.5 * ((1.0 + row[0][0] + row[1][1] + row[2][2]).max(0.0) as f64).sqrt()
);

if row[2][1] > row[1][2] {
@@ -2034,7 +2034,7 @@ impl Animatable for MatrixDecomposed3D {
// Determine the scale factor.
let mut theta = clamped_w.acos();
let mut scale = if theta == 0.0 { 0.0 } else { 1.0 / theta.sin() };
theta *= self_portion as f32;
theta *= self_portion;
scale *= theta.sin();

// Scale the self matrix by self_portion.
@@ -2068,12 +2068,12 @@ impl Animatable for MatrixDecomposed3D {
}

let theta = product.acos();
let w = (other_portion as f32 * theta).sin() * 1.0 / (1.0 - product * product).sqrt();
let w = (other_portion * theta).sin() * 1.0 / (1.0 - product * product).sqrt();

let mut a = *self;
let mut b = *other;
% for i in range(4):
a.quaternion.${i} *= (other_portion as f32 * theta).cos() - product * w;
a.quaternion.${i} *= (other_portion * theta).cos() - product * w;
b.quaternion.${i} *= w;
sum.quaternion.${i} = a.quaternion.${i} + b.quaternion.${i};
% endfor
@@ -2110,15 +2110,15 @@ impl From<MatrixDecomposed3D> for ComputedMatrix {
// Construct a composite rotation matrix from the quaternion values
// rotationMatrix is a identity 4x4 matrix initially
let mut rotation_matrix = ComputedMatrix::identity();
rotation_matrix.m11 = 1.0 - 2.0 * (y * y + z * z);
rotation_matrix.m12 = 2.0 * (x * y + z * w);
rotation_matrix.m13 = 2.0 * (x * z - y * w);
rotation_matrix.m21 = 2.0 * (x * y - z * w);
rotation_matrix.m22 = 1.0 - 2.0 * (x * x + z * z);
rotation_matrix.m23 = 2.0 * (y * z + x * w);
rotation_matrix.m31 = 2.0 * (x * z + y * w);
rotation_matrix.m32 = 2.0 * (y * z - x * w);
rotation_matrix.m33 = 1.0 - 2.0 * (x * x + y * y);
rotation_matrix.m11 = 1.0 - 2.0 * (y * y + z * z) as f32;
rotation_matrix.m12 = 2.0 * (x * y + z * w) as f32;
rotation_matrix.m13 = 2.0 * (x * z - y * w) as f32;
rotation_matrix.m21 = 2.0 * (x * y - z * w) as f32;
rotation_matrix.m22 = 1.0 - 2.0 * (x * x + z * z) as f32;
rotation_matrix.m23 = 2.0 * (y * z + x * w) as f32;
rotation_matrix.m31 = 2.0 * (x * z + y * w) as f32;
rotation_matrix.m32 = 2.0 * (y * z - x * w) as f32;
rotation_matrix.m33 = 1.0 - 2.0 * (x * x + y * y) as f32;

matrix = multiply(rotation_matrix, matrix);

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.