File: preset.rs

package info (click to toggle)
rust-colorgrad 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 364 kB
  • sloc: makefile: 15
file content (95 lines) | stat: -rw-r--r-- 2,029 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use colorgrad::Gradient;

mod utils;

#[test]
fn preset() {
    let g = colorgrad::preset::viridis();
    cmp_hex!(g.at(0.0), "#440154");
    cmp_hex!(g.at(0.5), "#27838e");
    cmp_hex!(g.at(1.0), "#fee825");
    cmp_hex!(g.at(f32::NAN), "#000000");

    let g = colorgrad::preset::greys();
    cmp_hex!(g.at(0.0), "#ffffff");
    cmp_hex!(g.at(1.0), "#000000");

    let g = colorgrad::preset::turbo();
    cmp_hex!(g.at(0.0), "#23171b");
    cmp_hex!(g.at(1.0), "#900c00");

    let g = colorgrad::preset::cividis();
    cmp_hex!(g.at(0.0), "#002051");
    cmp_hex!(g.at(1.0), "#fdea45");

    let g = colorgrad::preset::cubehelix_default();
    cmp_hex!(g.at(0.0), "#000000");
    cmp_hex!(g.at(1.0), "#ffffff");

    let g = colorgrad::preset::warm();
    cmp_hex!(g.at(0.0), "#6e40aa");
    cmp_hex!(g.at(1.0), "#aff05b");

    let g = colorgrad::preset::cool();
    cmp_hex!(g.at(0.0), "#6e40aa");
    cmp_hex!(g.at(1.0), "#aff05b");

    macro_rules! presets {
        ($($name:ident),+ $(,)?) => {
            $({
                let g = colorgrad::preset::$name();
                assert_eq!(g.domain(), (0.0, 1.0));
            })*
        }
    }

    presets!(
        blues,
        br_bg,
        bu_gn,
        bu_pu,
        cividis,
        cool,
        cubehelix_default,
        gn_bu,
        greens,
        greys,
        inferno,
        magma,
        or_rd,
        oranges,
        pi_yg,
        plasma,
        pr_gn,
        pu_bu,
        pu_bu_gn,
        pu_or,
        pu_rd,
        purples,
        rainbow,
        rd_bu,
        rd_gy,
        rd_pu,
        rd_yl_bu,
        rd_yl_gn,
        reds,
        sinebow,
        spectral,
        turbo,
        viridis,
        warm,
        yl_gn,
        yl_gn_bu,
        yl_or_br,
        yl_or_rd,
    );
}

#[test]
fn cyclic() {
    let g = colorgrad::preset::rainbow();
    assert_eq!(g.at(0.0).to_rgba8(), g.at(1.0).to_rgba8());

    let g = colorgrad::preset::sinebow();
    assert_eq!(g.at(0.0).to_rgba8(), g.at(1.0).to_rgba8());
}