Skip to main content

PathBuilder

Struct PathBuilder 

Source
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

Source

pub const DEFAULT_CAP: LineCap = LineCap::Butt

The default cap for a stroke.

Source

pub const DEFAULT_JOIN: LineJoin = LineJoin::Miter

The default join for a stroke.

Source

pub fn new() -> Self

A builder with an empty path and an identity transform.

Source

pub fn from_path(path: &Path2D) -> Self

A builder that starts from an existing path.

Source

pub const fn current_transform(&self) -> Affine2D

The transform in force right now.

Source

pub fn depth(&self) -> usize

How many transforms are stacked.

Source

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.

Source

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.

Source

pub fn reset_transforms(&mut self) -> &mut Self

Discard every stacked transform and return to the identity.

Source

pub const fn current_point(&self) -> (f32, f32)

The current point in device space.

Source

pub fn move_to(&mut self, x: f32, y: f32) -> &mut Self

Absolute MoveTo.

Source

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.

Source

pub fn line_to(&mut self, x: f32, y: f32) -> &mut Self

Absolute LineTo.

Source

pub fn line_by(&mut self, dx: f32, dy: f32) -> &mut Self

Relative LineTo, in device space, like move_by.

Source

pub fn quad_to(&mut self, cx: f32, cy: f32, x: f32, y: f32) -> &mut Self

Absolute QuadTo.

Source

pub fn cubic_to( &mut self, c1x: f32, c1y: f32, c2x: f32, c2y: f32, x: f32, y: f32, ) -> &mut Self

Absolute CubicTo.

Source

pub fn close(&mut self) -> &mut Self

Close the current subpath.

Source

pub fn add_polygon(&mut self, points: &[(f32, f32)], closed: bool) -> &mut Self

Add a whole subpath from a point list, closed.

Source

pub fn rect(&mut self, x: f32, y: f32, w: f32, h: f32) -> &mut Self

Add an axis-aligned rectangle as a closed subpath.

Source

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.

Source

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.

Source

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.

Source

pub fn commands(&self) -> &[PathCommand]

The commands accumulated so far.

Source

pub fn len(&self) -> usize

Number of commands.

Source

pub fn is_empty(&self) -> bool

True when nothing has been added.

Source

pub fn build(&self) -> Path2D

Take the accumulated commands as a path, leaving the builder empty but keeping its transform stack.

Trait Implementations§

Source§

impl Clone for PathBuilder

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PathBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PathBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.