Tatooine
PiYG.h
Go to the documentation of this file.
1#ifndef TATOOINE_COLOR_SCALES_PIYG_H
2#define TATOOINE_COLOR_SCALES_PIYG_H
3//==============================================================================
4#include <tatooine/concepts.h>
5#include <tatooine/vec.h>
6
7#include <memory>
8//==============================================================================
10//==============================================================================
11template <floating_point Real>
12struct PiYG {
13 using real_type = Real;
16 static constexpr std::size_t num_samples() { return 17; }
17 //==============================================================================
18 private:
19 std::unique_ptr<color_type[]> m_data;
20
21 public:
22 auto data_container() -> color_type* { return m_data; }
23 auto data_container() const -> color_type const* { return m_data; }
24 auto data() -> color_type* { return m_data.get(); }
25 auto data() const -> color_type const* { return m_data.get(); }
26 //==============================================================================
28 : m_data{new color_type[]{
29 {0.556863, 0.0039220000000000001, 0.32156899999999999},
30 {0.692195, 0.067896999999999999, 0.42737399999999998},
31 {0.797539, 0.197847, 0.53917700000000002},
32 {0.85905399999999998, 0.42422100000000001, 0.65974600000000005},
33 {0.90857399999999999, 0.59261799999999998, 0.77031899999999998},
34 {0.95155699999999999, 0.73633199999999999, 0.866205},
35 {0.98108399999999996, 0.83967700000000001, 0.91787799999999997},
36 {0.98292999999999997, 0.913802, 0.94955800000000001},
37 {0.96731999999999996, 0.96847399999999995, 0.96562899999999996},
38 {0.92549000000000003, 0.96355199999999996, 0.86966600000000005},
39 {0.852441, 0.93925400000000003, 0.73602500000000004},
40 {0.73925399999999997, 0.890042, 0.55394100000000002},
41 {0.60323000000000004, 0.80553600000000003, 0.38223800000000002},
42 {0.46728199999999998, 0.71141900000000002, 0.23521700000000001},
43 {0.344252, 0.608074, 0.15647800000000001},
44 {0.24060000000000001, 0.49826999999999999, 0.116494},
45 {0.15294099999999999, 0.39215699999999998, 0.098039000000000001}}} {
46 }
47 //----------------------------------------------------------------------------
48 auto sample(real_type t) const {
49 if (t <= 0) {
50 return m_data[0];
51 }
52 if (t >= 1) {
53 return m_data[(num_samples() - 1)];
54 }
55 t *= num_samples() - 1;
56 auto const i = static_cast<std::size_t>(std::floor(t));
57 t = t - i;
58 return m_data[i] * (1 - t) + m_data[i + 1] * t;
59 }
60 auto operator()(real_type const t) const { return sample(t); }
61};
62//==============================================================================
63PiYG()->PiYG<real_number>;
64//==============================================================================
65} // namespace tatooine::color_scales
66//==============================================================================
67#endif
68
Definition: BrBG.h:9
Definition: PiYG.h:12
auto data() -> color_type *
Definition: PiYG.h:24
auto operator()(real_type const t) const
Definition: PiYG.h:60
auto data_container() -> color_type *
Definition: PiYG.h:22
std::unique_ptr< color_type[]> m_data
Definition: PiYG.h:19
static constexpr std::size_t num_samples()
Definition: PiYG.h:16
Real real_type
Definition: PiYG.h:13
auto sample(real_type t) const
Definition: PiYG.h:48
auto data() const -> color_type const *
Definition: PiYG.h:25
auto data_container() const -> color_type const *
Definition: PiYG.h:23
PiYG()
Definition: PiYG.h:27
Definition: vec.h:12