MCPcopy Create free account
hub / github.com/FastLED/FastLED / mapToIndex

Method mapToIndex

src/fl/math/xymap.cpp.hpp:116–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116u16 XYMap::mapToIndex(const u16 &x, const u16 &y) const {
117 u16 index;
118 switch (type) {
119 case kSerpentine: {
120 u16 xx = x % width;
121 u16 yy = y % height;
122 index = xy_serpentine(xx, yy, width, height);
123 break;
124 }
125 case kLineByLine: {
126 u16 xx = x % width;
127 u16 yy = y % height;
128 index = xy_line_by_line(xx, yy, width, height);
129 break;
130 }
131 case kFunction:
132 if (xyFunction) {
133 index = xyFunction(x, y, width, height);
134 } else {
135 // Null function pointer — fall back to line-by-line to avoid crash.
136 // This can happen due to cross-DLL static initialization order issues.
137 index = xy_line_by_line(x, y, width, height);
138 }
139 break;
140 case kLookUpTable:
141 index = mLookUpTable->getData()[y * width + x];
142 break;
143 default:
144 return 0;
145 }
146 return index + mOffset;
147}
148
149u16 XYMap::getWidth() const { return width; }
150

Callers 1

fromXMapMethod · 0.45

Calls 1

getDataMethod · 0.80

Tested by

no test coverage detected