use crate::{color::Color, math::FloatNumber};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Swatch<T>
where
T: FloatNumber,
{
color: Color<T>,
position: (u32, u32),
population: usize,
ratio: T,
}
impl<T> Swatch<T>
where
T: FloatNumber,
{
pub fn new(color: Color<T>, position: (u32, u32), population: usize, ratio: T) -> Self {
Self {
color,
position,
population,
ratio,
}
}
#[inline]
#[must_use]
pub fn color(&self) -> &Color<T> {
&self.color
}
#[inline]
#[must_use]
pub fn position(&self) -> (u32, u32) {
self.position
}
#[inline]
#[must_use]
pub fn population(&self) -> usize {
self.population
}
#[inline]
#[must_use]
pub fn ratio(&self) -> T {
self.ratio
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_swatch() {
let color = Color::new(80.0, 0.0, 0.0);
let swatch = Swatch::new(color.clone(), (5, 10), 384, 0.25);
assert_eq!(swatch.color(), &color);
assert_eq!(swatch.position(), (5, 10));
assert_eq!(swatch.population(), 384);
}
}