Skip to main content

PathBuilder

Struct PathBuilder 

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

Ergonomic builder for Path implementing the PDF path construction operators (m, l, c, h) with the same state-machine semantics as SplashPath::moveTo / lineTo / curveTo / close.

Implementations§

Source§

impl PathBuilder

Source

pub fn new() -> Self

Create a new, empty builder with no current point.

Source

pub fn move_to(&mut self, x: f64, y: f64) -> Result<(), PathError>

Begin a new subpath at (x, y). Equivalent to the PDF m operator.

§Errors

Returns PathError::BogusPath if a one-point subpath is already active (i.e. the previous operation was also a move_to with no drawing operator in between). Callers must not silently ignore this error: it indicates a malformed path construction sequence.

Source

pub fn line_to(&mut self, x: f64, y: f64) -> Result<(), PathError>

Add a line segment from the current point to (x, y).

Equivalent to the PDF l operator.

§Errors

Returns PathError::NoCurPt if there is no current point. Callers must ensure a successful Self::move_to precedes this call.

§Panics

Panics if flags is empty despite a current point existing, which would indicate a broken Path invariant (pts.len() == flags.len()).

Source

pub fn curve_to( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64, ) -> Result<(), PathError>

Add a cubic Bezier curve. Equivalent to the PDF c operator.

(x1, y1) and (x2, y2) are the two off-curve control points; (x3, y3) is the on-curve endpoint. Three points are always appended: the control points receive PathFlags::CURVE and the endpoint receives PathFlags::LAST.

§Errors

Returns PathError::NoCurPt if there is no current point. Callers must ensure a successful Self::move_to precedes this call.

§Panics

Panics if flags is empty despite a current point existing, which would indicate a broken Path invariant (pts.len() == flags.len()).

Source

pub fn close(&mut self, force: bool) -> Result<(), PathError>

Close the current subpath. Equivalent to the PDF h operator.

Behaviour:

  • If force is true, a closing lineTo(first) is always appended.
  • If sp == last_idx the subpath consists of exactly one point (the moveTo with no drawing operators). In this degenerate case the subpath is trivially “closed” (first == last by identity), so no extra lineTo is needed — the single point has PathFlags::CLOSED set on itself. This matches the C++ SplashPath::close behaviour.
  • Otherwise, a closing lineTo(first) is appended only when first != last (the path is not already closed geometrically).

After closing, cur_subpath is advanced to pts.len() (the “no current point” sentinel), so Path::current_point returns None until the next move_to.

§Errors

Returns PathError::NoCurPt if there is no current point. The ? inside this method propagates any error from the internal line_to call; since line_to only errors on NoCurPt and we have already verified a current point exists at entry, that propagation path is only reachable if an invariant is broken.

Source

pub fn add_stroke_adjust_hint( &mut self, ctrl0: usize, ctrl1: usize, first_pt: usize, last_pt: usize, )

Add a stroke-adjust hint referencing existing point indices.

Indices refer to positions in Path::pts at build time.

Source

pub fn cur_pt(&self) -> Option<PathPoint>

Returns the current point (last appended endpoint), if any.

Returns None when there is no current point — i.e. on a freshly created builder or immediately after a successful Self::close. Delegates to Path::current_point.

Source

pub const fn pts_len(&self) -> usize

Returns the number of points accumulated in the builder so far.

This is a read-only view used by callers that need to record point indices for stroke-adjustment hints (e.g. raster::stroke::make_stroke_path).

Source

pub fn offset(&mut self, dx: f64, dy: f64)

Translate every point accumulated so far by (dx, dy).

Source

pub fn build(self) -> Path

Consume the builder and return the completed Path.

Trait Implementations§

Source§

impl Default for PathBuilder

Source§

fn default() -> Self

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

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