Skip to main content

Path

Struct Path 

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

One subpath: an ordered run of Commands with a cached current point.

Every *_to constructor is absolute; every *_by constructor is relative to the current point and resolves to the identical absolute command, so a path built either way compares equal.

Implementations§

Source§

impl Path

Source

pub fn new() -> Self

An empty path.

Source

pub fn starting_at(x: f32, y: f32) -> Self

A path holding a single MoveTo — the usual first call.

Source

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

The commands, in order.

Source

pub fn len(&self) -> usize

Number of commands.

Source

pub fn is_empty(&self) -> bool

True when the path holds no commands.

Source

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

The current point: the end of the last on-curve command, the subpath start after a Close, or (0, 0) for an empty path.

Source

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

The start of the current subpath.

Source

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

Absolute MoveTo, starting a new subpath.

Source

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

Relative MoveTo.

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.

Source

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

Absolute QuadTo.

Source

pub fn quad_by(&mut self, dcx: f32, dcy: f32, dx: f32, dy: f32) -> &mut Self

Relative QuadTo: control point and endpoint both relative to the current point.

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 cubic_by( &mut self, dc1x: f32, dc1y: f32, dc2x: f32, dc2y: f32, dx: f32, dy: f32, ) -> &mut Self

Relative CubicTo: both control points and the endpoint relative to the current point.

Source

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

Close: append the explicit Close command and reset the current point to the subpath start.

Source

pub fn open(&mut self) -> Option<Command>

Drop the trailing Close, leaving the subpath open. None when the path was not closed.

Source

pub fn truncate(&mut self, len: usize) -> Option<()>

Truncate to len commands. None when len exceeds the length.

The cached current point and subpath start are recomputed, so the path stays internally consistent.

Source

pub fn push(&mut self, cmd: Command) -> &mut Self

Append a raw command, keeping the cached current point in step.

Source

pub fn is_closed(&self) -> bool

True when the path ends with an explicit Close.

Source

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

Close the path unless it is empty or already closed. Idempotent.

Source

pub fn bbox(&self) -> Option<Bbox>

Exact bounding box: line endpoints plus the true interior extrema of every quadratic and cubic. None for a path with no points.

use font_model::Path;

// A cubic from (0,0) through controls (3,0) (3,3) to (0,3): the exact
// box reaches well inside the control hull's x = 3.
let mut p = Path::starting_at(0.0, 0.0);
p.cubic_to(3.0, 0.0, 3.0, 3.0, 0.0, 3.0);
p.close();
let b = p.bbox().expect("non-empty");
assert!(b.max_x() < 3.0);

// The known extreme of this cubic: x peaks at 2.25.
assert!((b.max_x() - 2.25).abs() < 1e-5, "max_x {}", b.max_x());
Source

pub fn signed_area(&self) -> f32

Signed area of the path in square font units, treating every subpath as closed. Curves contribute their exact analytic integral, so this is not a flattened approximation.

Source

pub fn area(&self) -> f32

Unsigned area.

Source

pub fn winding(&self) -> Winding

Orientation by signed-area sign.

Source

pub fn reverse(&mut self)

Reverse the direction of every subpath, keeping the same geometry. The way to normalise a mixed-direction contour set.

Source

pub fn points(&self) -> Vec<(f32, f32)>

Every on-curve and control point, in command order.

Source

pub fn subpaths(&self) -> Vec<Subpath>

The path split into its subpaths, each with its on-curve points and segments in order. Each subpath’s point list repeats its start at the end when closed.

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.