move get_angle to util

This commit is contained in:
Michael Sippel 2024-04-26 11:16:39 +02:00
parent 33123cb9c3
commit 17705e2288
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 21 additions and 0 deletions

View file

@ -13,6 +13,7 @@ use {
angle::Turns angle::Turns
}; };
mod util;
mod fixture; mod fixture;
mod setup; mod setup;
mod view; mod view;
@ -23,6 +24,7 @@ use crate::{
fixture::Fixture, fixture::Fixture,
setup::LightingSetup, setup::LightingSetup,
stripe_driver::StripeDriver, stripe_driver::StripeDriver,
util::get_angle
}; };
struct Breathing { struct Breathing {

19
src/util.rs Normal file
View 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
}
}
}