use std::f64::consts::PI;
use crate::tri::Tri;
use crate::Polygon;
#[derive(Debug)]
pub struct Rect {
pub width: f64,
pub height: f64,
}
impl Rect {
pub fn new(w: f64, h: f64) -> Option<Rect> {
if w == 0.0 || h == 0.0 {
None
} else {
Some(Rect {
width: w,
height: h,
})
}
}
pub fn square(w: f64) -> Option<Rect> {
if w == 0.0 {
None
} else {
Some(Rect {
width: w,
height: w,
})
}
}
pub fn split(&self) -> Option<Tri> {
Tri::sas(self.width, self.height, PI / 2.0)
}
}
impl Polygon for Rect {
fn area(&self) -> Option<f64> {
Some(self.width * self.height)
}
fn peri(&self) -> Option<f64> {
Some(2.0 * &self.width + 2.0 * &self.height)
}
fn angles(&self) -> Option<Vec<f64>> {
Some(vec![90.0; 4])
}
}