Skip to main content

Path

Struct Path 

Source
pub struct Path { /* private fields */ }
Expand description

A 2-D path storing a sequence of draw commands.

Use PathBuilder (or the inherent builder methods) to populate a path, then call Path::fill or Path::stroke to rasterise it.

Implementations§

Source§

impl Path

Source

pub fn new() -> Self

Create an empty path with the default (non-zero) fill rule.

Source

pub fn with_fill_rule(self, rule: FillRule) -> Self

Set the fill rule (consumes and returns self for chaining).

Source

pub fn move_to(&mut self, p: Point) -> &mut Self

Move the current point to p without drawing.

Source

pub fn line_to(&mut self, p: Point) -> &mut Self

Add a straight line from the current point to p.

Source

pub fn quad_to(&mut self, ctrl: Point, end: Point) -> &mut Self

Add a quadratic Bézier curve with control point ctrl ending at end.

Source

pub fn cubic_to(&mut self, c1: Point, c2: Point, end: Point) -> &mut Self

Add a cubic Bézier curve with control points c1/c2 ending at end.

Source

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

Close the current sub-path (draw a line back to the last MoveTo).

Source

pub fn flatten(&self, tolerance: f32) -> Vec<Vec<Point>>

Flatten all sub-paths to sequences of line vertices.

Returns one Vec<Point> per sub-path (contour). The last point of each contour is not duplicated at the start; callers should treat the contour as closed (connect last → first).

tolerance is the maximum chord-distance deviation allowed per Bézier segment (in pixels). A value of 0.25 gives visually smooth curves.

Source

pub fn fill(&self, fb: &mut Framebuffer, color: Color)

Fill this path’s interior into fb using the configured fill rule.

A single Rasterizer is created for the duration of this call so that scratch buffers are reused across all contours of the path.

Source

pub fn stroke(&self, fb: &mut Framebuffer, style: &StrokeStyle, color: Color)

Stroke this path into fb using the given style.

Each sub-path is stroked independently; closed sub-paths produce closed outlines (the cap style is ignored for closed paths).

A single Rasterizer is created for the duration of this call so that scratch buffers are reused across all contours.

Source

pub fn fill_clipped(&self, fb: &mut Framebuffer, color: Color, clip: ClipRect)

Fill this path’s interior, clipped to clip.

Uses fill_polygon_clipped so pixels outside clip are never written. Anti-aliasing is enabled by default.

Source

pub fn stroke_clipped( &self, fb: &mut Framebuffer, style: &StrokeStyle, color: Color, clip: ClipRect, )

Stroke this path, clipped to clip.

Constructs the stroke polygon and fills it using fill_polygon_clipped.

Source

pub fn fill_clipped_aa( &self, fb: &mut Framebuffer, color: Color, clip: ClipRect, aa: bool, )

Fill this path’s interior, clipped to clip, with explicit AA control.

When aa is false, edges are aliased (faster; no coverage blending).

A single Rasterizer is created for the duration of this call so that scratch buffers are reused across all contours.

Source

pub fn stroke_clipped_aa( &self, fb: &mut Framebuffer, style: &StrokeStyle, color: Color, clip: ClipRect, aa: bool, )

Stroke this path, clipped to clip, with explicit AA control.

When aa is false, the stroke polygon edges are aliased.

A single Rasterizer is created for the duration of this call so that scratch buffers are reused across all contours.

Trait Implementations§

Source§

impl Clone for Path

Source§

fn clone(&self) -> Path

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 Path

Source§

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

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

impl Default for Path

Source§

fn default() -> Path

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

Auto Trait Implementations§

§

impl Freeze for Path

§

impl RefUnwindSafe for Path

§

impl Send for Path

§

impl Sync for Path

§

impl Unpin for Path

§

impl UnsafeUnpin for Path

§

impl UnwindSafe for Path

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.