pub trait Shape: Sized {
type BezPathIter: Iterator<Item = PathEl>;
fn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter;
fn area(&self) -> f64;
fn perimeter(&self, accuracy: f64) -> f64;
fn winding(&self, pt: Vec2) -> i32;
fn bounding_box(&self) -> Rect;
fn into_bez_path(self, tolerance: f64) -> BezPath { ... }
fn as_line(&self) -> Option<Line> { ... }
fn as_rect(&self) -> Option<Rect> { ... }
fn as_path_slice(&self) -> Option<&[PathEl]> { ... }
}
Expand description
A generic trait for open and closed shapes.
Required Associated Types§
sourcetype BezPathIter: Iterator<Item = PathEl>
type BezPathIter: Iterator<Item = PathEl>
The iterator resulting from to_bez_path
.
Required Methods§
sourcefn to_bez_path(&self, tolerance: f64) -> Self::BezPathIter
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.
sourcefn area(&self) -> f64
fn area(&self) -> f64
Signed area.
This method only produces meaningful results with closed shapes.
TODO: figure out sign convention, see #4.
sourcefn winding(&self, pt: Vec2) -> i32
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.
sourcefn bounding_box(&self) -> Rect
fn bounding_box(&self) -> Rect
The smallest rectangle that encloses the shape.
Provided Methods§
fn into_bez_path(self, tolerance: f64) -> BezPath
sourcefn as_path_slice(&self) -> Option<&[PathEl]>
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§
source§impl<'a> Shape for &'a [PathEl]
impl<'a> Shape for &'a [PathEl]
source§fn winding(&self, pt: Vec2) -> i32
fn winding(&self, pt: Vec2) -> i32
Winding number of point.
TODO: figure out sign convention, see #4.
type BezPathIter = Cloned<Iter<'a, PathEl>>
fn to_bez_path(&self, _tolerance: f64) -> Self::BezPathIter
fn perimeter(&self, accuracy: f64) -> f64
fn bounding_box(&self) -> Rect
fn as_path_slice(&self) -> Option<&[PathEl]>
source§impl<'a, T: Shape> Shape for &'a T
impl<'a, T: Shape> Shape for &'a T
Blanket implementation so impl Shape
will accept owned or reference.