draw_ellipse_aa
Mojo function 🡭
draw_ellipse_aa
fn def draw_ellipse_aa(mut canvas: Canvas, cx: Int, cy: Int, rx: Int, ry: Int, color: Color, supersample: Int = Int(4), width: Float64 = 1)Anti-aliased ellipse outline, width pixels wide (default 1) – draw_circle_aa’s generalization to independent x/y radii.
Args:
- canvas (
Canvas): Canvas to draw into. - cx (
Int): Center x. - cy (
Int): Center y. - rx (
Int): Horizontal radius in pixels, to the middle of the stroke. - ry (
Int): Vertical radius in pixels, to the middle of the stroke. - color (
Color): Outline color. - supersample (
Int): Sub-pixel grid side length per pixel (N -> N*N samples). - width (
Float64): Stroke width in pixels.
fn def draw_ellipse_aa(mut canvas: Canvas, cx: Float64, cy: Float64, rx: Float64, ry: Float64, color: Color, supersample: Int = Int(4), width: Float64 = 1)draw_ellipse_aa at a sub-pixel center and radii; the whole-pixel overload above converts and calls this.
No single distance value serves both boundaries here: an ellipse’s
(rx-w/2, ry-w/2) and (rx+w/2, ry+w/2) rings are two different
ellipses, where a circle’s are concentric offsets of one curve. Each
sample is tested against both in their own normalized space:
(dx/outer_rx)^2 + (dy/outer_ry)^2 < 1 (strictly inside outer)
(dx/inner_rx)^2 + (dy/inner_ry)^2 >= 1 (on or outside inner)
Applying +/-w/2 to rx and ry independently, rather than offsetting
along the ellipse’s normal, makes the ring’s width vary around the
ellipse: exactly width at the four axis extremes, narrower
elsewhere. A normal-offset ring would need the perimeter
parameterization. A stroke wider than the shorter diameter leaves
no hole and draws the filled ellipse.
Args:
- canvas (
Canvas): Canvas to draw into. - cx (
Float64): Center x, sub-pixel. - cy (
Float64): Center y, sub-pixel. - rx (
Float64): Horizontal radius in pixels, to the middle of the stroke. - ry (
Float64): Vertical radius in pixels, to the middle of the stroke. - color (
Color): Outline color. - supersample (
Int): Sub-pixel grid side length per pixel (N -> N*N samples). - width (
Float64): Stroke width in pixels.