pub struct Polygon<F: IntoFill> {
pub vertices: Vec<(u32, u32)>,
pub border: Option<Border<F::Pixel>>,
pub rounded: bool,
pub fill: Option<F::Fill>,
pub overlay: Option<OverlayMode>,
pub antialiased: bool,
}
Expand description
A polygon.
Fields§
§vertices: Vec<(u32, u32)>
A Vec
of vertices that make up the polygon. The vertices are connected in the order they
are given.
When drawing, a panic will occur if there is less than 3 vertices in this Vec
.
If the first and last vertices are the same, these points will remain untouched. Otherwise,
and extra vertex equivalent to the first vertex will be added to the end of the Vec
to
close the polygon.
border: Option<Border<F::Pixel>>
The border of the polygon. Either this or fill
must be Some
.
rounded: bool
Whether the border should be rounded off by drawing circles at each vertex. This is only
applied if border
is Some
. Additionally, these circles will not antialias.
fill: Option<F::Fill>
The fill color of the polygon. Either this or border
must be Some
.
overlay: Option<OverlayMode>
The overlay mode of the polygon. If None
, the image’s overlay mode will be used.
antialiased: bool
Whether to antialias the polygon’s edges.
Implementations§
source§impl<F: IntoFill> Polygon<F>
impl<F: IntoFill> Polygon<F>
sourcepub fn update_bounding_box(&mut self)
pub fn update_bounding_box(&mut self)
Updates the polygon’s bounding box. This is automatically called, unless explicitly specified in documentation.
sourcepub fn from_vertices(vertices: impl IntoIterator<Item = (u32, u32)>) -> Self
pub fn from_vertices(vertices: impl IntoIterator<Item = (u32, u32)>) -> Self
Creates a new polygon with the given vertices.
sourcepub fn regular_rotated(
n: u32,
center: (u32, u32),
radius: u32,
angle: f64,
) -> Self
pub fn regular_rotated( n: u32, center: (u32, u32), radius: u32, angle: f64, ) -> Self
Creates a regular polygon with n
sides centered at center
, with each of the points
radius
away from the center. angle
is measured in radians and is the angle offset of the
first point, which for angle=0.0
, will be horizontally to the right of the center
(i.e. a unit circle).
For angles specified in degrees, the f64::to_radians
method can be used for conversion.
§Note
Apart from n=4
, the polygon will not be pixel-perfect since no polygons other than squares
have all of their vertices as perfect integers. This means that they will be rounded to the
nearest pixel.
§Panics
- If
n < 3
sourcepub fn regular(n: u32, center: (u32, u32), radius: u32) -> Self
pub fn regular(n: u32, center: (u32, u32), radius: u32) -> Self
Creates a regular polygon with the first point vertically up from the center (the polygon will seem to be facing “upwards”).
This is a shortcut to calling Polygon::regular_rotated
with angle = PI / 2
(90deg
).
§See Also
Polygon::regular_rotated
for more information.
sourcepub fn with_vertex(self, x: u32, y: u32) -> Self
pub fn with_vertex(self, x: u32, y: u32) -> Self
Adds a vertex to the polygon.
sourcepub fn push_vertex(&mut self, x: u32, y: u32)
pub fn push_vertex(&mut self, x: u32, y: u32)
Adds a vertex to the polygon in place.
sourcepub fn vertices_mut(&mut self) -> &mut [(u32, u32)]
pub fn vertices_mut(&mut self) -> &mut [(u32, u32)]
Returns a mutable slice of the vertices in the polygon.
sourcepub fn iter_vertices(&self) -> impl Iterator<Item = &(u32, u32)>
pub fn iter_vertices(&self) -> impl Iterator<Item = &(u32, u32)>
Iterates over the vertices in the polygon.
sourcepub fn iter_vertices_mut(&mut self) -> impl Iterator<Item = &mut (u32, u32)>
pub fn iter_vertices_mut(&mut self) -> impl Iterator<Item = &mut (u32, u32)>
Iterates over the vertices in the polygon in mutable form. Make sure to call
update_bounding_box
after mutating the vertices.
sourcepub const fn with_border(self, border: Border<F::Pixel>) -> Self
pub const fn with_border(self, border: Border<F::Pixel>) -> Self
Sets the border of the polygon.
sourcepub const fn with_rounded(self, rounded: bool) -> Self
pub const fn with_rounded(self, rounded: bool) -> Self
Sets whether the border should be rounded.
sourcepub const fn with_overlay_mode(self, overlay: OverlayMode) -> Self
pub const fn with_overlay_mode(self, overlay: OverlayMode) -> Self
Sets the overlay mode of the polygon.
sourcepub const fn with_antialiased(self, antialiased: bool) -> Self
pub const fn with_antialiased(self, antialiased: bool) -> Self
Sets whether to antialias the polygon’s edges. If set to true
, this will also set the
overlay mode to OverlayMode::Merge
.
Trait Implementations§
Auto Trait Implementations§
impl<F> Freeze for Polygon<F>
impl<F> RefUnwindSafe for Polygon<F>
impl<F> Send for Polygon<F>
impl<F> Sync for Polygon<F>
impl<F> Unpin for Polygon<F>
impl<F> UnwindSafe for Polygon<F>
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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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