bevy_color/
color_range.rsuse std::ops::Range;
use crate::Mix;
pub trait ColorRange<T: Mix> {
fn at(&self, factor: f32) -> T;
}
impl<T: Mix> ColorRange<T> for Range<T> {
fn at(&self, factor: f32) -> T {
self.start.mix(&self.end, factor)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::palettes::basic;
use crate::{LinearRgba, Srgba};
#[test]
fn test_color_range() {
let range = basic::RED..basic::BLUE;
assert_eq!(range.at(0.0), basic::RED);
assert_eq!(range.at(0.5), Srgba::new(0.5, 0.0, 0.5, 1.0));
assert_eq!(range.at(1.0), basic::BLUE);
let lred: LinearRgba = basic::RED.into();
let lblue: LinearRgba = basic::BLUE.into();
let range = lred..lblue;
assert_eq!(range.at(0.0), lred);
assert_eq!(range.at(0.5), LinearRgba::new(0.5, 0.0, 0.5, 1.0));
assert_eq!(range.at(1.0), lblue);
}
}