Tatooine
BrBG.h
Go to the documentation of this file.
1#ifndef TATOOINE_COLOR_SCALES_BRBG_H
2#define TATOOINE_COLOR_SCALES_BRBG_H
3//==============================================================================
4#include <tatooine/concepts.h>
5#include <tatooine/vec.h>
6
7#include <memory>
8//==============================================================================
10//==============================================================================
11template <floating_point Real>
12struct BrBG {
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.32941199999999998, 0.18823500000000001, 0.019608},
30 {0.46720499999999998, 0.26943499999999998, 0.031911000000000002},
31 {0.59999999999999998, 0.36562899999999998, 0.074202000000000004},
32 {0.72548999999999997, 0.48373699999999997, 0.16032299999999999},
33 {0.81299500000000002, 0.63583199999999995, 0.33640900000000001},
34 {0.88688999999999996, 0.78123799999999999, 0.52787399999999995},
35 {0.94348299999999996, 0.87473999999999996, 0.70011500000000004},
36 {0.96316800000000002, 0.92979599999999996, 0.84159899999999999},
37 {0.95724699999999996, 0.95993799999999996, 0.95955400000000002},
38 {0.84406000000000003, 0.93287200000000003, 0.92018500000000003},
39 {0.70396000000000003, 0.88642799999999999, 0.85928499999999997},
40 {0.52925800000000001, 0.81507099999999999, 0.77070399999999994},
41 {0.34625099999999998, 0.69181099999999995, 0.653057},
42 {0.17585500000000001, 0.56201500000000004, 0.53064199999999995},
43 {0.047905000000000003, 0.44144600000000001, 0.41007300000000002},
44 {0.002307, 0.33217999999999998, 0.294348},
45 {0, 0.235294, 0.18823500000000001}}} {}
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//==============================================================================
62BrBG()->BrBG<real_number>;
63//==============================================================================
64} // namespace tatooine::color_scales
65//==============================================================================
66#endif
67
Definition: BrBG.h:9
Definition: BrBG.h:12
Real real_type
Definition: BrBG.h:13
auto sample(real_type t) const
Definition: BrBG.h:47
auto data() const -> color_type const *
Definition: BrBG.h:25
auto data() -> color_type *
Definition: BrBG.h:24
auto data_container() const -> color_type const *
Definition: BrBG.h:23
static constexpr std::size_t num_samples()
Definition: BrBG.h:16
BrBG()
Definition: BrBG.h:27
auto data_container() -> color_type *
Definition: BrBG.h:22
auto operator()(real_type const t) const
Definition: BrBG.h:59
std::unique_ptr< color_type[]> m_data
Definition: BrBG.h:19
Definition: vec.h:12