pub struct XYChromaticity { /* private fields */ }Implementations§
Source§impl XYChromaticity
impl XYChromaticity
Sourcepub fn plot_grid(
self,
x_step: f64,
y_step: f64,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_grid( self, x_step: f64, y_step: f64, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}pub fn plot_poly_line( self, points: impl IntoIterator<Item = (f64, f64)>, style_attr: Option<StyleAttr>, ) -> Self
pub fn plot_shape( self, points: impl IntoIterator<Item = (f64, f64)>, style_attr: Option<StyleAttr>, ) -> Self
pub fn draw_data( self, layer: &str, data: Data, style_attr: Option<StyleAttr>, ) -> Self
pub fn draw_path( self, layer: &str, path: Path, style_attr: Option<StyleAttr>, ) -> Self
pub fn plot_image( self, image: impl Into<Image>, style_attr: Option<StyleAttr>, ) -> Self
Sourcepub fn ticks(
self,
x_step: f64,
y_step: f64,
length: i32,
style_attr: Option<StyleAttr>,
) -> Self
pub fn ticks( self, x_step: f64, y_step: f64, length: i32, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn x_labels(
self,
step: f64,
offset: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn x_labels( self, step: f64, offset: usize, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn y_labels(
self,
step: f64,
offset: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn y_labels( self, step: f64, offset: usize, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn x_axis_description(
self,
description: &str,
style_attr: Option<StyleAttr>,
) -> Self
pub fn x_axis_description( self, description: &str, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn y_axis_description(
self,
description: &str,
style_attr: Option<StyleAttr>,
) -> Self
pub fn y_axis_description( self, description: &str, style_attr: Option<StyleAttr>, ) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}pub fn label_pin( self, cxy: (f64, f64), r: f64, angle_and_length: (i32, i32), text: impl AsRef<str>, style_attr: Option<StyleAttr>, ) -> Self
Source§impl XYChromaticity
impl XYChromaticity
pub const ANNOTATE_SEP: u32 = 2u32
Sourcepub fn new(
width_and_height: (u32, u32),
ranges: (impl RangeBounds<f64>, impl RangeBounds<f64>),
) -> XYChromaticity
pub fn new( width_and_height: (u32, u32), ranges: (impl RangeBounds<f64>, impl RangeBounds<f64>), ) -> XYChromaticity
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}pub fn set_observer(self, observer: Observer) -> Self
Sourcepub fn plot_spectral_locus(self, style_attr: Option<StyleAttr>) -> Self
pub fn plot_spectral_locus(self, style_attr: Option<StyleAttr>) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn plot_spectral_locus_ticks(
self,
range: impl RangeBounds<usize>,
step: usize,
length: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_spectral_locus_ticks( self, range: impl RangeBounds<usize>, step: usize, length: usize, style_attr: Option<StyleAttr>, ) -> Self
Plots spectral locus ticks perpendicular to the spectral locus for
a range for wavelengths, specficied by a start wavelength and an end wavelength,
in usize units of nanometer, and with a step in nanometers.
The length parameter specifies the length of the tick lines in pixels.
A positive length will draw the ticks pointing inwards, towards the white point,
and negative length will draw the ticks pointing outwards, away from the white point.
Typically you will use this method multiple times to draw ticks for different ranges, and different lengths, with the finest ticks plotted first, and the coarsest ticks plotted last, plotting over the fine lines.
The style_attr parameter allows you to specify the style of the ticks,
such as stroke color, width, and other SVG style attributes.
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn plot_spectral_locus_labels(
self,
range: impl RangeBounds<usize> + Clone,
step: usize,
distance: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_spectral_locus_labels( self, range: impl RangeBounds<usize> + Clone, step: usize, distance: usize, style_attr: Option<StyleAttr>, ) -> Self
Plots spectral locus labels for the specified range of wavelengths, with a step size in nanometers.
The labels are rotated to align with the spectral locus slope at each point.
The distance parameter specifies the distance from the spectral locus to the label in pixels.
The style_attr parameter allows you to specify the style of the labels,
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn plot_planckian_locus(self, style_attr: Option<StyleAttr>) -> Self
pub fn plot_planckian_locus(self, style_attr: Option<StyleAttr>) -> Self
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn planckian_xy_slope_angle(&self, cct: f64) -> ((f64, f64), f64)
pub fn planckian_xy_slope_angle(&self, cct: f64) -> ((f64, f64), f64)
Calculates the slope angle of the Planckian locus at a given CCT. Returns a tuple containing the chromaticity coordinates (x, y) and the slope angle in degrees. The slope angle is the angle of the tangent to the Planckian locus in the xy chromatity chart at the specified CCT, and points left with increasing CCT. Angles in SVG are measured clockwise from the positive x-axis.
§Arguments
cct- The correlated color temperature in Kelvin.
§Returns
A tuple containing the chromaticity coordinates (x, y) and the slope angle in degrees.
§Example
use colorimetry_plot::chart::XYChromaticity;
let xy_chromaticity = XYChromaticity::new((800, 600), (0.0..=0.75, 0.0..=0.875));
let (xy, angle) = xy_chromaticity.planckian_xy_slope_angle(2300.0);
approx::assert_abs_diff_eq!(angle.to_degrees(), -178.0, epsilon = 0.5);
let (xy, angle) = xy_chromaticity.planckian_xy_slope_angle(6500.0);
approx::assert_abs_diff_eq!(angle.to_degrees(), -136.0, epsilon = 0.5); // Check if the angle is a finite numberSourcepub fn planckian_uvp_normal_angle(&self, cct: f64) -> ((f64, f64), f64)
pub fn planckian_uvp_normal_angle(&self, cct: f64) -> ((f64, f64), f64)
The iso-temperature lines are defined as the lines that are perpendicular to the slope of the Planckian locus at a given CCT in the CIE 1960 (u,v) chromaticity diagram, using the CIE 1931 standard observer.
§References
- CIE 015:2018, “Colorimetry, 4th Edition”, Section 9.4
Sourcepub fn cct_transform(&self, cct_duv: (f64, f64)) -> Result<(f64, f64), Error>
pub fn cct_transform(&self, cct_duv: (f64, f64)) -> Result<(f64, f64), Error>
Transform a (CCT, duv) pair to a plot point using the CIE 1931 observer.
§Arguments
cct_duv- A tuple containing the correlated color temperature (CCT) in Kelvin and the chromaticity deviation from the Planckian locus (duv).
§Returns
A Result containing a tuple of the transformed chromaticity coordinates (x, y) in the plot space.
§Errors
Returns an error if the CCT is invalid or cannot be converted to XYZ coordinates.
Sourcepub fn plot_ansi_step7(
self,
rgb_space: RgbSpace,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_ansi_step7( self, rgb_space: RgbSpace, style_attr: Option<StyleAttr>, ) -> Self
Plots the ANSI C78.377-2017 step 7 Quadrangles in the plot, filled with the color corresponding to the CCT and duv target.
Sourcepub fn planckian_xy_normal_angle(&self, cct: f64) -> ((f64, f64), f64)
pub fn planckian_xy_normal_angle(&self, cct: f64) -> ((f64, f64), f64)
Get the normal to the Planckian locus, which is perpendicular to the slope at the given CCT. Returns a tuple containing the chromaticity coordinates (x, y) and the normal angle in radians.
Sourcepub fn plot_planckian_locus_ticks(
self,
values: impl IntoIterator<Item = u32>,
length: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_planckian_locus_ticks( self, values: impl IntoIterator<Item = u32>, length: usize, style_attr: Option<StyleAttr>, ) -> Self
Plots the Planckian locus ticks at specified CCT values. Typically, you will use this method several times to create a nice looking scale, with different ranges and lengths. The scale if very non-linear, and requires small steps for the lower CCT values, and larger steps for the higher CCT values.
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn plot_planckian_locus_labels(
self,
values: impl IntoIterator<Item = u32>,
distance: usize,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_planckian_locus_labels( self, values: impl IntoIterator<Item = u32>, distance: usize, style_attr: Option<StyleAttr>, ) -> Self
Plots labels for the Planckian locus at specified CCT values, divided by 100. The labels are rotated to align with the normal to the the Planckian locus at each point, centered away from the white point.
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn plot_rgb_gamut(
self,
rgb_space: RgbSpace,
style_attr: Option<StyleAttr>,
) -> Self
pub fn plot_rgb_gamut( self, rgb_space: RgbSpace, style_attr: Option<StyleAttr>, ) -> Self
Plots the sRGB gamut as an embeded image overlay in the plot layer. At this point, only correct colors are shown in case the RGB space is sRGB. For other color spaces, the colors are clipped to the sRGB gamut.
Examples found in repository?
20pub fn make_plot(space: RgbSpace) -> Result<(), Box<dyn std::error::Error>> {
21 let observer = Observer::Cie1931; // Use the CIE 1931 observer
22 // let space = RgbSpace::DisplayP3; // Use the sRGB color space
23
24 // Create an XYChromaticity chart with the specified observer and ranges
25 let xy_chromaticity = XYChromaticity::new((775, 875), (-0.025..=0.75, 0.0..=0.875))
26 .ticks(0.01, 0.01, 5, class("fine-grid"))
27 .ticks(0.1, 0.1, 10, class("grid"))
28 .x_labels(0.1, 10, None)
29 .x_axis_description(&format!("{} x", observer.name()), None)
30 .y_labels(0.1, 10, class("y-labels"))
31 .y_axis_description(&format!("{} y", observer.name()), None)
32 .plot_spectral_locus(class("spectral-locus"))
33 .plot_spectral_locus_ticks(440..=650, 10, 15, class("spectral-locus-ticks"))
34 .plot_spectral_locus_ticks(460..=630, 1, 7, class("spectral-locus-ticks"))
35 .plot_spectral_locus_labels(460..=620, 10, 3, class("spectral-locus-labels"))
36 .plot_rgb_gamut(space, None)
37 .plot_planckian_locus(class("planckian"))
38 .plot_planckian_locus_ticks((1500..=7500).step_by(100), 7, class("planckian-ticks-fine"))
39 .plot_planckian_locus_ticks(PLANCKIAN_LABELS_AT.to_vec(), 15, class("planckian-ticks"))
40 .plot_planckian_locus_labels(PLANCKIAN_LABELS_AT.to_vec(), 18, class("planckian-labels"))
41 .plot_grid(0.01, 0.01, class("fine-grid"))
42 .plot_grid(0.1, 0.1, class("grid"));
43
44 // create the plot
45 SvgDocument::new()
46 .append_scss(STYLE)
47 .add_plot(Box::new(xy_chromaticity))
48 .save(format!("docs/img/{}_gamut.svg", space.as_ref().to_lowercase()).as_str())?;
49 Ok(())
50}Sourcepub fn annotate_white_points(
&mut self,
point: impl IntoIterator<Item = (CieIlluminant, (i32, i32))>,
) -> &mut Self
pub fn annotate_white_points( &mut self, point: impl IntoIterator<Item = (CieIlluminant, (i32, i32))>, ) -> &mut Self
Draw white points on the chromaticity diagram as an iterator of CieIlluminant, and i32 angle and length pairs.
Trait Implementations§
Source§impl Clone for XYChromaticity
impl Clone for XYChromaticity
Source§fn clone(&self) -> XYChromaticity
fn clone(&self) -> XYChromaticity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Rendable for XYChromaticity
Implements the XYChromaticity as a Rendable object, allowing it to be rendered as an SVG.
impl Rendable for XYChromaticity
Implements the XYChromaticity as a Rendable object, allowing it to be rendered as an SVG.
Source§fn view_parameters(&self) -> ViewParameters
fn view_parameters(&self) -> ViewParameters
Source§fn set_view_parameters(&mut self, view_box: ViewParameters)
fn set_view_parameters(&mut self, view_box: ViewParameters)
Source§fn set_height(&mut self, height: u32)
fn set_height(&mut self, height: u32)
fn view_box(&mut self) -> (i32, i32, u32, u32)
fn set_view_box(&mut self, vx: i32, vy: i32, vw: u32, vh: u32)
Auto Trait Implementations§
impl Freeze for XYChromaticity
impl !RefUnwindSafe for XYChromaticity
impl !Send for XYChromaticity
impl !Sync for XYChromaticity
impl Unpin for XYChromaticity
impl !UnwindSafe for XYChromaticity
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.