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
impl Rect
Sourcepub fn new(w: f64, h: f64) -> Option<Rect>
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);
Sourcepub fn square(w: f64) -> Option<Rect>
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);
Sourcepub fn split(&self) -> Option<Tri>
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 Polygon for Rect
impl Polygon for Rect
Source§fn area(&self) -> Option<f64>
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);
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> 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
Mutably borrows from an owned value. Read more