Bug 1332633 - Part 1: Implement ComputeDistance trait.

Introduce ComputeDistance trait, which implement compute_distance and
compute_squared_distance.

For vector, compute_squared_distance is necessary because we use Euclidean
distance as the distance between two values. The easier way to implement
compute_squared_distance is to square the result from compute_distance, but
for some property values, they may have many components, e.g. (v1, v2, v3).
If we just square the result from compute_distance, the computation is
(sqrt(v1^2 + v2^2 + v3^2))^2. There are two redundant operators:
"square-root" and then "square". In order to avoid this, we should
implement compute_squared_distance separately for these types.

MozReview-Commit-ID: LmmrUXYlDb6
This commit is contained in:
Boris Chiou 2017-03-18 19:47:04 +08:00
parent 17dc598d99
commit 57f87007f2
7 changed files with 733 additions and 11 deletions

View file

@ -121,7 +121,7 @@ ${helpers.single_keyword("mask-mode",
pub use properties::longhands::background_position_x::single_value::parse;
pub use properties::longhands::background_position_x::single_value::SpecifiedValue;
pub use properties::longhands::background_position_x::single_value::computed_value;
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
use properties::longhands::mask_position_x::computed_value::T as MaskPositionX;
impl Interpolate for MaskPositionX {
@ -132,6 +132,13 @@ ${helpers.single_keyword("mask-mode",
}
impl RepeatableListInterpolate for MaskPositionX {}
impl ComputeDistance for MaskPositionX {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
</%helpers:vector_longhand>
<%helpers:vector_longhand name="mask-position-y" products="gecko" animation_type="normal" extra_prefixes="webkit"
@ -142,7 +149,7 @@ ${helpers.single_keyword("mask-mode",
pub use properties::longhands::background_position_y::single_value::parse;
pub use properties::longhands::background_position_y::single_value::SpecifiedValue;
pub use properties::longhands::background_position_y::single_value::computed_value;
use properties::animated_properties::{Interpolate, RepeatableListInterpolate};
use properties::animated_properties::{ComputeDistance, Interpolate, RepeatableListInterpolate};
use properties::longhands::mask_position_y::computed_value::T as MaskPositionY;
impl Interpolate for MaskPositionY {
@ -153,6 +160,13 @@ ${helpers.single_keyword("mask-mode",
}
impl RepeatableListInterpolate for MaskPositionY {}
impl ComputeDistance for MaskPositionY {
#[inline]
fn compute_distance(&self, _other: &Self) -> Result<f64, ()> {
Err(())
}
}
</%helpers:vector_longhand>
${helpers.single_keyword("mask-clip",