Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upIntroduce and derive ComputeSquaredDistance #18058
Conversation
highfive
commented
Aug 12, 2017
|
Heads up! This PR modifies the following files:
|
highfive
commented
Aug 12, 2017
Introduce and derive ComputeSquaredDistance This new trait merges the former `Animatable` methods `compute_distance` and `compute_squared_distance`.
|
|
|
It's not clear to me why we need to optimise the case where we only have one distance and we don't want to square it, I think |
|
Looks quite fancy, r=me :) |
| Some(first) => first, | ||
| None => return SquaredDistance::Value(0.), | ||
| }; | ||
| iter.fold(first, Add::add) |
This comment has been minimized.
This comment has been minimized.
emilio
Aug 13, 2017
Member
Can't you do iter.fold(SquaredDistance::Value(0.), Add::add), and remove the match above?
This comment has been minimized.
This comment has been minimized.
nox
Aug 13, 2017
Author
Member
I'm not doing that to avoid pointlessly transforming a SquaredDistance::Sqrt into SquaredDistance::Value if there was only one distance in the iterator. As I said in a comment of the PR though, I'm not sure we should even bother to try to avoid the final f64::sqrt call, I just did it that way to preserve the functionality but I wouldn't mind just storing the squared one always.
| #[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))] | ||
| #[cfg_attr(feature = "servo", derive(Deserialize, HeapSizeOf, Serialize))] | ||
| #[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage)] | ||
| #[derive(PartialEq, PartialOrd, ToComputedValue, ToCss)] |
This comment has been minimized.
This comment has been minimized.
| }, | ||
| _ => { | ||
| // FIXME(nox): Should this return `Ok(SquaredDistance::Value(1.))` | ||
| // when `self` and `other` are the same extremum value? |
This comment has been minimized.
This comment has been minimized.
| }, | ||
| _ => { | ||
| // FIXME(nox): Should this return `Ok(SquaredDistance::Value(0.))` | ||
| // if `self` and `other` are the same keyword value? |
This comment has been minimized.
This comment has been minimized.
| #[inline] | ||
| fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> { | ||
| // FIXME(nox): This looks incorrect to me, to add a distance between lengths | ||
| // with a distance between percentages. |
This comment has been minimized.
This comment has been minimized.
emilio
Aug 13, 2017
Member
Maybe check with @BorisChiou or @hiikezoe? It does seem slightly fishy...
|
@bors-servo r=emilio |
|
|
Introduce and derive ComputeSquaredDistance This new trait merges the former `Animatable` methods `compute_distance` and `compute_squared_distance`. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18058) <!-- Reviewable:end -->
|
|
|
@bors-servo retry #6734 wat |
|
|
|
|
nox commentedAug 12, 2017
•
edited by SimonSapin
This new trait merges the former
Animatablemethodscompute_distanceandcompute_squared_distance.This change is