Struct Rect

Source
pub struct Rect {
    pub width: f64,
    pub height: f64,
}
Expand description

Struct that represents a rectangle.

Fields§

§width: f64§height: f64

Implementations§

Source§

impl Rect

Source

pub fn new(w: f64, h: f64) -> Option<Rect>

Returns a new Rect from given width w and height h.

§Examples
let rect = polys::Rect::new(12.0, 6.0);
Source

pub fn square(w: f64) -> Option<Rect>

Returns a new Rect where both width and height are set to given value w.

§Examples
let square = polys::Rect::square(12.0);
Source

pub fn split(&self) -> Option<Tri>

Returns the triangle created by cutting the Rect through two opposite corners.

§Examples
use crate::polys::Polygon;

let rect = polys::Rect::new(3.0, 4.0)
    .expect("Cound not make Rect")
    .split()
    .expect("Could not convert to Tri");
let tri = polys::Tri::new(3.0, 4.0, 5.0)
    .expect("Could not make Tri");

assert_eq!(rect.side3, tri.side3);

Trait Implementations§

Source§

impl Debug for Rect

Source§

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

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

impl Polygon for Rect

Source§

fn area(&self) -> Option<f64>

Gets the area of the Rect according to its width and height.

§Examples
use crate::polys::Polygon;

let rect = polys::Rect::new(10.0, 5.0)
    .expect("Could not make Rect");
let area = rect.area().expect("Is none");
assert_eq!(area, 50.0);
Source§

fn peri(&self) -> Option<f64>

Gets the perimeter of the Rect from its width and height.

§Examples
use crate::polys::Polygon;

let rect = polys::Rect::new(10.0, 5.0)
    .expect("Could not make Rect");
let peri = rect.peri().expect("Is none");
assert_eq!(peri, 30.0);
Source§

fn angles(&self) -> Option<Vec<f64>>

Returns interior angles (all 90) in degrees.

§Examples
use crate::polys::Polygon;

let rect = polys::Rect::new(10.0, 5.0)
    .expect("Could not make Rect");
let angles = rect.angles().expect("Is none");
assert_eq!((angles)[0], 90.0);

Auto Trait Implementations§

§

impl Freeze for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnwindSafe for Rect

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