servo / euclid

Geometry primitives (basic linear algebra) for Rust
Other
462 stars 103 forks source link

Scale `mod`, `div` by scalar #499

Closed ArtHome12 closed 1 year ago

ArtHome12 commented 1 year ago

Is Scale's lack of the ability to multiply and divide by T due to something or is it just unfinished? I have to write code like this

let step: f32...
let scale = self.scale.get() * step;
let scale = scale.clamp(self.min_scale.get(), self.max_scale.get());
Scale::new(scale)

Instead this

let scale = self.scale * step;
scale.clamp(self.min_scale, self.max_scale)
ArtHome12 commented 1 year ago

Although clamp() won't work:

the following trait bounds were not satisfied: f32: Ord

ArtHome12 commented 1 year ago

I came to the conclusion that the step from the example in the post should not be T, but already Scale<T...> And no mod,div by scalar` is required.

Perhaps for completeness, need to add Scale::transform_length() (in addition to transform_vector, transform_point, transform_size...), but guided by the rule "less code is better" I think it should not do this. At least until someone needs it.

Scale::clamp() will made according to the same in crate::point

ArtHome12 commented 1 year ago

Done 77e6901