plot::path
On this page
Vector paths in pixel coordinates (y down): moves, lines, quadratic and cubic Beziers, and closes. The SVG backend writes them as they are; the rasterizer and the terminal flatten them to polylines.
Structs
PathSource
pub struct PathA path. Its point lists are shared by copies, so build it in one place and hand it over.
use plot::Path;
let p = Path::new();
p.move_to(0.0, 0.0);
p.line_to(10.0, 0.0);
p.close();
assert(p.len() == 3);
An empty path.
nabiassert(plot::Path::new().is_empty());The number of commands.
nabiassert(plot::Path::rect(0.0, 0.0, 1.0, 1.0).len() == 5);Whether the path has no commands.
nabiassert(!plot::Path::circle(0.0, 0.0, 1.0).is_empty());Starts a subpath at
(x, y).nabilet p = plot::Path::new(); p.move_to(1.0, 2.0); assert(p.bounds() == (1.0, 2.0, 1.0, 2.0));A straight line to
(x, y).nabilet p = plot::Path::new(); p.move_to(0.0, 0.0); p.line_to(3.0, 4.0); assert(p.bounds().3 == 4.0);A quadratic Bezier through control
(cx, cy)to(x, y).nabilet p = plot::Path::new(); p.move_to(0.0, 0.0); p.quad_to(1.0, 2.0, 2.0, 0.0); assert(p.len() == 2);A cubic Bezier through controls
(c1x, c1y),(c2x, c2y)to(x, y).nabilet p = plot::Path::new(); p.move_to(0.0, 0.0); p.cubic_to(0.0, 1.0, 1.0, 1.0, 1.0, 0.0); assert(p.len() == 2);Closes the current subpath.
nabilet p = plot::Path::new(); p.move_to(0.0, 0.0); p.close(); assert(p.len() == 2);An axis-aligned rectangle, clockwise on screen.
nabiassert(plot::Path::rect(1.0, 2.0, 3.0, 4.0).bounds() == (1.0, 2.0, 4.0, 6.0));Adds a rectangle subpath.
nabilet p = plot::Path::new(); p.add_rect(0.0, 0.0, 1.0, 1.0); p.add_rect(2.0, 0.0, 1.0, 1.0); assert(p.len() == 10);A circle of four cubic arcs.
nabiassert(plot::Path::circle(0.0, 0.0, 2.0).bounds() == (-2.0, -2.0, 2.0, 2.0));Adds a circle subpath, clockwise on screen.
nabilet p = plot::Path::new(); p.add_circle(5.0, 5.0, 1.0); assert(p.len() == 6);Adds a closed polygon through the points.
nabilet p = plot::Path::new(); p.add_polygon([0.0, 1.0, 0.0], [0.0, 0.0, 1.0]); assert(p.len() == 4);An open polyline through the points; a NaN breaks it into pieces.
nabiassert(plot::Path::polyline([0.0, 1.0, f64::NAN, 3.0], [0.0, 1.0, 2.0, 3.0]).len() == 3);The path moved by
(dx, dy)after scaling by(sx, sy)and rotating bydegdegrees clockwise on screen around the origin.nabilet p = plot::Path::rect(0.0, 0.0, 1.0, 1.0).transformed(2.0, 2.0, 0.0, 10.0, 0.0); assert(p.bounds() == (10.0, 0.0, 12.0, 2.0));Appends every command of
o.nabilet p = plot::Path::rect(0.0, 0.0, 1.0, 1.0); p.extend(plot::Path::circle(3.0, 3.0, 1.0)); assert(p.len() == 11);(min x, min y, max x, max y) of the points, controls included.
nabiassert(plot::Path::rect(-1.0, 0.0, 2.0, 1.0).bounds().0 == -1.0);