Skip to content
path

path

Mojo module 🡭

path

A general path type: move/line/quadratic-curve/cubic-curve/arc-to/ close, built up through chained calls, then flattened into straight- line segments and handed to canvas.shapes’ polyline/polygon/fill machinery.

Coordinates are Float64 (FPoint), not Point’s integer pixels, and stay that way end to end: flattening keeps sub-pixel positions rather than snapping them to the grid, so fill_path_aa’s coverage sweep sees where an edge actually falls. Text depends on it – a glyph at 12px has most of its outline landing between pixel centers. The hard-edged consumers (fill_path, stroke_path, stroke_path_aa) address whole pixels and round at the point of use.

Quad/cubic flattening picks its step count per segment from that segment’s curvature; _auto_steps carries the bound. curve_steps overrides it: a positive value forces that many segments, 0 (the default) chooses per segment. arc_to instead reuses canvas.shapes.arcs’ _arc_fpoints, whose step count is proportional to radius.

A path can hold multiple sub-paths (more than one move_to). fill_path combines every sub-path’s scanline crossings, so an outer shape plus an inner sub-path punches a hole the way ‘o’ or ‘A’ need. stroke_path/stroke_path_aa draw each sub-path independently, closed (draw_polygon) or open (draw_polyline) depending on whether close() was called.

Structs

  • PathOp: Which builder call a PathCommand records: one of MOVE_TO, LINE_TO, QUAD_TO, CUBIC_TO, CLOSE, ARC_TO. Prints as its name, so assert_equal(cmd.op, PathOp.MOVE_TO) reports which op it found.
  • PathCommand: One path command, as Path.commands records it. Which of p1/p2/p3 matter depends on op: MOVE_TO/LINE_TO use p1 (endpoint); QUAD_TO uses p1 (control) and p2 (endpoint); CUBIC_TO uses all three (control1, control2, endpoint); CLOSE uses none; ARC_TO packs five scalars across the three points – p1 = (cx, cy), p2 = (radius, start_angle), p3.x = end_angle, p3.y unused. Unused fields are zeroed.
  • Path: Build with move_to/line_to/quad_curve_to/cubic_curve_to/arc_to/ close, or a whole shape at once with rect/round_rect/ellipse/ regular_polygon/arrow_head, then hand to fill_path/stroke_path/ stroke_path_aa. No chaining: each call is mut self returning nothing, like Canvas’s push_clip/set_pixel.

Functions