pub struct PathBuilder { /* private fields */ }Expand description
Accumulates a Path2D through a transform stack.
The builder applies the current transform to every point as it is added, so the finished path is already in device space and the rasteriser needs no transform of its own.
Implementations§
Source§impl PathBuilder
impl PathBuilder
Sourcepub const DEFAULT_CAP: LineCap = LineCap::Butt
pub const DEFAULT_CAP: LineCap = LineCap::Butt
The default cap for a stroke.
Sourcepub const DEFAULT_JOIN: LineJoin = LineJoin::Miter
pub const DEFAULT_JOIN: LineJoin = LineJoin::Miter
The default join for a stroke.
Sourcepub const fn current_transform(&self) -> Affine2D
pub const fn current_transform(&self) -> Affine2D
The transform in force right now.
Sourcepub fn push_transform(&mut self, m: Affine2D) -> &mut Self
pub fn push_transform(&mut self, m: Affine2D) -> &mut Self
Compose a transform onto the current one.
push_transform(&m) then a point p gives m.transform_point(p)
composed with everything already stacked.
Sourcepub fn pop_transform(&mut self) -> Result<Affine2D, ShapeError>
pub fn pop_transform(&mut self) -> Result<Affine2D, ShapeError>
Restore the transform beneath the top of the stack.
§Errors
ShapeError::UnbalancedPop when the stack is empty. Returning the
identity instead would silently discard a transform, which is worse
than refusing.
Sourcepub fn reset_transforms(&mut self) -> &mut Self
pub fn reset_transforms(&mut self) -> &mut Self
Discard every stacked transform and return to the identity.
Sourcepub const fn current_point(&self) -> (f32, f32)
pub const fn current_point(&self) -> (f32, f32)
The current point in device space.
Sourcepub fn move_by(&mut self, dx: f32, dy: f32) -> &mut Self
pub fn move_by(&mut self, dx: f32, dy: f32) -> &mut Self
Relative MoveTo, in device space.
The offset goes through the transform’s linear part only, so the relative helpers compose with whatever transform stack is in force: a caller walking the finished path in device coordinates gets device deltas back.
Sourcepub fn line_by(&mut self, dx: f32, dy: f32) -> &mut Self
pub fn line_by(&mut self, dx: f32, dy: f32) -> &mut Self
Relative LineTo, in device space, like move_by.
Sourcepub fn cubic_to(
&mut self,
c1x: f32,
c1y: f32,
c2x: f32,
c2y: f32,
x: f32,
y: f32,
) -> &mut Self
pub fn cubic_to( &mut self, c1x: f32, c1y: f32, c2x: f32, c2y: f32, x: f32, y: f32, ) -> &mut Self
Absolute CubicTo.
Sourcepub fn add_polygon(&mut self, points: &[(f32, f32)], closed: bool) -> &mut Self
pub fn add_polygon(&mut self, points: &[(f32, f32)], closed: bool) -> &mut Self
Add a whole subpath from a point list, closed.
Sourcepub fn rect(&mut self, x: f32, y: f32, w: f32, h: f32) -> &mut Self
pub fn rect(&mut self, x: f32, y: f32, w: f32, h: f32) -> &mut Self
Add an axis-aligned rectangle as a closed subpath.
Sourcepub fn circle(&mut self, cx: f32, cy: f32, r: f32) -> &mut Self
pub fn circle(&mut self, cx: f32, cy: f32, r: f32) -> &mut Self
Add a circle as a closed subpath of four cubic arcs, each within
tolerance of the true curve.
Sourcepub fn extend(&mut self, path: &Path2D) -> &mut Self
pub fn extend(&mut self, path: &Path2D) -> &mut Self
Append an existing path’s commands, transformed by the current stack.
The commands arrive already in that path’s own space, so they go through the current transform like any other point.
Sourcepub fn add_stroke(
&mut self,
path: &Path2D,
width: f32,
style: StrokeStyle,
) -> &mut Self
pub fn add_stroke( &mut self, path: &Path2D, width: f32, style: StrokeStyle, ) -> &mut Self
Add a stroke’s expansion of path under the current transform.
Sourcepub fn commands(&self) -> &[PathCommand]
pub fn commands(&self) -> &[PathCommand]
The commands accumulated so far.