pub struct FloatColor { /* private fields */ }Implementations§
Source§impl FloatColor
impl FloatColor
Sourcepub fn set_r(&mut self, new_value: f64)
pub fn set_r(&mut self, new_value: f64)
Sets the red value of the color.
Values range from 0.0 (no red) to 1.0 (fully red).
The provided color value is clamped between 0.0 and 1.0.
§Panics
This function will panic if the provided argument is NaN.
§Examples
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_r(0.5);
assert_eq!(color.get_r(), 0.5);let mut color_clamped_lower = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_lower.set_r(-20.0);
assert_eq!(color_clamped_lower.get_r(), 0.0);let mut color_clamped_upper = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_upper.set_r(15.0);
assert_eq!(color_clamped_upper.get_r(), 1.0);This example will panic:
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_r(std::f64::NAN);Sourcepub fn set_g(&mut self, new_value: f64)
pub fn set_g(&mut self, new_value: f64)
Sets the green value of the color.
Values range from 0.0 (no green) to 1.0 (fully green).
The provided color value is clamped between 0.0 and 1.0.
§Panics
This function will panic if the provided argument is NaN.
§Examples
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_g(0.6);
assert_eq!(color.get_g(), 0.6);let mut color_clamped_lower = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_lower.set_g(-20.0);
assert_eq!(color_clamped_lower.get_g(), 0.0);let mut color_clamped_upper = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_upper.set_g(15.0);
assert_eq!(color_clamped_upper.get_g(), 1.0);This example will panic:
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_g(std::f64::NAN);Sourcepub fn set_b(&mut self, new_value: f64)
pub fn set_b(&mut self, new_value: f64)
Sets the blue value of the color.
Values range from 0.0 (no blue) to 1.0 (fully blue).
The provided color value is clamped between 0.0 and 1.0.
§Panics
This function will panic if the provided argument is NaN.
§Examples
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_b(0.7);
assert_eq!(color.get_b(), 0.7);let mut color_clamped_lower = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_lower.set_b(-20.0);
assert_eq!(color_clamped_lower.get_b(), 0.0);let mut color_clamped_upper = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_upper.set_b(15.0);
assert_eq!(color_clamped_upper.get_b(), 1.0);This example will panic:
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_b(std::f64::NAN);Sourcepub fn set_a(&mut self, new_value: f64)
pub fn set_a(&mut self, new_value: f64)
Sets the alpha (opacity) value of the color.
Values range from 0.0 (fully transparent) to 1.0 (fully opaque).
The provided color value is clamped between 0.0 and 1.0.
§Panics
This function will panic if the provided argument is NaN.
§Examples
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_a(0.8);
assert_eq!(color.get_a(), 0.8);let mut color_clamped_lower = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_lower.set_a(-20.0);
assert_eq!(color_clamped_lower.get_a(), 0.0);let mut color_clamped_upper = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color_clamped_upper.set_a(15.0);
assert_eq!(color_clamped_upper.get_a(), 1.0);This example will panic:
let mut color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
color.set_a(std::f64::NAN);Sourcepub fn get_r(&self) -> f64
pub fn get_r(&self) -> f64
Returns the red value of the color.
Values range from 0.0 (no red) to 1.0 (fully red).
§Examples
let color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
assert_eq!(color.get_r(), 0.1);Sourcepub fn get_g(&self) -> f64
pub fn get_g(&self) -> f64
Returns the green value of the color.
Values range from 0.0 (no green) to 1.0 (fully green).
§Examples
let color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
assert_eq!(color.get_g(), 0.2);Sourcepub fn get_b(&self) -> f64
pub fn get_b(&self) -> f64
Returns the blue value of the color.
Values range from 0.0 (no blue) to 1.0 (fully blue).
§Examples
let color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
assert_eq!(color.get_b(), 0.3);Sourcepub fn get_a(&self) -> f64
pub fn get_a(&self) -> f64
Returns the alpha (opacity) value of the color.
Values range from 0.0 (fully transparent) to 1.0 (fully opaque).
§Examples
let color = FloatColor::new(0.1, 0.2, 0.3, 0.4);
assert_eq!(color.get_a(), 0.4);Sourcepub fn new(r: f64, g: f64, b: f64, a: f64) -> Self
pub fn new(r: f64, g: f64, b: f64, a: f64) -> Self
Constructs a new FloatColor structure from four f64 values.
The color values provided via arguments are clamped between 0.0 and 1.0.
§Panics
This function will panic if any of the arguments is NaN.
§Examples
let color1 = FloatColor::new(0.4, 0.0, -2.9, std::f64::NEG_INFINITY);
assert_eq!(color1.get_r(), 0.4);
assert_eq!(color1.get_g(), 0.0);
assert_eq!(color1.get_b(), 0.0);
assert_eq!(color1.get_a(), 0.0);
let color2 = FloatColor::new(0.6, 1.0, 2.9, std::f64::INFINITY);
assert_eq!(color2.get_r(), 0.6);
assert_eq!(color2.get_g(), 1.0);
assert_eq!(color2.get_b(), 1.0);
assert_eq!(color2.get_a(), 1.0);These examples will panic:
FloatColor::new(std::f64::NAN, 0.2, 0.3, 0.4);FloatColor::new(0.1, std::f64::NAN, 0.3, 0.4);FloatColor::new(0.1, 0.2, std::f64::NAN, 0.4);FloatColor::new(0.1, 0.2, 0.3, std::f64::NAN);Trait Implementations§
Source§impl Clone for FloatColor
impl Clone for FloatColor
Source§fn clone(&self) -> FloatColor
fn clone(&self) -> FloatColor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Color for FloatColor
impl Color for FloatColor
Source§fn hex_rgba_string(&self) -> String
fn hex_rgba_string(&self) -> String
Creates a hexadecimal color string in the format #rrggbbaa.
This function converts float values to bytes by first multiplying the value by 255.0 and then casting the result to u8 (rounding towards 0).
§Examples
let color = FloatColor::new(0.2, 0.901, 0.0, 1.0);
assert_eq!(color.hex_rgba_string(), "#33e500ff");
// 0.901 gets converted to 229.755 which rounds down to 229 (0xe5)Source§fn lightness(&self) -> f64
fn lightness(&self) -> f64
Returns an arithmetic mean of the red, green and blue values. The alpha value is not taken into account.
Note that this is different from the perceived brightness of the color, as high values on some color channels look more bright to the human eye than the same values on other color channels.
§Examples
let color = FloatColor::new(0.1, 0.4, 0.7, 0.2);
assert!((color.lightness() - 0.4).abs() < 0.00001)Source§impl Debug for FloatColor
impl Debug for FloatColor
Source§impl Default for FloatColor
impl Default for FloatColor
Source§impl<'de> Deserialize<'de> for FloatColor
impl<'de> Deserialize<'de> for FloatColor
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<ByteColor> for FloatColor
impl From<ByteColor> for FloatColor
Source§fn from(value: ByteColor) -> Self
fn from(value: ByteColor) -> Self
Convert a ByteColor into a FloatColor.
This function converts bytes to float values by first casting them to f64 and then dividing the value by 255.0.
§Examples
let byte_color = ByteColor::new(0, 32, 53, 255);
let float_color: FloatColor = byte_color.into();
assert_eq!(float_color.get_r(), 0.0);
assert!((float_color.get_g() - 0.125490).abs() < 0.00001);
assert!((float_color.get_b() - 0.207843).abs() < 0.00001);
assert_eq!(float_color.get_a(), 1.0);