mirror of
https://github.com/danbulant/cushy
synced 2026-05-24 12:28:23 +00:00
Lerp/PercentBetween fixes
Asserting condition on PercentBetween, Color lerping now works correctly according to testing with gray shades, but due to rounding errors, no unit test is being checked in at the moment.
This commit is contained in:
parent
4c7c3be5ba
commit
42ed86cdfd
1 changed files with 9 additions and 4 deletions
|
|
@ -779,6 +779,8 @@ macro_rules! impl_percent_between {
|
|||
($type:ident, $float:ident) => {
|
||||
impl PercentBetween for $type {
|
||||
fn percent_between(&self, min: &Self, max: &Self) -> ZeroToOne {
|
||||
assert!(min <= max, "percent_between requires min <= max");
|
||||
|
||||
let range = *max - *min;
|
||||
ZeroToOne::from(*self as $float / range as $float)
|
||||
}
|
||||
|
|
@ -812,10 +814,13 @@ impl PercentBetween for Color {
|
|||
func(value).percent_between(&func(min), &func(max))
|
||||
}
|
||||
|
||||
channel_percent(*self, *min, *max, Color::red)
|
||||
* channel_percent(*self, *min, *max, Color::green)
|
||||
* channel_percent(*self, *min, *max, Color::blue)
|
||||
* channel_percent(*self, *min, *max, Color::alpha)
|
||||
ZeroToOne::new(
|
||||
(*channel_percent(*self, *min, *max, Color::red)
|
||||
+ *channel_percent(*self, *min, *max, Color::green)
|
||||
+ *channel_percent(*self, *min, *max, Color::blue)
|
||||
+ *channel_percent(*self, *min, *max, Color::alpha))
|
||||
/ 4.,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue