Tatooine
PRGn.h
Go to the documentation of this file.
1#ifndef TATOOINE_COLOR_SCALES_PRGN_H
2#define TATOOINE_COLOR_SCALES_PRGN_H
3//==============================================================================
4#include <tatooine/concepts.h>
5#include <tatooine/vec.h>
6
7#include <memory>
8//==============================================================================
10//==============================================================================
11template <floating_point Real>
12struct PRGn {
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.25097999999999998, 0, 0.29411799999999999},
30 {0.38385200000000003, 0.10334500000000001, 0.43191099999999999},
31 {0.49773200000000001, 0.234679, 0.55371000000000004},
32 {0.58385200000000004, 0.40692, 0.65213399999999999},
33 {0.68196800000000002, 0.54517499999999997, 0.74256100000000003},
34 {0.78069999999999995, 0.67235699999999998, 0.82522099999999998},
35 {0.87174200000000002, 0.78800499999999996, 0.88673599999999997},
36 {0.93048799999999998, 0.88519800000000004, 0.93287200000000003},
37 {0.96632099999999999, 0.96808899999999998, 0.96585900000000002},
38 {0.89250300000000005, 0.95086499999999996, 0.877278},
39 {0.79607799999999995, 0.91857, 0.77254900000000004},
40 {0.67058799999999996, 0.86689700000000003, 0.64705900000000005},
41 {0.49319499999999999, 0.76539800000000002, 0.49665500000000001},
42 {0.31418699999999999, 0.64913500000000002, 0.35455599999999998},
43 {0.15917000000000001, 0.51626300000000003, 0.25121100000000002},
44 {0.062283999999999999, 0.38662099999999999, 0.17047300000000001},
45 {0, 0.26666699999999999, 0.105882}}} {}
46 //----------------------------------------------------------------------------
47 auto sample(real_type t) const {
48 if (t <= 0) {
49 return m_data[0];
50 }
51 if (t >= 1) {
52 return m_data[(num_samples() - 1)];
53 }
54 t *= num_samples() - 1;
55 auto const i = static_cast<std::size_t>(std::floor(t));
56 t = t - i;
57 return m_data[i] * (1 - t) + m_data[i + 1] * t;
58 }
59 auto operator()(real_type const t) const { return sample(t); }
60};
61//==============================================================================
62PRGn()->PRGn<real_number>;
63//==============================================================================
64} // namespace tatooine::color_scales
65//==============================================================================
66#endif
67
Definition: BrBG.h:9
Definition: PRGn.h:12
auto data() const -> color_type const *
Definition: PRGn.h:25
auto data() -> color_type *
Definition: PRGn.h:24
static constexpr std::size_t num_samples()
Definition: PRGn.h:16
auto data_container() -> color_type *
Definition: PRGn.h:22
Real real_type
Definition: PRGn.h:13
std::unique_ptr< color_type[]> m_data
Definition: PRGn.h:19
PRGn()
Definition: PRGn.h:27
auto operator()(real_type const t) const
Definition: PRGn.h:59
auto sample(real_type t) const
Definition: PRGn.h:47
auto data_container() const -> color_type const *
Definition: PRGn.h:23
Definition: vec.h:12