cgmath icon indicating copy to clipboard operation
cgmath copied to clipboard

Add `clamp` and `wraparound` methods

Open faulesocke opened this issue 6 years ago • 1 comments

These methods are quite useful whenever you have to make sure that a value stays inside a specified range. Although there is f32::clamp and f64::clamp these are not stabilized yet so it would be nice to have them inside cgmath.

wraparound should have a signature like this:

fn wraparound<S>(x: S, min: S, max: S) -> S

See also https://stackoverflow.com/questions/4633177/c-how-to-wrap-a-float-to-the-interval-pi-pi#

faulesocke avatar Jul 11 '19 13:07 faulesocke

Just wanted to point out fXX::clamp is stable since Rust version 1.50.0. It would be nice to have it for the common use case of clamping the pitch angle of a camera (uhm, my current use case).

jmi2k avatar Sep 10 '23 19:09 jmi2k