Skip to main content

Path

Struct Path 

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

A vector path: a sequence of PathVerb. Built in builder style (chainable), and consumed at render time.

use frus_core::{Path, Point};
let triangle = Path::new()
    .move_to(Point::new(0.0, 0.0))
    .line_to(Point::new(10.0, 0.0))
    .line_to(Point::new(5.0, 8.0))
    .close();
assert_eq!(triangle.verbs().len(), 4);

Implementations§

Source§

impl Path

Source

pub fn new() -> Self

An empty path.

Source

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

Starts a sub-path at p.

Source

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

A straight segment to p.

Source

pub fn quad_to(self, ctrl: Point, to: Point) -> Self

A quadratic curve (one control point, ctrl) to to.

Source

pub fn cubic_to(self, c1: Point, c2: Point, to: Point) -> Self

A cubic curve (two control points, c1 and c2) to to.

Source

pub fn close(self) -> Self

Closes the current sub-path.

Source

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

The path’s commands, in order.

Source

pub fn is_empty(&self) -> bool

true when the path holds no commands at all.

Source

pub fn rect(r: Rect) -> Self

A filled rectangle (a closed outline, clockwise).

Source

pub fn arc_to(self, center: Point, radius: f32, start: f32, end: f32) -> Self

Continues the path along a circular arc, from start to end (radians, measured from the positive x axis, y downwards), around center.

The current point is assumed to be the arc’s start; nothing moves it there, because an arc that jumped to its own beginning could not be part of an outline. Approximated by cubics, split so that no piece spans more than a quarter turn — which is where the constant used by Path::circle stops being accurate enough.

Source

pub fn circle(center: Point, radius: f32) -> Self

A circle, approximated by four cubic arcs (the Bézier constant 0.5523, which is exact at the nodes).

Source

pub fn oval(r: Rect) -> Self

An ellipse inscribed in r, by the same four-cubic approximation as Path::circle — which it generalises: a square r gives that circle back.

A circle scaled along one axis, in other words, without needing a transform to say so: it is how a wide, shallow arc (an overscroll glow, a soft highlight) is drawn as a plain filled path.

Source

pub fn scaled(&self, factor: f32) -> Path

A copy scaled by factor about the origin — used for logical-to-physical conversion, or to fit a 24×24 icon to its real size.

Source

pub fn translated(&self, dx: f32, dy: f32) -> Path

A copy translated by (dx, dy) — used to place an icon inside its box.

Source

pub fn mirrored_x(&self, axis: f32) -> Path

A copy reflected in the vertical line x = axis — how an icon that carries a direction (an arrow, an indent, a reply) is turned round for a right-to-left reading order.

The reflection reverses each contour’s winding, and reverses every contour, so a shape’s holes stay holes: the non-zero rule cares about the relative direction of the contours, not about their absolute one.

Source

pub fn rotated(&self, center: Point, radians: f32) -> Path

A copy turned by radians about center, clockwise — y points down here, so a positive angle turns the way a clock’s hand does.

Unlike a reflection, a rotation keeps each contour’s winding, so a shape’s holes stay holes without anything else being done about it. Bézier control points turn with their curve, which is exact: an affine map of a Bézier’s control polygon is the same Bézier mapped.

The sine and cosine are taken once for the whole path rather than per point.

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