Skip to main content

PathShape

Struct PathShape 

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

A parsed, normalized, resampled closed contour.

The points are the contour itself: samples of them, evenly spaced by arc length around the outline and not repeating the first at the end — the closing edge from the last point back to the first is implicit, and both the distance field and the arc-length walk here assume it.

Implementations§

Source§

impl PathShape

Source

pub fn parse(d: &str, samples: usize) -> Result<Self, PathError>

Parse inline SVG path data into a normalized contour of samples points.

samples is trusted to be in MIN_SAMPLES..=MAX_SAMPLES; the [path] table checks it at the load boundary, which is where a range belongs.

Source

pub fn points(&self) -> &[[f32; 2]]

The contour’s points, normalized into [-1, 1] on its longer axis.

Source

pub fn source_center(&self) -> [f32; 2]

The centre of the source drawing’s bounding box, in the source’s own units — the translation the normalization applied, recorded.

Source

pub fn source_scale(&self) -> f32

The factor the source drawing was scaled by — the reciprocal of half its longer bounding-box axis, recorded.

Source

pub fn signed_area(&self) -> f32

Twice the shoelace sum: positive when the contour winds counter-clockwise in a y-up frame, negative when it winds clockwise.

The stored contour is in that frame — parse negates SVG’s downward y — so this sign is the winding an author sees on screen, and a d string that reads clockwise in a browser reports negative here.

The sign is what a morph pair has to agree on (ADR-0107) — a clockwise contour interpolating into a counter-clockwise one turns inside out through the middle, passing through zero area on the way.

Source

pub fn aligned_to(&self, from: &Self) -> Option<Self>

This contour re-expressed so that interpolating toward it from from is a morph rather than a scramble (ADR-0107).

The two alignment problems ADR-0107 says have answers, solved in the order they have to be:

  1. Winding, by signed area. A clockwise contour interpolating into a counter-clockwise one turns inside out through the middle — every intermediate frame is a valid shape and the motion is wrong — and the contour passes through zero enclosed area on the way. When the two signs disagree, the target is walked backwards.
  2. Start point, by minimising total displacement over cyclic offsets. Without it a star morphing into a star can unwind through a spiral: each point travels to a correspondent rather than to its neighbour, and every intermediate frame is again valid. O(N^2) at load, which at this arity is thousands of operations, so the brute-force search is affordable and no cleverness is owed.

The third — two paths with different subpath counts — has no answer, and is refused at the parser rather than guessed at here.

Both contours must already carry the same number of points; None if they do not, which the load boundary prevents by parsing the pair at one arity.

Source

pub fn piece_count(&self) -> usize

How many arc pieces the fit kept — 0 where the figure stays a polyline.

The count rather than the chain, so a caller outside the crate can report what a curve cost without biarc::Piece being public API.

Source

pub fn resampled(&self, samples: usize) -> Option<Self>

This contour resampled to samples points, evenly spaced by arc length from its own first point. None when the contour or the request is degenerate.

Trait Implementations§

Source§

impl Clone for PathShape

Source§

fn clone(&self) -> PathShape

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 PathShape

Source§

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

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

impl PartialEq for PathShape

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PathShape

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,