use crate::prelude::Point;
pub fn project_angle(start: Point, radius: f32, angle_radians: f32) -> Point {
let degrees_radians = angle_radians + std::f32::consts::PI;
Point::new(
(0.0 - (start.x as f32 + radius * f32::sin(degrees_radians))) as i32,
(start.y as f32 + radius * f32::cos(degrees_radians)) as i32,
)
}
#[cfg(test)]
mod tests {
use crate::prelude::{Point, project_angle};
#[test]
fn test_project_angle() {
let start = Point::new(0, 0);
let mut dest = project_angle(start, 10.0, 0.0);
assert_eq!(dest, Point::new(0, -10));
dest = project_angle(start, 10.0, std::f32::consts::PI); assert_eq!(dest, Point::new(0, 10));
dest = project_angle(start, 10.0, std::f32::consts::PI / 2.0); assert_eq!(dest, Point::new(10, 0));
dest = project_angle(
start,
10.0,
std::f32::consts::PI + (std::f32::consts::PI / 2.0),
); assert_eq!(dest, Point::new(-10, 0));
dest = project_angle(start, 10.0, std::f32::consts::FRAC_PI_4); assert_eq!(dest, Point::new(7, -7));
dest = project_angle(start, 10.0, 2.35619); assert_eq!(dest, Point::new(7, 7));
dest = project_angle(start, 10.0, 3.92699); assert_eq!(dest, Point::new(-7, 7));
dest = project_angle(start, 10.0, 5.49779); assert_eq!(dest, Point::new(-7, -7));
}
}