-
While porting a crate to This was the solution I ended up with for the trait bounds, constraining to pub fn difference<Wp, T>(c1: palette::Lab<Wp, T>, c2: palette::Lab<Wp, T>) -> f32
where
T: palette::num::Real
+ palette::num::Arithmetics
+ palette::color_difference::EuclideanDistance
+ palette::num::IntoScalarArray<1>
+ palette::num::FromScalar<Scalar = f32>
+ Copy,
{
T::into_array(
palette::color_difference::EuclideanDistance::distance_squared(c1, c2)
)[0]
} Is there a better way to do this? I was wondering if it made sense to have something similar to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 18 replies
-
Hmm, I think the issue here is just that you are trying to convert |
Beta Was this translation helpful? Give feedback.
I see, sorry for the headaches. First, let me just answer your last question: prefer
num-traits
overpalette::num
as much as you possibly can for now. It's much more complete and long-term stable, and also more integrated in the general ecosystem.palette::num
should ideally be a separate crate but I didn't want to take that step without trying it out in practice first (and I'm not sure I should be the one maintaining it, honestly).For the case with
Lab
(I found your PR and had a look), since you effectively requiredLab<Wp, f32>
before, you should be able to continue doing that and not make it generic over the component type for now. You shouldn't have to introduce new requirements in t…