Skip to content
fill_polygon_aa

fill_polygon_aa

Mojo function 🡭

fill_polygon_aa

fn def fill_polygon_aa(mut canvas: Canvas, points: List[Point], color: Color, fill_rule: FillRule = FillRule.EVEN_ODD, supersample: Int = Int(4))

Anti-aliased filled polygon: for every pixel near the polygon, samples an NxN sub-pixel grid and turns the coverage fraction into that pixel’s alpha. Each output pixel is visited exactly once, so a translucent color cannot double-blend. draw_polygon_aa is the AA outline.

Pixels are centered at their integer coordinate, as in every other AA primitive here, and fill_rule shares _is_inside with fill_polygon so the two agree on the boundary.

Args:

  • canvas (Canvas): Canvas to fill into.
  • points (List[Point]): Polygon vertices, in order. Implicitly closed.
  • color (Color): Fill color.
  • fill_rule (FillRule): EVEN_ODD (default) or NONZERO – see FillRule.
  • supersample (Int): Sub-pixel grid side length per pixel (N -> N*N samples) under EVEN_ODD. A NONZERO fill rasterizes by exact area (canvas.aa_area) and ignores it.
fn def fill_polygon_aa(mut canvas: Canvas, points: List[FPoint], color: Color, fill_rule: FillRule = FillRule.EVEN_ODD, supersample: Int = Int(4))

fill_polygon_aa at sub-pixel vertices – the same fill, with its outline placed to a fraction of a pixel rather than snapped to the pixel grid.

This is the real implementation; the whole-pixel overload above converts and calls it.

Args:

  • canvas (Canvas): Canvas to fill into.
  • points (List[FPoint]): Polygon vertices, in order, at sub-pixel positions. Implicitly closed.
  • color (Color): Fill color.
  • fill_rule (FillRule): EVEN_ODD (default) or NONZERO – see FillRule.
  • supersample (Int): Sub-pixel grid side length per pixel (N -> N*N samples) under EVEN_ODD. A NONZERO fill rasterizes by exact area (canvas.aa_area) and ignores it.