[−][src]Trait kurbo::Shape
A generic trait for open and closed shapes.
Associated Types
type BezPathIter: Iterator<Item = PathEl>
The iterator resulting from to_bez_path
.
Required methods
fn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter
Convert to a Bézier path, as an iterator over path elements.
Callers should exhaust the as_
methods first, as those are
likely to be more efficient; in the general case, this
allocates.
TODO: When GAT's land, the type of this can be changed to
contain a &'a self
reference, which would let us take
iterators from complex shapes without cloning.
fn area(&self) -> f64
Signed area.
This method only produces meaningful results with closed shapes.
TODO: figure out sign convention, see #4.
fn perimeter(&self, accuracy: f64) -> f64
Total length of perimeter.
fn winding(&self, pt: Vec2) -> i32
Winding number of point.
This method only produces meaningful results with closed shapes.
TODO: figure out sign convention, see #4.
fn bounding_box(&self) -> Rect
The smallest rectangle that encloses the shape.
Provided methods
fn into_bez_path(self, tolerance: f64) -> BezPath
fn as_line(&self) -> Option<Line>
If the shape is a line, make it available.
fn as_rect(&self) -> Option<Rect>
If the shape is a rectangle, make it available.
fn as_circle(&self) -> Option<Circle>
If the shape is a circle, make it available.
fn as_path_slice(&self) -> Option<&[PathEl]>
If the shape is stored as a slice of path elements, make that available.
Note: when GAT's land, a method like to_bez_path
would be
able to iterate through the slice with no extra allocation,
without making any assumption that storage is contiguous.
Implementations on Foreign Types
impl<'a> Shape for &'a [PathEl]
[src]
type BezPathIter = Cloned<Iter<'a, PathEl>>
fn to_bez_path(&self, _tolerance: f64) -> Self::BezPathIter
[src]
fn area(&self) -> f64
[src]
Signed area.
TODO: figure out sign convention, see #4.
fn perimeter(&self, accuracy: f64) -> f64
[src]
fn winding(&self, pt: Vec2) -> i32
[src]
Winding number of point.
TODO: figure out sign convention, see #4.
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_circle(&self) -> Option<Circle>
[src]
impl<'a, T: Shape> Shape for &'a T
[src]
Blanket implementation so impl Shape
will accept owned or reference.
type BezPathIter = T::BezPathIter
fn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter
[src]
fn area(&self) -> f64
[src]
fn perimeter(&self, accuracy: f64) -> f64
[src]
fn winding(&self, pt: Vec2) -> i32
[src]
fn bounding_box(&self) -> Rect
[src]
fn as_line(&self) -> Option<Line>
[src]
fn as_rect(&self) -> Option<Rect>
[src]
fn as_path_slice(&self) -> Option<&[PathEl]>
[src]
fn into_bez_path(self, tolerance: f64) -> BezPath
[src]
fn as_circle(&self) -> Option<Circle>
[src]
Implementors
impl Shape for BezPath
[src]
type BezPathIter = IntoIter<PathEl>
fn to_bez_path(&self, _tolerance: f64) -> Self::BezPathIter
[src]
fn area(&self) -> f64
[src]
Signed area.
TODO: figure out sign convention, see #4.
fn perimeter(&self, accuracy: f64) -> f64
[src]
fn winding(&self, pt: Vec2) -> i32
[src]
Winding number of point.
TODO: figure out sign convention, see #4.
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_circle(&self) -> Option<Circle>
[src]
impl Shape for Circle
[src]
type BezPathIter = CirclePathIter
fn to_bez_path(&self, tolerance: f64) -> CirclePathIter
[src]
fn area(&self) -> f64
[src]
fn perimeter(&self, _accuracy: f64) -> f64
[src]
fn winding(&self, pt: Vec2) -> i32
[src]
fn bounding_box(&self) -> Rect
[src]
fn as_circle(&self) -> Option<Circle>
[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_path_slice(&self) -> Option<&[PathEl]>
[src]
impl Shape for Line
[src]
type BezPathIter = LinePathIter
ⓘImportant traits for LinePathIterfn to_bez_path(&self, _tolerance: f64) -> LinePathIter
[src]
fn area(&self) -> f64
[src]
Returning zero here is consistent with the contract (area is only meaningful for closed shapes), but an argument can be made that the contract should be tightened to include the Green's theorem contribution.
fn perimeter(&self, _accuracy: f64) -> f64
[src]
fn winding(&self, _pt: Vec2) -> i32
[src]
Same consideration as area
.
fn bounding_box(&self) -> Rect
[src]
fn as_line(&self) -> Option<Line>
[src]
fn into_bez_path(self, tolerance: f64) -> BezPath
[src]
fn as_rect(&self) -> Option<Rect>
[src]
fn as_circle(&self) -> Option<Circle>
[src]
fn as_path_slice(&self) -> Option<&[PathEl]>
[src]
impl Shape for Rect
[src]
type BezPathIter = RectPathIter
fn to_bez_path(&self, _tolerance: f64) -> RectPathIter
[src]
fn area(&self) -> f64
[src]
fn perimeter(&self, _accuracy: f64) -> f64
[src]
fn winding(&self, pt: Vec2) -> i32
[src]
Note: this function is carefully designed so that if the plane is tiled with rectangles, the winding number will be nonzero for exactly one of them.