-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use f64::clamp #44
Use f64::clamp #44
Conversation
Stabilized in Rust 1.50, and resvg now has MSRV 1.65.
@@ -310,7 +310,7 @@ fn f64_bound(min: f64, val: f64, max: f64) -> f64 { | |||
debug_assert!(min.is_finite()); | |||
debug_assert!(val.is_finite()); | |||
debug_assert!(max.is_finite()); | |||
val.max(min).min(max) | |||
val.clamp(min, max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter that this might introduce a panic? (In the face of wrong code…)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but I don't think it matters. min
and max
aren't set by user code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I nearly brought this up in #43 before seeing this PR. I think this is reasonable
src/color.rs
Outdated
debug_assert!(min.is_finite()); | ||
debug_assert!(val.is_finite()); | ||
debug_assert!(max.is_finite()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug_assert!(min.is_finite()); | |
debug_assert!(val.is_finite()); | |
debug_assert!(max.is_finite()); | |
debug_assert!(val.is_finite()); |
I don't think the f64::INFINITY
case is likely to come up for min
or max
.
(Fwiw, I think the last assertion is a bit dodgy; infinity is fine, it's just NaN
that we don't want to propagate)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that one is a bit dodgy, infinity would get clamped to the almost-surely-finite min
or max
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just merge it as-is (with that assertion) and not spend too much thought on it, as it's likely to go away anyway. This keeps the same behavior, which may be useful for the patch release.
Co-authored-by: Daniel McNab <[email protected]>
Stabilized in Rust 1.50, and resvg now has MSRV 1.65.