1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::{Angle, Point2, Vector2};
use euclid::Trig;
pub trait Point2Godot {
fn angle_to_point(self, other: Point2) -> Angle;
fn direction_to(self, other: Point2) -> Vector2;
fn distance_to(self, other: Point2) -> f32;
fn distance_squared_to(self, other: Point2) -> f32;
}
impl Point2Godot for Point2 {
#[inline]
fn angle_to_point(self, other: Point2) -> Angle {
Angle::radians(Trig::fast_atan2(self.y - other.y, self.x - other.x))
}
#[inline]
fn direction_to(self, other: Point2) -> Vector2 {
(other - self).normalize()
}
#[inline]
fn distance_to(self, other: Point2) -> f32 {
(other - self).length()
}
#[inline]
fn distance_squared_to(self, other: Point2) -> f32 {
(other - self).square_length()
}
}