Tatooine
jet.h
Go to the documentation of this file.
1#ifndef TATOOINE_COLOR_SCALES_JET_H
2#define TATOOINE_COLOR_SCALES_JET_H
3//==============================================================================
4#include <tatooine/concepts.h>
5#include <tatooine/vec.h>
6
7#include <memory>
8//==============================================================================
10//==============================================================================
11template <floating_point Real>
12struct jet {
13 using real_type = Real;
16 //==============================================================================
17 static constexpr auto num_samples() -> std::size_t{return 7;}
18 //==============================================================================
19 std::unique_ptr<color_type[]> m_data;
20 //==============================================================================
22 : m_data{new color_type[]{{0, 0, 0.5625},
23 {0, 0, 1},
24 {0, 1, 1},
25 {0.5, 1, 0.5},
26 {1, 1, 0},
27 {1, 0, 0},
28 {0.5, 0, 0}}} {}
29 //----------------------------------------------------------------------------
30 auto data() -> auto& { return m_data; }
31 auto data() const -> auto const& { return m_data; }
32 //----------------------------------------------------------------------------
33 auto sample(real_type t) const {
34 if (t <= 0) {
35 return m_data[0];
36 }
37 if (t >= 1) {
38 return m_data[num_samples() - 1];
39 }
40 t *= num_samples() - 1;
41 auto const i = static_cast<size_t>(std::floor(t));
42 t = t - i;
43 return m_data[i] * (1 - t) + m_data[i + 1] * t;
44 }
45 //----------------------------------------------------------------------------
46 auto operator()(real_type const t) const { return sample(t); }
47};
48//==============================================================================
49jet()->jet<double>;
50//==============================================================================
51} // namespace tatooine::color_scales
52//==============================================================================
53#endif
54
Definition: BrBG.h:9
Definition: jet.h:12
std::unique_ptr< color_type[]> m_data
Definition: jet.h:19
Real real_type
Definition: jet.h:13
auto operator()(real_type const t) const
Definition: jet.h:46
auto sample(real_type t) const
Definition: jet.h:33
auto data() -> auto &
Definition: jet.h:30
auto data() const -> auto const &
Definition: jet.h:31
static constexpr auto num_samples() -> std::size_t
Definition: jet.h:17
jet()
Definition: jet.h:21
Definition: vec.h:12