color_lib/maps.rs
1//!
2//! This module includes all default color maps for quick use
3//!
4
5use crate::{ColorMap, ColorND};
6
7/// A color map in the gray spectrum
8#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
9pub struct Grays {
10 /// The alpha value
11 a: f32,
12}
13
14impl Grays {
15 /// Constructs a new gray color map
16 ///
17 /// parameters
18 ///
19 /// a: The alpha value
20 pub fn new(a: f32) -> Self {
21 return Self {
22 a: a.clamp(0.0, 1.0),
23 };
24 }
25
26 /// Constructs a new gray color map without clamping the input values
27 ///
28 /// parameters
29 ///
30 /// a: The alpha value
31 pub unsafe fn new_unsafe(a: f32) -> Self {
32 return Self { a };
33 }
34}
35
36impl ColorMap<1> for Grays {
37 fn get_color(&self, color: ColorND<1>) -> impl crate::Color {
38 return unsafe { crate::colors::Grays::new_unsafe(color.get()[0], self.a) };
39 }
40}