FastLED 3.9.15
Loading...
Searching...
No Matches
xmap.h
Go to the documentation of this file.
1#pragma once
2
4#include "fl/math/lut.h"
5#include "fl/stl/int.h"
6#include "fl/stl/noexcept.h"
7
8namespace fl {
9
11 (void)length;
12 return x;
13}
14
16 return length - 1 - x;
17}
18
19// typedef for xMap function type
20typedef u16 (*XFunction)(u16 x, u16 length);
21
22// XMap holds either a function or a look up table to map x coordinates to a 1D
23// index.
24class XMap {
25 public:
27
29 u16 offset = 0);
30
31 // When a pointer to a lookup table is passed in then we assume it's
32 // owned by someone else and will not be deleted.
34 const u16 *lookUpTable,
35 u16 offset = 0);
36
37 // is_reverse is false by default for linear layout
38 XMap(u16 length, bool is_reverse = false, u16 offset = 0);
39
40 XMap(const XMap &other) FL_NOEXCEPT;
41
42 // define the assignment operator
43 XMap &operator=(const XMap &other) FL_NOEXCEPT;
44
46
47 u16 mapToIndex(u16 x) const;
48
49 u16 operator()(u16 x) const { return mapToIndex(x); }
50
51 u16 getLength() const;
52
53 Type getType() const;
54
55 private:
56 XMap(u16 length, Type type);
57 u16 length = 0;
60 const u16 *mData = nullptr;
61 fl::LUT16Ptr mLookUpTable;
62 u16 mOffset = 0; // offset to be added to the output
63};
64
65} // 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
u16 operator()(u16 x) const
Definition xmap.h:49
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 length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
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
u16(* XFunction)(u16 x, u16 length)
Definition xmap.h:20
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_FORCE_INLINE
#define FL_NOEXCEPT