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