@@ -77,6 +77,21 @@ impl Vector2 {
77
77
v. cast_float ( )
78
78
}
79
79
80
+ /// Creates a unit Vector2 rotated to the given `angle` in radians. This is equivalent to doing `Vector2::new(angle.cos(), angle.sin())`
81
+ /// or `Vector2::RIGHT.rotated(angle)`.
82
+ ///
83
+ /// ```no_run
84
+ /// use godot::prelude::*;
85
+ ///
86
+ /// let a = Vector2::from_angle(0.0); // (1.0, 0.0)
87
+ /// let b = Vector2::new(1.0, 0.0).angle(); // 0.0
88
+ /// let c = Vector2::from_angle(real_consts::PI / 2.0); // (0.0, 1.0)
89
+ /// ```
90
+ #[ inline]
91
+ pub fn from_angle ( angle : real ) -> Self {
92
+ Self :: from_glam ( RVec2 :: from_angle ( angle) )
93
+ }
94
+
80
95
/// Returns this vector's angle with respect to the positive X axis, or `(1.0, 0.0)` vector, in radians.
81
96
///
82
97
/// For example, `Vector2::RIGHT.angle()` will return zero, `Vector2::DOWN.angle()` will return `PI / 2` (a quarter turn, or 90 degrees),
@@ -90,6 +105,14 @@ impl Vector2 {
90
105
self . y . atan2 ( self . x )
91
106
}
92
107
108
+ /// Returns the **signed** angle between `self` and the given vector, as radians in `[-π, +π]`.
109
+ ///
110
+ /// Note that behavior is different from 3D [`Vector3::angle_to()`] which returns the **unsigned** angle.
111
+ #[ inline]
112
+ pub fn angle_to ( self , to : Self ) -> real {
113
+ self . glam2 ( & to, |a, b| a. angle_to ( b) )
114
+ }
115
+
93
116
/// Returns the angle to the given vector, in radians.
94
117
///
95
118
/// [Illustration of the returned angle.](https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png)
@@ -111,21 +134,6 @@ impl Vector2 {
111
134
self . to_glam ( ) . perp_dot ( with. to_glam ( ) )
112
135
}
113
136
114
- /// Creates a unit Vector2 rotated to the given `angle` in radians. This is equivalent to doing `Vector2::new(angle.cos(), angle.sin())`
115
- /// or `Vector2::RIGHT.rotated(angle)`.
116
- ///
117
- /// ```no_run
118
- /// use godot::prelude::*;
119
- ///
120
- /// let a = Vector2::from_angle(0.0); // (1.0, 0.0)
121
- /// let b = Vector2::new(1.0, 0.0).angle(); // 0.0
122
- /// let c = Vector2::from_angle(real_consts::PI / 2.0); // (0.0, 1.0)
123
- /// ```
124
- #[ inline]
125
- pub fn from_angle ( angle : real ) -> Self {
126
- Self :: from_glam ( RVec2 :: from_angle ( angle) )
127
- }
128
-
129
137
/// Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
130
138
#[ inline]
131
139
pub fn orthogonal ( self ) -> Self {
0 commit comments