Skip to content
fill_circle_aa

fill_circle_aa

Mojo function 🡭

fill_circle_aa

fn def fill_circle_aa(mut canvas: Canvas, cx: Int, cy: Int, radius: Int, color: Color, supersample: Int = Int(4))

Anti-aliased filled disk.

Pixel (px, py) is centered AT (px, py), the convention the hard-edged draw_circle/fill_circle use, not a unit square with (px, py) at its corner. That is what makes supersample=1 degenerate to the hard-edged decision pixel for pixel.

Before sampling, the pixel’s square ([px-0.5, px+0.5] x [py-0.5, py+0.5]) is tested for being provably wholly inside or outside the disk, via its nearest and farthest points from the center (point-to-AABB min/max distance). Either way all n*n samples would agree, so coverage is 0 or full without visiting the grid, leaving the per-sample loop to the O(radius) pixels straddling the edge rather than all O(radius^2).

Args:

  • canvas (Canvas): Canvas to fill into.
  • cx (Int): Center x.
  • cy (Int): Center y.
  • radius (Int): Circle radius in pixels.
  • color (Color): Fill color.
  • supersample (Int): Sub-pixel grid side length per pixel (N -> N*N samples).
fn def fill_circle_aa(mut canvas: Canvas, cx: Float64, cy: Float64, radius: Float64, color: Color, supersample: Int = Int(4))

fill_circle_aa at a sub-pixel center and radius – the same disk, placed and sized 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.
  • cx (Float64): Center x, sub-pixel.
  • cy (Float64): Center y, sub-pixel.
  • radius (Float64): Circle radius in pixels, sub-pixel.
  • color (Color): Fill color.
  • supersample (Int): Sub-pixel grid side length per pixel (N -> N*N samples).