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

@ -439,13 +439,14 @@ ${helpers.single_keyword("text-align-last",
pub mod computed_value {
use app_units::Au;
use properties::animated_properties::Interpolate;
use properties::animated_properties::{ComputeDistance, Interpolate};
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Au>);
${helpers.impl_interpolate_for_option_tuple('Au(0)')}
${helpers.impl_compute_distance_for_option_tuple('Au(0)')}
}
impl ToCss for computed_value::T {
@ -523,13 +524,14 @@ ${helpers.single_keyword("text-align-last",
}
pub mod computed_value {
use properties::animated_properties::Interpolate;
use properties::animated_properties::{ComputeDistance, Interpolate};
use values::computed::LengthOrPercentage;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<LengthOrPercentage>);
${helpers.impl_interpolate_for_option_tuple('LengthOrPercentage::zero()')}
${helpers.impl_compute_distance_for_option_tuple('LengthOrPercentage::zero()')}
}
impl ToCss for computed_value::T {