FastLED 3.9.15
Loading...
Searching...
No Matches
xmap.cpp.hpp
Go to the documentation of this file.
1
2
3#include "fl/math/xmap.h"
4#include "fl/stl/noexcept.h"
5
6namespace fl {
7
15
17 const u16 *lookUpTable,
18 u16 offset) {
20 out.mData = lookUpTable;
21 out.mOffset = offset;
22 return out;
23}
24
25XMap::XMap(u16 length, bool is_reverse, u16 offset) {
26 type = is_reverse ? kReverse : kLinear;
27 this->length = length;
28 this->mOffset = offset;
29}
30
31XMap::XMap(const XMap &other) {
32 type = other.type;
33 length = other.length;
34 xFunction = other.xFunction;
35 mData = other.mData;
37 mOffset = other.mOffset;
38}
39
41 if (type == kLookUpTable) {
42 return;
43 }
44 mLookUpTable.reset();
46 u16 *dataMutable = mLookUpTable->getDataMutable();
47 mData = mLookUpTable->getData();
48 for (u16 x = 0; x < length; x++) {
49 dataMutable[x] = mapToIndex(x);
50 }
52 xFunction = nullptr;
53}
54
55u16 XMap::mapToIndex(u16 x) const {
56 u16 index;
57 switch (type) {
58 case kLinear:
59 index = x_linear(x, length);
60 break;
61 case kReverse:
62 index = x_reverse(x, length);
63 break;
64 case kFunction:
65 x = x % length;
66 index = xFunction(x, length);
67 break;
68 case kLookUpTable:
69 index = mData[x];
70 break;
71 default:
72 return 0;
73 }
74 return index + mOffset;
75}
76
77u16 XMap::getLength() const { return length; }
78
79XMap::Type XMap::getType() const { return type; }
80
83
85 if (this != &other) {
86 type = other.type;
87 length = other.length;
88 xFunction = other.xFunction;
89 mData = other.mData;
90 mLookUpTable = other.mLookUpTable;
91 mOffset = other.mOffset;
92 }
93 return *this;
94}
95
96} // namespace fl
void convertToLookUpTable()
Definition xmap.cpp.hpp:40
Type type
Definition xmap.h:58
u16 length
Definition xmap.h:57
u16 mOffset
Definition xmap.h:62
u16 getLength() const
Definition xmap.cpp.hpp:77
Type getType() const
Definition xmap.cpp.hpp:79
XMap & operator=(const XMap &other) FL_NOEXCEPT
Definition xmap.cpp.hpp:84
u16 mapToIndex(u16 x) const
Definition xmap.cpp.hpp:55
static XMap constructWithLookUpTable(u16 length, const u16 *lookUpTable, u16 offset=0)
Definition xmap.cpp.hpp:16
fl::LUT16Ptr mLookUpTable
Definition xmap.h:61
const u16 * mData
Definition xmap.h:60
@ kFunction
Definition xmap.h:26
@ kLookUpTable
Definition xmap.h:26
@ kLinear
Definition xmap.h:26
@ kReverse
Definition xmap.h:26
XMap(u16 length, bool is_reverse=false, u16 offset=0)
Definition xmap.cpp.hpp:25
XFunction xFunction
Definition xmap.h:59
static XMap constructWithUserFunction(u16 length, XFunction xFunction, u16 offset=0)
Definition xmap.cpp.hpp:8
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
FASTLED_FORCE_INLINE u16 x_linear(u16 x, u16 length)
Definition xmap.h:10
FASTLED_FORCE_INLINE u16 x_reverse(u16 x, u16 length)
Definition xmap.h:15
shared_ptr< T > make_shared(Args &&... args) FL_NOEXCEPT
Definition shared_ptr.h:414
u16(* XFunction)(u16 x, u16 length)
Definition xmap.h:20
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT