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
impl PathBuilder
pub fn new() -> Self
Sourcepub fn rule(self, rule: FillRule) -> Self
pub fn rule(self, rule: FillRule) -> Self
Which points count as inside where contours overlap (default FillRule::NonZero).
pub fn line_to(self, p: Point) -> Self
Sourcepub fn quad_to(self, c: Point, p: Point) -> Self
pub fn quad_to(self, c: Point, p: Point) -> Self
Quadratic bezier through control point c to p.
Sourcepub fn cubic_to(self, c1: Point, c2: Point, p: Point) -> Self
pub fn cubic_to(self, c1: Point, c2: Point, p: Point) -> Self
Cubic bezier with control points c1, c2 to p.
Sourcepub fn arc_to(
self,
center: Point,
radius: f64,
start_deg: f64,
sweep_deg: f64,
) -> Self
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.
pub fn circle(self, center: Point, radius: f64) -> Self
Sourcepub fn smooth_polyline(self, pts: &[Point], tension: f64) -> Self
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.
Sourcepub fn rounded_rect(self, rect: Rect, radii: CornerRadii) -> Self
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).
Trait Implementations§
Source§impl Clone for PathBuilder
impl Clone for PathBuilder
Source§fn clone(&self) -> PathBuilder
fn clone(&self) -> PathBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PathBuilder
impl Debug for PathBuilder
Source§impl Default for PathBuilder
impl Default for PathBuilder
Source§fn default() -> PathBuilder
fn default() -> PathBuilder
Auto Trait Implementations§
impl Freeze for PathBuilder
impl RefUnwindSafe for PathBuilder
impl Send for PathBuilder
impl Sync for PathBuilder
impl Unpin for PathBuilder
impl UnsafeUnpin for PathBuilder
impl UnwindSafe for PathBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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