pub struct RegularPolygon {
    pub circumcircle: Circle,
    pub sides: usize,
}
Expand description

A polygon where all vertices lie on a circle, equally far apart.

Fields§

§circumcircle: Circle

The circumcircle on which all vertices lie

§sides: usize

The number of sides

Implementations§

source§

impl RegularPolygon

source

pub fn new(circumradius: f32, sides: usize) -> Self

Create a new RegularPolygon from the radius of the circumcircle and a number of sides

§Panics

Panics if circumradius is non-positive

source

pub fn circumradius(&self) -> f32

Get the radius of the circumcircle on which all vertices of the regular polygon lie

source

pub fn inradius(&self) -> f32

Get the inradius or apothem of the regular polygon. This is the radius of the largest circle that can be drawn within the polygon

source

pub fn side_length(&self) -> f32

Get the length of one side of the regular polygon

source

pub fn area(&self) -> f32

Get the area of the regular polygon

source

pub fn perimeter(&self) -> f32

Get the perimeter of the regular polygon. This is the sum of its sides

source

pub fn internal_angle_degrees(&self) -> f32

Get the internal angle of the regular polygon in degrees.

This is the angle formed by two adjacent sides with points within the angle being in the interior of the polygon

source

pub fn internal_angle_radians(&self) -> f32

Get the internal angle of the regular polygon in radians.

This is the angle formed by two adjacent sides with points within the angle being in the interior of the polygon

source

pub fn external_angle_degrees(&self) -> f32

Get the external angle of the regular polygon in degrees.

This is the angle formed by two adjacent sides with points within the angle being in the exterior of the polygon

source

pub fn external_angle_radians(&self) -> f32

Get the external angle of the regular polygon in radians.

This is the angle formed by two adjacent sides with points within the angle being in the exterior of the polygon

source

pub fn vertices(self, rotation: f32) -> impl IntoIterator<Item = Vec2>

Returns an iterator over the vertices of the regular polygon, rotated counterclockwise by the given angle in radians.

With a rotation of 0, a vertex will be placed at the top (0.0, circumradius).

Trait Implementations§

source§

impl Bounded2d for RegularPolygon

source§

fn aabb_2d(&self, translation: Vec2, rotation: f32) -> Aabb2d

Get an axis-aligned bounding box for the shape with the given translation and rotation. The rotation is in radians, counterclockwise, with 0 meaning no rotation.
source§

fn bounding_circle(&self, translation: Vec2, _rotation: f32) -> BoundingCircle

Get a bounding circle for the shape The rotation is in radians, counterclockwise, with 0 meaning no rotation.
source§

impl Clone for RegularPolygon

source§

fn clone(&self) -> RegularPolygon

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 Debug for RegularPolygon

source§

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

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

impl Default for RegularPolygon

source§

fn default() -> Self

Returns the default RegularPolygon with six sides (a hexagon) and a circumradius of 0.5.

source§

impl PartialEq for RegularPolygon

source§

fn eq(&self, other: &RegularPolygon) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for RegularPolygon

source§

impl Primitive2d for RegularPolygon

source§

impl StructuralPartialEq for RegularPolygon

Auto Trait Implementations§

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