glyphCoverageAA function

double glyphCoverageAA(
  1. List<QuadCurve> curves,
  2. GlyphBands bands,
  3. double x,
  4. double y,
  5. double pxPerEmX,
  6. double pxPerEmY,
)

Anti-aliased coverage at em-space (x, y), the Slug-style dual-ray evaluation the B3 shader mirrors step for step (see the library header for the formula). pxPerEmX/pxPerEmY are the glyph's device-pixels-per-em along each axis - they set the width of the AA ramp (one device pixel).

Robustness: crossing COUNTS and SIGNS come from strict endpoint comparisons (p > level), never from root-in-range tests - adjacent curves share endpoint values exactly (fixed-point encoding), so a crossing at a joint counts exactly once regardless of float noise in the root positions (which only nudge the AA ramp). Endpoints on the same side contribute either zero or a canceling double crossing (both roots strictly inside (0,1)).

Implementation

double glyphCoverageAA(List<QuadCurve> curves, GlyphBands bands, double x,
    double y, double pxPerEmX, double pxPerEmY) {
  if (bands.bandCount == 0) return 0;
  var covH = 0.0;
  for (final index in bands.bands[bands.bandFor(y)]) {
    final c = curves[index];
    covH += _rayCrossings(c.y0 - y, c.cy - y, c.y1 - y, c.x0, c.cx, c.x1, x,
        pxPerEmX, false);
  }
  var covV = 0.0;
  for (final index in bands.vBands[bands.vBandFor(x)]) {
    final c = curves[index];
    covV += _rayCrossings(c.x0 - x, c.cx - x, c.x1 - x, c.y0, c.cy, c.y1, y,
        pxPerEmY, true);
  }
  final h = covH.abs().clamp(0.0, 1.0);
  final v = covV.abs().clamp(0.0, 1.0);
  return (h + v) / 2;
}