XYChromaticity

Struct XYChromaticity 

Source
pub struct XYChromaticity { /* private fields */ }

Implementations§

Source§

impl XYChromaticity

Source

pub fn plot_grid( self, x_step: f64, y_step: f64, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 41)
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}
Source

pub fn plot_poly_line( self, points: impl IntoIterator<Item = (f64, f64)>, style_attr: Option<StyleAttr>, ) -> Self

Source

pub fn plot_shape( self, points: impl IntoIterator<Item = (f64, f64)>, style_attr: Option<StyleAttr>, ) -> Self

Source

pub fn draw_data( self, layer: &str, data: Data, style_attr: Option<StyleAttr>, ) -> Self

Source

pub fn draw_path( self, layer: &str, path: Path, style_attr: Option<StyleAttr>, ) -> Self

Source

pub fn plot_image( self, image: impl Into<Image>, style_attr: Option<StyleAttr>, ) -> Self

Source

pub fn ticks( self, x_step: f64, y_step: f64, length: i32, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 26)
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}
Source

pub fn x_labels( self, step: f64, offset: usize, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 28)
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}
Source

pub fn y_labels( self, step: f64, offset: usize, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 30)
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}
Source

pub fn x_axis_description( self, description: &str, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 29)
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}
Source

pub fn y_axis_description( self, description: &str, style_attr: Option<StyleAttr>, ) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 31)
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}
Source

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

Source

pub const ANNOTATE_SEP: u32 = 2u32

Source

pub fn new( width_and_height: (u32, u32), ranges: (impl RangeBounds<f64>, impl RangeBounds<f64>), ) -> XYChromaticity

Examples found in repository?
examples/xy_gamut_plots.rs (line 25)
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}
Source

pub fn set_observer(self, observer: Observer) -> Self

Source

pub fn plot_spectral_locus(self, style_attr: Option<StyleAttr>) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 32)
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}
Source

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?
examples/xy_gamut_plots.rs (line 33)
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}
Source

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?
examples/xy_gamut_plots.rs (line 35)
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}
Source

pub fn plot_planckian_locus(self, style_attr: Option<StyleAttr>) -> Self

Examples found in repository?
examples/xy_gamut_plots.rs (line 37)
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}
Source

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 number
Source

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
Source

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.

Source

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.

Source

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.

Source

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?
examples/xy_gamut_plots.rs (line 38)
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}
Source

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?
examples/xy_gamut_plots.rs (line 40)
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}
Source

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?
examples/xy_gamut_plots.rs (line 36)
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}
Source

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

Source§

fn clone(&self) -> XYChromaticity

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Rendable for XYChromaticity

Implements the XYChromaticity as a Rendable object, allowing it to be rendered as an SVG.

Source§

fn render(&self) -> SVG

Renders the object as an SVG element.
Source§

fn view_parameters(&self) -> ViewParameters

Returns the current view parameters for the object.
Source§

fn set_view_parameters(&mut self, view_box: ViewParameters)

Sets the view parameters for the object.
Source§

fn set_x(&mut self, x: i32)

Sets the x position of the view box (optional).
Source§

fn set_y(&mut self, y: i32)

Sets the y position of the view box (optional).
Source§

fn width(&self) -> u32

Returns the width of the view box (optional).
Source§

fn set_width(&mut self, width: u32)

Sets the width of the view box (optional).
Source§

fn height(&self) -> u32

Returns the height of the view box (optional).
Source§

fn set_height(&mut self, height: u32)

Sets the height of the view box (optional).
Source§

fn view_box(&mut self) -> (i32, i32, u32, u32)

Source§

fn set_view_box(&mut self, vx: i32, vy: i32, vw: u32, vh: u32)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool