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

Method drawDiscCore

src/fl/gfx/primitives.h:656–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

654// ---------------------------------------------------------------------------
655template<typename PixelT, typename Coord, bool Overwrite>
656inline void detail::drawDiscCore(Canvas<PixelT>& canvas, const PixelT& color,
657 Coord cx, Coord cy, Coord r) {
658 PixelT* pixels = canvas.pixels;
659 int width = canvas.width;
660 int height = canvas.height;
661
662 fl::i32 cx8 = detail::toFixed8(cx);
663 fl::i32 cy8 = detail::toFixed8(cy);
664 fl::i32 r8 = detail::toFixed8(r);
665
666 fl::i32 rin8 = r8 - 128; // r - 0.5 in 8.8
667 fl::i32 rout8 = r8 + 128; // r + 0.5 in 8.8
668
669 fl::i32 rin2 = rin8 * rin8;
670 fl::i32 rout2 = rout8 * rout8;
671 fl::i32 band = rout2 - rin2;
672 if (band <= 0) return;
673
674 int ri = (rout8 >> 8) + 1;
675 int cxi = cx8 >> 8;
676 int cyi = cy8 >> 8;
677
678 int xmin = cxi - ri; if (xmin < 0) xmin = 0;
679 int xmax = cxi + ri; if (xmax >= width) xmax = width - 1;
680 if (xmin > xmax) return;
681 if (cyi + ri < 0 || cyi - ri >= height) return;
682
683 fl::i32 dx8 = (static_cast<fl::i32>(xmin) << 8) - cx8;
684 fl::i32 dx2 = dx8 * dx8;
685
686 detail::DiscCtx<PixelT> fc;
687 fc.xdelta0 = 512 * dx8 + 65536;
688 fc.xmin = xmin; fc.xmax = xmax;
689 fc.rin2 = rin2; fc.rout2 = rout2;
690 detail::computeBandShift(band, fc.band_shift, fc.band_inv);
691 fc.color = color;
692
693 fl::i32 cyfrac = (static_cast<fl::i32>(cyi) << 8) - cy8;
694 fl::i32 d2c = dx2 + cyfrac * cyfrac;
695
696 if (cyi >= 0 && cyi < height)
697 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, cyi, d2c, fc);
698
699 fl::i32 botd2 = d2c, botdelta = 512 * cyfrac + 65536;
700 fl::i32 topd2 = d2c, topdelta = -512 * cyfrac + 65536;
701 botd2 += botdelta; botdelta += 131072;
702 topd2 += topdelta; topdelta += 131072;
703
704 for (int dy = 1; dy <= ri; ++dy) {
705 bool cbot = (botd2 - dx2 <= rout2);
706 bool ctop = (topd2 - dx2 <= rout2);
707 if (!cbot && !ctop) break;
708 int pyb = cyi + dy, pyt = cyi - dy;
709 if (cbot && pyb >= 0 && pyb < height)
710 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, pyb, botd2, fc);
711 if (ctop && pyt >= 0 && pyt < height)
712 detail::renderDiscRow<PixelT, Overwrite>(pixels, width, pyt, topd2, fc);
713 botd2 += botdelta; botdelta += 131072;

Callers

nothing calls this directly

Calls 2

toFixed8Function · 0.85
computeBandShiftFunction · 0.85

Tested by

no test coverage detected