Struct ril::draw::Polygon

source ·
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>

source

pub fn new() -> Self

Creates a new empty polygon.

source

pub fn update_bounding_box(&mut self)

Updates the polygon’s bounding box. This is automatically called, unless explicitly specified in documentation.

source

pub fn from_vertices(vertices: impl IntoIterator<Item = (u32, u32)>) -> Self

Creates a new polygon with the given vertices.

source

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
source

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
source

pub fn with_vertex(self, x: u32, y: u32) -> Self

Adds a vertex to the polygon.

source

pub fn push_vertex(&mut self, x: u32, y: u32)

Adds a vertex to the polygon in place.

source

pub fn vertices(&self) -> &[(u32, u32)]

Returns a slice of the vertices in the polygon.

source

pub fn vertices_mut(&mut self) -> &mut [(u32, u32)]

Returns a mutable slice of the vertices in the polygon.

source

pub fn iter_vertices(&self) -> impl Iterator<Item = &(u32, u32)>

Iterates over the vertices in the polygon.

source

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.

source

pub const fn with_border(self, border: Border<F::Pixel>) -> Self

Sets the border of the polygon.

source

pub const fn with_rounded(self, rounded: bool) -> Self

Sets whether the border should be rounded.

source

pub fn with_fill(self, fill: F) -> Self

Sets the fill color of the polygon.

source

pub const fn with_overlay_mode(self, overlay: OverlayMode) -> Self

Sets the overlay mode of the polygon.

source

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§

source§

impl<F: Clone + IntoFill> Clone for Polygon<F>
where F::Pixel: Clone, F::Fill: Clone,

source§

fn clone(&self) -> Polygon<F>

Returns a copy 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<F: Debug + IntoFill> Debug for Polygon<F>
where F::Pixel: Debug, F::Fill: Debug,

source§

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

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

impl<F: IntoFill> Default for Polygon<F>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<F: IntoFill> Draw<<F as IntoFill>::Pixel> for Polygon<F>

source§

fn draw<I: DerefMut<Target = Image<F::Pixel>>>(&self, image: I)

Draws the object to the given image.

Auto Trait Implementations§

§

impl<F> Freeze for Polygon<F>
where <F as IntoFill>::Fill: Freeze, <F as IntoFill>::Pixel: Freeze,

§

impl<F> RefUnwindSafe for Polygon<F>

§

impl<F> Send for Polygon<F>
where <F as IntoFill>::Fill: Send, <F as IntoFill>::Pixel: Send,

§

impl<F> Sync for Polygon<F>
where <F as IntoFill>::Fill: Sync, <F as IntoFill>::Pixel: Sync,

§

impl<F> Unpin for Polygon<F>
where <F as IntoFill>::Fill: Unpin, <F as IntoFill>::Pixel: Unpin,

§

impl<F> UnwindSafe for Polygon<F>
where <F as IntoFill>::Fill: UnwindSafe, <F as IntoFill>::Pixel: 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

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,

§

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

§

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

§

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.