move get_angle to util
This commit is contained in:
parent
33123cb9c3
commit
17705e2288
2 changed files with 21 additions and 0 deletions
|
@ -13,6 +13,7 @@ use {
|
|||
angle::Turns
|
||||
};
|
||||
|
||||
mod util;
|
||||
mod fixture;
|
||||
mod setup;
|
||||
mod view;
|
||||
|
@ -23,6 +24,7 @@ use crate::{
|
|||
fixture::Fixture,
|
||||
setup::LightingSetup,
|
||||
stripe_driver::StripeDriver,
|
||||
util::get_angle
|
||||
};
|
||||
|
||||
struct Breathing {
|
||||
|
|
19
src/util.rs
Normal file
19
src/util.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
use cgmath::Vector2;
|
||||
|
||||
pub fn get_angle(p: &Vector2<f32>) -> f32 {
|
||||
let pi=3.1415926;
|
||||
let pi2 = 2.0*pi;
|
||||
|
||||
if p.x < 0.0 {
|
||||
(p.y / p.x).atan() / pi2 + 0.75
|
||||
} else if p.x == 0.0 && p.y == 0.0 {
|
||||
0.0
|
||||
} else {
|
||||
if p.y < 0.0 {
|
||||
(-p.x / p.y).atan() / pi2
|
||||
} else {
|
||||
(p.y / p.x).atan() / pi2 + 0.25
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue