[−][src]Trait polys::Polygon
Polygon trait for structs representing 2-dimensional shapes.
Required methods
Loading content...Implementors
impl Polygon for Circle
[src]
fn area(&self) -> Option<f64>
[src]
Gets the area of the Circle from its radius.
Examples
use crate::polys::Polygon; use std::f64::consts::PI; let circle = polys::Circle::new(5.0) .expect("Could not make Circle"); let area = circle.area().expect("Is none"); assert_eq!(area, PI * 25.0);
fn peri(&self) -> Option<f64>
[src]
Gets the circumferance of the Circle from its radius.
Examples
use crate::polys::Polygon; use core::f64::consts::PI; let circle = polys::Circle::new(5.0) .expect("Could not make Circle"); let peri = circle.peri().expect("Is none"); assert_eq!(peri, 10.0*PI);
fn angles(&self) -> Option<Vec<f64>>
[src]
Returns None.
Examples
use crate::polys::Polygon; let circle = polys::Circle::new(5.0) .expect("Could not make Circle"); let angles = circle.angles(); assert!(angles.is_none());
impl Polygon for Rect
[src]
fn area(&self) -> Option<f64>
[src]
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);
fn peri(&self) -> Option<f64>
[src]
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);
fn angles(&self) -> Option<Vec<f64>>
[src]
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);
impl Polygon for Reg
[src]
fn area(&self) -> Option<f64>
[src]
Gets the area of the Reg.
Examples
use crate::polys::Polygon; let reg = polys::Reg::new(3.0, 5.0) .expect("Could not make Reg"); let area = reg.area().expect("Is none"); assert_eq!(area, 15.484296605300704);
This can also be seen by comparing the Rect square and Reg implementations.
use crate::polys::Polygon; let square = polys::Rect::square(7.0) .expect("Could not make Reg").area().expect("Is none"); let reg = polys::Reg::new(7.0, 4.0) .expect("Could not make Reg").area().expect("Is none"); assert_eq!(square as i32, reg as i32); // casted to i32 because floats suck :)
fn peri(&self) -> Option<f64>
[src]
Gets the perimeter of the Reg.
Examples
This works on a regular polygon where it has 5 of more sides.
use crate::polys::Polygon; let reg = polys::Reg::new(3.0, 5.0) .expect("Could not make Reg"); let peri = reg.peri().expect("Is none"); assert_eq!(peri, 15.0);
This can also be seen by comparing the Rect square and Reg implementations.
use crate::polys::Polygon; let square = polys::Rect::square(7.0) .expect("Could not make Reg").peri(); let reg = polys::Reg::new(7.0, 4.0) .expect("Could not make Reg").peri();
fn angles(&self) -> Option<Vec<f64>>
[src]
Returns the size of the interior angles in degrees.
Examples
use crate::polys::Polygon; let poly = polys::Reg::pent(12.0) .expect("Could not make Reg"); let angles = poly.angles().expect("Is none"); assert_eq!(angles[0], 108.0);
impl Polygon for Tri
[src]
fn area(&self) -> Option<f64>
[src]
Gets the area of the Tri from its sides.
Examples
use crate::polys::Polygon; let tri = polys::Tri::new(24.0, 30.0, 18.0) .expect("Triangle could not be made"); let area = tri.area().expect("Is none"); assert_eq!(area, 216.0);
fn peri(&self) -> Option<f64>
[src]
Gets the perimeter of the Tri from its sides.
Examples
use crate::polys::Polygon; let tri = polys::Tri::new(24.0, 30.0, 18.0) .expect("Triangle could not be made"); let peri = tri.peri().expect("Is none"); assert_eq!(peri, 72.0);
fn angles(&self) -> Option<Vec<f64>>
[src]
Returns the a vector of three angles in radians such that angles[0]
is the angle opposite side1
, angles[1]
is the angle opposite side2
, and angles[2]
is the angle opposite side3
.
Examples
use crate::polys::Polygon; use std::f64::consts::PI; let tri = polys::Tri::new(24.0, 30.0, 24.0) .expect("Triangle could not be made"); let ang = tri.angles().expect("Is none"); assert_eq!(ang[0]+ang[1]+ang[2], PI); assert_eq!(ang[0], ang[2]); //iso tri let tri = polys::Tri::new(12.0, 19.0, 8.0) .expect("Triangle could not be made"); let ang = tri.angles().expect("Is none"); assert_eq!(ang[0]+ang[1]+ang[2], PI); let tri = polys::Tri::new(12.0, 12.0, 12.0) .expect("Triangle could not be made"); let ang = tri.angles().expect("Is none"); assert_eq!((ang[0]+ang[1]+ang[2]) as f32, PI as f32);