aboutsummaryrefslogtreecommitdiffstats
path: root/components/style_derive/compute_squared_distance.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/style_derive/compute_squared_distance.rs')
-rw-r--r--components/style_derive/compute_squared_distance.rs21
1 files changed, 18 insertions, 3 deletions
diff --git a/components/style_derive/compute_squared_distance.rs b/components/style_derive/compute_squared_distance.rs
index 5b414206cda..f7e50c6bb00 100644
--- a/components/style_derive/compute_squared_distance.rs
+++ b/components/style_derive/compute_squared_distance.rs
@@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use animate::{AnimationInputAttrs, AnimationVariantAttrs};
+use animate::{AnimationInputAttrs, AnimationVariantAttrs, AnimationFieldAttrs};
use cg;
use quote::Tokens;
use syn::{DeriveInput, Path};
@@ -47,8 +47,23 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
parse_quote!(#ty: ::values::distance::ComputeSquaredDistance),
);
}
- quote! {
- ::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
+
+ let animation_field_attrs =
+ cg::parse_field_attrs::<AnimationFieldAttrs>(&this.ast());
+
+ if animation_field_attrs.constant {
+ quote! {
+ {
+ if #this != #other {
+ return Err(());
+ }
+ ::values::distance::SquaredDistance::from_sqrt(0.)
+ }
+ }
+ } else {
+ quote! {
+ ::values::distance::ComputeSquaredDistance::compute_squared_distance(#this, #other)?
+ }
}
}), quote!(+));
sum