Crates.io | area_crate |
lib.rs | area_crate |
version | 0.1.1 |
source | src |
created_at | 2023-08-10 10:45:37.614802 |
updated_at | 2024-06-15 12:30:59.995243 |
description | Basic Area function |
homepage | |
repository | |
max_upload_size | |
id | 940823 |
size | 7,130 |
This is a collection of some generally used area functions.
let radius = 12.0;
let answer = area_crate::area::circle(radius);
assert_eq!(452.38934211696005, answer);
pub fn circle(radius: f64) -> f64 {
let pi = 3.14159265359;
pi * radius * radius
}
pub fn triangle(base: f64, height: f64) -> f64 {
0.5 * base * height
}
pub fn rectangle(length: f64, breadth: f64) -> f64 {
length * breadth
}
pub fn square(side: f64) -> f64 {
side * side
}
pub fn parallelogram(base: f64, height: f64) -> f64 {
base * height
}
pub fn trapezoid(base1: f64, base2: f64, height: f64) -> f64 {
0.5 * (base1 + base2) * height
}
pub fn ellipse(major_axis: f64, minor_axis: f64) -> f64 {
let pi = 3.14159265359;
pi * major_axis * minor_axis
}
pub fn sector(radius: f64, angle: f64) -> f64 {
let pi = 3.14159265359;
0.5 * radius * radius * angle.to_radians()
}
pub fn rhombus(diagonal1: f64, diagonal2: f64) -> f64 {
0.5 * diagonal1 * diagonal2
}
pub fn kite(diagonal1: f64, diagonal2: f64) -> f64 {
0.5 * diagonal1 * diagonal2
}
pub fn regular_polygon(perimeter: f64, apothem: f64) -> f64 {
0.5 * perimeter * apothem
}
pub fn annulus(outer_radius: f64, inner_radius: f64) -> f64 {
let pi = 3.14159265359;
pi * (outer_radius * outer_radius - inner_radius * inner_radius)
}