draw_line_aa
Mojo function 🡭
draw_line_aa
fn def draw_line_aa(mut canvas: Canvas, x0: Int, y0: Int, x1: Int, y1: Int, color: Color, width: Float64 = 1, supersample: Int = Int(4), dashes: List[Float64] = List(), dash_offset: Float64 = 0, cap: LineCap = LineCap.ROUND, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)Anti-aliased line, width pixels wide (default 1), finished with cap at each end.
A one-segment polyline, and drawn as one: _draw_polyline_core_aa
turns the stroke into an outline and fills it, so the cost follows
the stroke’s area rather than its bounding box.
Args:
- canvas (
Canvas): Canvas to draw into. - x0 (
Int): Start point x. - y0 (
Int): Start point y. - x1 (
Int): End point x. - y1 (
Int): End point y. - color (
Color): Line color. - width (
Float64): Stroke width in pixels. - supersample (
Int): Sub-pixel grid side length per pixel (N -> N*N samples) for the one stroke that still samples: a closed one whose inner ring inverts, the width being past the curve’s radius of curvature. Every other stroke rasterizes by exact area and ignores it. See_stroke_edges. - dashes (
List[Float64]): On/off segment lengths in pixels, cycled along the line. Empty (default) draws a solid line. - dash_offset (
Float64): Distance into the dash pattern the line starts at. - cap (
LineCap): How the two ends are finished – see LineCap. - join (
LineJoin): Unused for a single segment, which has no corners. - miter_limit (
Float64): Unused for a single segment.
fn def draw_line_aa(mut canvas: Canvas, x0: Float64, y0: Float64, x1: Float64, y1: Float64, color: Color, width: Float64 = 1, supersample: Int = Int(4), dashes: List[Float64] = List(), dash_offset: Float64 = 0, cap: LineCap = LineCap.ROUND, join: LineJoin = LineJoin.ROUND, miter_limit: Float64 = 4)draw_line_aa at sub-pixel endpoints – the same line, 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. Placing a value at x = 103.7 rather than rounding to 104 shifts the line by a third of a pixel, which at a 1px stroke width is visible.
Args:
- canvas (
Canvas): Canvas to draw into. - x0 (
Float64): Start point x. - y0 (
Float64): Start point y. - x1 (
Float64): End point x. - y1 (
Float64): End point y. - color (
Color): Line color. - width (
Float64): Stroke width in pixels. - supersample (
Int): Sub-pixel grid side length per pixel (N -> N*N samples) for the one stroke that still samples: a closed one whose inner ring inverts, the width being past the curve’s radius of curvature. Every other stroke rasterizes by exact area and ignores it. See_stroke_edges. - dashes (
List[Float64]): On/off segment lengths in pixels, cycled along the line. Empty (default) draws a solid line. - dash_offset (
Float64): Distance into the dash pattern the line starts at. - cap (
LineCap): How the two ends are finished – see LineCap. - join (
LineJoin): Unused for a single segment, which has no corners. - miter_limit (
Float64): Unused for a single segment.