Skip to content

Commit 0cc5036

Browse files
committed
glam: Vec2::angle_between() deprecated -> angle_to()
1 parent 11b3ea6 commit 0cc5036

File tree

3 files changed

+37
-23
lines changed

3 files changed

+37
-23
lines changed

godot-core/src/builtin/vectors/vector2.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,21 @@ impl Vector2 {
7777
v.cast_float()
7878
}
7979

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+
8095
/// Returns this vector's angle with respect to the positive X axis, or `(1.0, 0.0)` vector, in radians.
8196
///
8297
/// 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 {
90105
self.y.atan2(self.x)
91106
}
92107

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+
93116
/// Returns the angle to the given vector, in radians.
94117
///
95118
/// [Illustration of the returned angle.](https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png)
@@ -111,21 +134,6 @@ impl Vector2 {
111134
self.to_glam().perp_dot(with.to_glam())
112135
}
113136

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-
129137
/// Returns a perpendicular vector rotated 90 degrees counter-clockwise compared to the original, with the same length.
130138
#[inline]
131139
pub fn orthogonal(self) -> Self {

godot-core/src/builtin/vectors/vector3.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,20 @@ impl Vector3 {
180180
Basis::from_axis_angle(axis, angle) * self
181181
}
182182

183-
/// Returns the signed angle to the given vector, in radians. The sign of the angle is positive in a counter-clockwise direction and
184-
/// negative in a clockwise direction when viewed from the side specified by the `axis`.
183+
/// Returns the **unsigned** angle between `self` and the given vector, as radians in `[0, +π]`.
184+
///
185+
/// Note that behavior is different from 2D [`Vector2::angle_to()`], which returns the **signed** angle.
186+
#[inline]
187+
pub fn angle_to(self, to: Self) -> real {
188+
self.glam2(&to, |a, b| a.angle_between(b))
189+
}
190+
191+
/// Returns the signed angle to the given vector, as radians in `[-π, +π]`.
192+
///
193+
/// The sign of the angle is positive in a counter-clockwise direction and negative in a clockwise direction, when viewed from
194+
/// the side specified by the `axis`.
195+
///
196+
/// For unsigned angles, use [`Vector3::angle_to()`].
185197
#[inline]
186198
pub fn signed_angle_to(self, to: Self, axis: Self) -> real {
187199
let cross_to = self.cross(to);

godot-core/src/builtin/vectors/vector_macros.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,12 +1009,6 @@ macro_rules! impl_vector2_vector3_fns {
10091009
/// # 2D and 3D functions
10101010
/// The following methods are available on both 2D and 3D float vectors.
10111011
impl $Vector {
1012-
/// Returns the angle to the given vector, in radians.
1013-
#[inline]
1014-
pub fn angle_to(self, to: Self) -> real {
1015-
self.glam2(&to, |a, b| a.angle_between(b))
1016-
}
1017-
10181012
/// Returns the derivative at the given `t` on the [Bézier](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
10191013
/// curve defined by this vector and the given `control_1`, `control_2`, and `end` points.
10201014
#[inline]

0 commit comments

Comments
 (0)