dsalgo 0.3.10

A package for Datastructures and Algorithms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// (r. theta)
#[derive(Debug, Clone, Copy, PartialEq)]

pub struct Polar(pub f64, pub f64);

impl Polar {
    pub fn from_cartesian(
        x: f64,
        y: f64,
    ) -> Self {
        Self(x.hypot(y), y.atan2(x))
    }

    pub fn cartesian(&self) -> (f64, f64) {
        (self.0 * self.1.cos(), self.0 * self.1.sin())
    }
}