|
FastLED 3.10.10
|
|
inline |
Exact left-of-line coverage of one pixel for one polygon edge.
Line: x(tau) = x_q + (B/D) * tau with tau in Q16.16 relative to the row center (the caller's anchor; drawPolygonCore always anchors at the row center, which is what the floored-Q16.16 edge crossing stores); u = D * (x_q - px * 65536) at the anchor. Returns T = round(2^28 * cov) where cov = int_{ta}^{tb} clamp(x(tau) - px_left, 0, 1) dtau/65536, i.e. the fraction of the pixel lying to the LEFT of the line over the row sub-interval [ta, tb]. Pixel coverage between span lines L (left) and R (right) is then T_left(R) - T_left(L).
In s = B * tau space the clamp breakpoints are integers (s = -u and s = 2*D*32768 - u), so the integral is a sum of at most two trapezoid/rectangle pieces: M = (hi-lo) * ((u+lo)+(u+hi)) + (s_hi-lo2) * (4*D*32768) T = round(M / (32*D*|B|)) M < 2^98, den = 32*D*S < 2^67; the exact quotient is < 2^31 and the result is clamped to 2^28 = kPolyOne, the physical full-pixel bound.
The quotient is the exact round-half-up M / den for every den (#5286). For den < 2^63 (every edge with dx*dy < 2^26 px^2, i.e. all normal polygons) it is the committed 457b21d1b shift-subtract, which is exact in that range; huge edges (den >= 2^63) divide M >> 4 by den >> 4 instead, see the comment at the den setup. In polyDivRoundT28 M is left-aligned so its highest relevant bit sits at the top of the 128-bit window, and the numerator is fed top-down by left-shifting the window in place — constant-width shifts only, no FPU, no __int128, and on AVR the whole loop stays in registers (no libgcc __*di3 helper calls). An M == 0 numerator (line does not cross the pixel within [ta, tb]) returns 0 immediately. Result: [0, kPolyOne].
Definition at line 541 of file primitives.h.
References fl::B, fl::FL_NO_EXCEPT, kPolyOne, polyAdd128(), polyDivRoundT28(), polyLineT28(), and polyMul128().
Referenced by drawPolygonCore(), and polyLineT28().
Here is the call graph for this function:
Here is the caller graph for this function: