Skip to main content

Path

Struct Path 

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

A path: a verb stream plus the points those verbs consume.

Implementations§

Source§

impl Path

Source

pub fn builder() -> PathBuilder

Source

pub fn as_rounded_rect(&self) -> Option<(Rect, f32)>

The rounded rectangle this was built from, if it was built from one.

A radius of zero is a plain rectangle and is reported as such; None means only that nothing recorded a shape, never that the outline is not one.

Source

pub fn verbs(&self) -> &[Verb]

Source

pub fn points(&self) -> &[Vec2]

Source

pub fn is_finite(&self) -> bool

Whether every point in this path is a real location.

A path carrying a NaN or an infinity is not a shape. It arrives when a caller’s own arithmetic has already gone wrong – a division by a zero extent, an inverted degenerate transform – and there is no picture it asks for, so the tessellator refuses one rather than inventing it.

Worth having as a question rather than a debug assertion because lyon asserts on a non-finite coordinate, and an assertion in a dependency takes the process down. A library given a bad number should decline to draw, not abort the application holding it.

Source

pub fn is_within_tessellation_range(&self) -> bool

Whether every coordinate is small enough to tessellate.

Finite is not the same as usable, and the gap between them is where the tessellator’s cost stops being bounded. f32::MAX is finite; so is 1e15, and a path with three verbs at that magnitude strokes to thirty-one million vertices – six hundred megabytes of position and index from a cubic and a close. The fill route is safe from it because this crate’s own flattener caps at MAX_SEGMENTS, but a stroke hands its curves to lyon intact, deliberately and for the reason Tessellator::stroke gives, and lyon subdivides by its own arithmetic with no such cap. The output grows linearly in the coordinate, which makes it a caller-controlled allocation with nothing at the top of it.

MAX_COORDINATE is where that stops, and the limit is the same one two different arguments arrive at. A float past two to the twenty-fourth has an interval above one between it and its neighbor, so a coordinate there cannot name a pixel and no picture depends on it. And measured, a curve at that magnitude strokes to about twenty thousand vertices, which is a shape rather than an allocation.

Source

pub fn fill_rule(&self) -> FillRule

Source

pub fn is_empty(&self) -> bool

Source

pub fn bounds(&self) -> Rect

Bounds of the control points.

This is a bound, not a tight fit: a curve lies within the convex hull of its control points, so a curve that bends away from its handles reports a larger box than it occupies. That is the right trade for culling, where a conservative overestimate is safe and cheap while a tight fit costs a solve per curve.

Source

pub fn segments(&self) -> impl Iterator<Item = (Verb, &[Vec2])>

Walk the path as (verb, points) pairs.

Source

pub fn convexity(&self) -> Convexity

Whether the path is provably convex.

Answers Convexity::Concave for anything with more than one subpath, or containing curves, rather than analyzing further. Curved paths are classified after flattening, where the question is a polygon question.

Trait Implementations§

Source§

impl Clone for Path

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 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() -> Self

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

impl PartialEq for Path

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Path

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> 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.