Polygon

Struct Polygon 

Source
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>

Source

pub fn new(points: S) -> Polygon<T, S>

Create a view of a set of points as a polygon.

Source

pub fn borrow(&self) -> Polygon<T, &[Point<T>]>

Return a polygon which borrows its points from this polygon.

Source

pub fn edges(&self) -> impl Iterator<Item = Line<T>> + '_

Return an iterator over the edges of this polygon.

Source

pub fn vertices(&self) -> &[Point<T>]

Return a slice of the endpoints of the polygon’s edges.

Source

pub fn to_owned(&self) -> Polygon<T>

Return a clone of this polygon which owns its vertices.

Source§

impl<S: AsRef<[Point]>> Polygon<i32, S>

Source

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.

Source

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.

Source

pub fn is_simple(&self) -> bool

Return true if this polygon has no self-intersections and no holes.

Trait Implementations§

Source§

impl<S: AsRef<[Point<f32>]>> BoundingRect for Polygon<f32, S>

Source§

type Coord = f32

Coordinate type of bounding rect.
Source§

fn bounding_rect(&self) -> Rect<f32>

Return the smallest axis-aligned bounding rect which contains this shape.
Source§

impl<S: AsRef<[Point<i32>]>> BoundingRect for Polygon<i32, S>

Source§

type Coord = i32

Coordinate type of bounding rect.
Source§

fn bounding_rect(&self) -> Rect<i32>

Return the smallest axis-aligned bounding rect which contains this shape.
Source§

impl<T: Clone + Coord, S: Clone + AsRef<[Point<T>]>> Clone for Polygon<T, S>

Source§

fn clone(&self) -> Polygon<T, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Coord, S: Debug + AsRef<[Point<T>]>> Debug for Polygon<T, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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>

§

impl<T, S> Send for Polygon<T, S>
where S: Send, T: Send,

§

impl<T, S> Sync for Polygon<T, S>
where S: Sync, T: Sync,

§

impl<T, S> Unpin for Polygon<T, S>
where S: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for Polygon<T, S>
where S: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.