use crate::{
LatLng,
math::{atan, sqrt, tan},
};
pub struct Triangle {
a: LatLng,
b: LatLng,
c: LatLng,
}
impl Triangle {
pub const fn new(a: LatLng, b: LatLng, c: LatLng) -> Self {
Self { a, b, c }
}
pub fn area(&self) -> f64 {
area_from_edges(
self.a.distance_rads(self.b),
self.b.distance_rads(self.c),
self.c.distance_rads(self.a),
)
}
}
fn area_from_edges(mut a: f64, mut b: f64, mut c: f64) -> f64 {
let mut s = (a + b + c) / 2.0;
a = (s - a) / 2.;
b = (s - b) / 2.;
c = (s - c) / 2.;
s /= 2.;
4. * atan(sqrt(tan(s) * tan(a) * tan(b) * tan(c)))
}