Skip to main content

PathBuilder

Struct PathBuilder 

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

Build a Shape::Path: several contours, straight or curved, with a fill rule.

ⓘ
let ring = PathBuilder::new()
    .rule(FillRule::EvenOdd)          // the inner circle cuts a hole
    .circle(center, 40.0)
    .circle(center, 24.0)
    .build();
d.fill(ring, Color::BLUE);

Implementations§

Source§

impl PathBuilder

Source

pub fn new() -> Self

Source

pub fn rule(self, rule: FillRule) -> Self

Which points count as inside where contours overlap (default FillRule::NonZero).

Source

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

Start a new contour.

Source

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

Source

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

Quadratic bezier through control point c to p.

Source

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

Cubic bezier with control points c1, c2 to p.

Source

pub fn close(self) -> Self

Close the current contour back to its start.

Source

pub fn arc_to( self, center: Point, radius: f64, start_deg: f64, sweep_deg: f64, ) -> Self

A whole circular contour, as four cubics.

0.5523 is the standard circle-from-beziers constant (4/3·tan(π/8)); the error against a true circle is under a thousandth of the radius, which is well inside a pixel at any size a UI draws. Append a circular arc: sweep_deg of a circle of radius about center, starting at start_deg. Degrees, 0 = the +x axis, positive sweeping clockwise, the same convention Shape::Arc and PathBuilder::circle already use, so the crate has one.

A segment, not a shape: the arc joins whatever came before it, which is what lets a donut wedge, a rounded gauge or a pie slice with a hole be one closed path. Without it every such figure is hand-rolled from cubics; day-piece-charts carried forty lines of exactly this to draw a wedge.

Emitted as cubics rather than as an arc op on the wire. Every rasterizer under Day has its own rule for joining an arc to the line before it, and its own flattening tolerance; the same beziers everywhere means the same pixels everywhere.

A cubic cannot be a circle, so this is an approximation, and the quarter turns it splits into are where that is cheapest: the radial error of a cubic quarter-circle peaks at 2.7 × 10⁻⁴ of the radius, a quarter of a pixel on a circle a thousand points across, and proportionally less on anything smaller. Splitting finer would halve nothing anyone can see and double the segment count. It is the same tradeoff Core Graphics, cairo and every SVG renderer make.

Continues the current subpath when there is one, and starts a new one otherwise.

Source

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

Source

pub fn smooth_polyline(self, pts: &[Point], tension: f64) -> Self

A contour through pts as a Catmull-Rom spline converted to cubics: the smooth line a chart wants through its data points, without the caller doing bezier arithmetic.

The curve passes through every point (unlike a plain bezier fit), and the tangent at each point follows its neighbors. tension 0.0 is a straight polyline and 1.0 is the standard Catmull-Rom; values above about 1.2 overshoot visibly.

Source

pub fn rounded_rect(self, rect: Rect, radii: CornerRadii) -> Self

Append a rectangle with its own radius on each corner, as one closed contour: the path Shape::rounded_rect draws when its corners differ, for a figure that needs it as one contour among several (a rounded frame with a hole cut out of it).

Source

pub fn build(self) -> Shape

Finish, as a Shape ready for fill, stroke or clip.

Trait Implementations§

Source§

impl Clone for PathBuilder

Source§

fn clone(&self) -> PathBuilder

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 PathBuilder

Source§

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

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

impl Default for PathBuilder

Source§

fn default() -> PathBuilder

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

impl<T> ErasedDestructor for T
where T: 'static,

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> IntoReactive<T, StaticMark> for T
where T: Clone + 'static,

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.
Day API ↩ Guides· daybrite.dev