[−][src]Struct kurbo::BezPath
A path that can Bézier segments up to cubic, possibly with multiple subpaths.
Implementations
impl BezPath
[src]
pub fn new() -> BezPath
[src]
Create a new path.
pub fn from_vec(v: Vec<PathEl>) -> BezPath
[src]
Create a path from a vector of path elements.
BezPath
also implements FromIterator<PathEl>
, so it works with collect
:
// a very contrived example: use kurbo::{BezPath, PathEl}; let path = BezPath::new(); let as_vec: Vec<PathEl> = path.into_iter().collect(); let back_to_path: BezPath = as_vec.into_iter().collect();
pub fn push(&mut self, el: PathEl)
[src]
Push a generic path element onto the path.
pub fn move_to<P: Into<Point>>(&mut self, p: P)
[src]
Push a "move to" element onto the path.
pub fn line_to<P: Into<Point>>(&mut self, p: P)
[src]
Push a "line to" element onto the path.
pub fn quad_to<P: Into<Point>>(&mut self, p1: P, p2: P)
[src]
Push a "quad to" element onto the path.
pub fn curve_to<P: Into<Point>>(&mut self, p1: P, p2: P, p3: P)
[src]
Push a "curve to" element onto the path.
pub fn close_path(&mut self)
[src]
Push a "close path" element onto the path.
pub fn elements(&self) -> &[PathEl]
[src]
Get the path elements.
pub fn iter(&self) -> impl Iterator<Item = PathEl> + '_
[src]
Returns an iterator over the path's elements.
pub fn segments(&self) -> impl Iterator<Item = PathSeg> + '_
[src]
Iterate over the path segments.
pub fn flatten(&self, tolerance: f64, callback: impl FnMut(PathEl))
[src]
Flatten the path, invoking the callback repeatedly.
Flattening is the action of approximating a curve with a succession of line segments.
The tolerance value controls the maximum distance between the curved input
segments and their polyline approximations. (In technical terms, this is the
Hausdorff distance). The algorithm attempts to bound this distance between
by tolerance
but this is not absolutely guaranteed. The appropriate value
depends on the use, but for antialiasted rendering, a value of 0.25 has been
determined to give good results. The number of segments tends to scale as the
inverse square root of tolerance.
The callback will be called in order with each element of the generated path. Because the result is made of polylines, these will be straight-line path elements only, no curves.
This algorithm is based on the blog post Flattening quadratic Béziers but with some refinements. For one, there is a more careful approximation at cusps. For two, the algorithm is extended to work with cubic Béziers as well, by first subdividing into quadratics and then computing the subdivision of each quadratic. However, as a clever trick, these quadratics are subdivided fractionally, and their endpoints are not included.
TODO: write a paper explaining this in more detail.
Note: the flatten
function provides the same
functionality but works with slices and other PathEl
iterators.
pub fn get_seg(&self, ix: usize) -> Option<PathSeg>
[src]
Get the segment at the given element index.
The element index counts PathEl
elements, so
for example includes an initial Moveto
.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the path contains no segments.
pub fn apply_affine(&mut self, affine: Affine)
[src]
Apply an affine transform to the path.
pub fn nearest(&self, p: Point, accuracy: f64) -> (usize, f64, f64)
[src]
Find the nearest point.
Panics if path is empty or invalid.
Note that the returned index counts segments, not elements. Thus, the
initial Moveto
is not counted. For a simple path consisting of a Moveto
followed by Lineto/Quadto/Cubicto
elements, the element index is the
segment index + 1.
Returns the index of the segment, the parameter within that segment, and the square of the distance to the point.
impl BezPath
[src]
pub fn from_path_segments(segments: impl Iterator<Item = PathSeg>) -> BezPath
[src]
Create a BezPath with segments corresponding to the sequence of
PathSeg
s
pub fn to_svg(&self) -> String
[src]
Convert the path to an SVG path string representation.
The current implementation doesn't take any special care to produce a short string (reducing precision, using relative movement).
pub fn write_to<W: Write>(&self, writer: W) -> Result<()>
[src]
Write the SVG representation of this path to the provided buffer.
pub fn from_svg(data: &str) -> Result<BezPath, SvgParseError>
[src]
Try to parse a bezier path from an SVG path element.
This is implemented on a best-effort basis, intended for cases where the user controls the source of paths, and is not intended as a replacement for a general, robust SVG parser.
Trait Implementations
impl Clone for BezPath
[src]
impl Debug for BezPath
[src]
impl Default for BezPath
[src]
impl<'de> Deserialize<'de> for BezPath
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Extend<PathEl> for BezPath
[src]
fn extend<I: IntoIterator<Item = PathEl>>(&mut self, iter: I)
[src]
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl FromIterator<PathEl> for BezPath
[src]
fn from_iter<T: IntoIterator<Item = PathEl>>(iter: T) -> Self
[src]
impl<'a> IntoIterator for &'a BezPath
[src]
Allow iteration over references to BezPath
.
Note: the semantics are slightly different than simply iterating over the
slice, as it returns PathEl
items, rather than references.
type Item = PathEl
The type of the elements being iterated over.
type IntoIter = Cloned<Iter<'a, PathEl>>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl IntoIterator for BezPath
[src]
type Item = PathEl
The type of the elements being iterated over.
type IntoIter = IntoIter<PathEl>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a> Mul<&'a BezPath> for Affine
[src]
type Output = BezPath
The resulting type after applying the *
operator.
fn mul(self, other: &BezPath) -> BezPath
[src]
impl<'a> Mul<&'a BezPath> for TranslateScale
[src]
type Output = BezPath
The resulting type after applying the *
operator.
fn mul(self, other: &BezPath) -> BezPath
[src]
impl Mul<BezPath> for Affine
[src]
type Output = BezPath
The resulting type after applying the *
operator.
fn mul(self, other: BezPath) -> BezPath
[src]
impl Mul<BezPath> for TranslateScale
[src]
type Output = BezPath
The resulting type after applying the *
operator.
fn mul(self, other: BezPath) -> BezPath
[src]
impl Serialize for BezPath
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl Shape for BezPath
[src]
type BezPathIter = IntoIter<PathEl>
The iterator resulting from to_bez_path
.
fn to_bez_path(&self, _tolerance: f64) -> Self::BezPathIter
[src]
fn area(&self) -> f64
[src]
Signed area.
fn perimeter(&self, accuracy: f64) -> f64
[src]
fn winding(&self, pt: Point) -> i32
[src]
Winding number of point.
fn bounding_box(&self) -> Rect
[src]
fn as_path_slice(&self) -> Option<&[PathEl]>
[src]
fn into_bez_path(self, tolerance: f64) -> BezPath
[src]
fn as_line(&self) -> Option<Line>
[src]
fn as_rect(&self) -> Option<Rect>
[src]
fn as_rounded_rect(&self) -> Option<RoundedRect>
[src]
fn as_circle(&self) -> Option<Circle>
[src]
Auto Trait Implementations
impl RefUnwindSafe for BezPath
impl Send for BezPath
impl Sync for BezPath
impl Unpin for BezPath
impl UnwindSafe for BezPath
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,