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

Class XYRasterSparse_RGB8

src/fl/gfx/raster_sparse.h:228–389  ·  view source on GitHub ↗

A raster of CRGB values. This is a sparse raster, meaning that it will only store the values that are set.

Source from the content-addressed store, hash-verified

226// A raster of CRGB values. This is a sparse raster, meaning that it will
227// only store the values that are set.
228class XYRasterSparse_RGB8 {
229 public:
230 XYRasterSparse_RGB8() FL_NOEXCEPT = default;
231 XYRasterSparse_RGB8(u16 width, u16 height) {
232 setBounds(rect<u16>(0, 0, width, height));
233 }
234 XYRasterSparse_RGB8(const XYRasterSparse_RGB8 &) FL_NOEXCEPT = default;
235 XYRasterSparse_RGB8 &operator=(XYRasterSparse_RGB8 &&) FL_NOEXCEPT = default;
236 XYRasterSparse_RGB8(XYRasterSparse_RGB8 &&) FL_NOEXCEPT = default;
237 XYRasterSparse_RGB8 &operator=(XYRasterSparse_RGB8 &) FL_NOEXCEPT = default;
238
239 XYRasterSparse_RGB8 &reset() {
240 mSparseGrid.clear();
241 mCache.clear();
242 return *this;
243 }
244
245 XYRasterSparse_RGB8 &clear() { return reset(); }
246
247 // Rasterizes point with a CRGB color value
248 void rasterize(const vec2<u16> &pt, const CRGB &color) {
249 write(pt, color);
250 }
251
252 void setSize(u16 width, u16 height) {
253 setBounds(rect<u16>(0, 0, width, height));
254 }
255
256 void setBounds(const rect<u16> &bounds) {
257 mAbsoluteBounds = bounds;
258 mAbsoluteBoundsSet = true;
259 }
260
261 using iterator = fl::unordered_map<vec2<u16>, CRGB>::iterator;
262 using const_iterator = fl::unordered_map<vec2<u16>, CRGB>::const_iterator;
263
264 iterator begin() { return mSparseGrid.begin(); }
265 const_iterator begin() const { return mSparseGrid.begin(); }
266 iterator end() { return mSparseGrid.end(); }
267 const_iterator end() const { return mSparseGrid.end(); }
268 fl::size size() const { return mSparseGrid.size(); }
269 bool empty() const { return mSparseGrid.empty(); }
270
271 pair<bool, CRGB> at(u16 x, u16 y) const {
272 const CRGB *val = mSparseGrid.find_value(vec2<u16>(x, y));
273 if (val != nullptr) {
274 return {true, *val};
275 }
276 return {false, CRGB::Black};
277 }
278
279 rect<u16> bounds() const {
280 if (mAbsoluteBoundsSet) {
281 return mAbsoluteBounds;
282 }
283 return bounds_pixels();
284 }
285

Callers

nothing calls this directly

Calls 2

resetFunction · 0.50
clearMethod · 0.45

Tested by

no test coverage detected