pub struct Polygon<T: Coord = i32, S: AsRef<[Point<T>]> = Vec<Point<T>>> { /* private fields */ }Expand description
Polygon shape defined by a list of vertices.
Depending on the storage type S, a Polygon can own its vertices
(eg. Vec<Point>) or they can borrowed (eg. &[Point]).
Implementations§
Source§impl<T: Coord, S: AsRef<[Point<T>]>> Polygon<T, S>
impl<T: Coord, S: AsRef<[Point<T>]>> Polygon<T, S>
Source§impl<S: AsRef<[Point]>> Polygon<i32, S>
impl<S: AsRef<[Point]>> Polygon<i32, S>
Sourcepub fn fill_iter(&self) -> FillIter ⓘ
pub fn fill_iter(&self) -> FillIter ⓘ
Return an iterator over coordinates of pixels that fill the polygon.
Polygon filling treats the polygon’s vertices as being located at the center of pixels with the corresponding coordinates. Pixels are deemed inside the polygon if a ray from -infinity to the pixel’s center crosses an odd number of polygon edges, aka. the even-odd rule 1. Pixel centers which lie exactly on a polygon edge are treated as inside the polygon for top/left edges and outside the polygon for bottom/right edges. This follows conventions in various graphics libraries (eg. 2).
This treatment of polygon vertices differs from graphics libraries like Skia or Qt which use float coordinates for paths. In those libraries polygon filling is still based on the relationship between polygon edges and pixel centers, but integer polygon vertex coordinates refer to the corners of pixels.
Sourcepub fn contains_pixel(&self, p: Point) -> bool
pub fn contains_pixel(&self, p: Point) -> bool
Return true if the pixel with coordinates p lies inside the polygon.
The intent of this function is to align with Polygon::fill_iter such
that polygon.contains_pixel(p) is equivalent to
polygon.fill_iter().any(|fp| fp == p) but faster because it doesn’t
iterate over every pixel inside the polygon. See Polygon::fill_iter
for notes on how the inside/outisde status of a pixel is determined.
Trait Implementations§
impl<T: Copy + Coord, S: Copy + AsRef<[Point<T>]>> Copy for Polygon<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for Polygon<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for Polygon<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for Polygon<T, S>
impl<T, S> Sync for Polygon<T, S>
impl<T, S> Unpin for Polygon<T, S>
impl<T, S> UnwindSafe for Polygon<T, S>where
S: UnwindSafe,
T: UnwindSafe,
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,
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