Crates.io | polys |
lib.rs | polys |
version | 0.4.2 |
source | src |
created_at | 2020-07-15 04:11:43.196314 |
updated_at | 2020-07-22 11:37:40.473297 |
description | A package for polygon geometry |
homepage | |
repository | https://github.com/Breadinator/polys |
max_upload_size | |
id | 265320 |
size | 19,130 |
polys is a Rust crate implementing basic polygons as structs, all implementing a trait which gives the basic functions associated with polygons.
Add this to your Cargo.toml
:
[dependencies]
polys = "0.4.2"
The following is the main.rs
file of my test program. It shows the area and perimeter of a rectangle, a triangle, and a circle.
use polys::{Polygon, Rect, Tri, Circle, Reg};
fn main() {
let poly = Rect::new(12.0, 6.0).expect("Could not make Rect");
println!("{:?}\n area: {}, peri: {}\n", &poly, &poly.area().expect("Is none"), &poly.peri().expect("Is none"));
let poly = Tri::new(24.0, 30.0, 18.0).expect("Could not make Tri");
println!("{:?}\n area: {}, peri: {}\n", &poly, &poly.area().expect("Is none"), &poly.peri().expect("Is none"));
let poly = Circle::new(5.0).expect("Could not make Circle");
println!("{:?}\n area: {}, peri: {}\n", &poly, &poly.area().expect("Is none"), &poly.peri().expect("Is none"));
let poly = Reg::new(3.0, 5.0).expect("Could not make Reg");
println!("{:?}\n area: {}, peri: {}\n", &poly, &poly.area().expect("Is none"), &poly.peri().expect("Is none"));
}
The output of this program returns the following:
Rect { width: 12.0, height: 6.0 }
area: 72, peri: 36
Tri { side1: 24.0, side2: 30.0, side3: 18.0 }
area: 216, peri: 72
Circle { radius: 5.0 }
area: 78.53981633974483, peri: 31.41592653589793
Reg { length: 3.0, sides: 5.0 }
area: 15.484296605300704, peri: 15
polys is distributed under the MIT license. See LICENSE.