Skip to content

Commit 27b0054

Browse files
authored
Merge pull request #710 from joriskleiber/fix-vector3-signed-angle-to
Fix `Vector3::signed_angle_to` implementation
2 parents 22fd33d + cdcdd94 commit 27b0054

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl Vector3 {
205205

206206
pub fn signed_angle_to(self, to: Self, axis: Self) -> real {
207207
let cross_to = self.cross(to);
208-
let unsigned_angle = self.dot(to).atan2(cross_to.length());
208+
let unsigned_angle = cross_to.length().atan2(self.dot(to));
209209
let sign = cross_to.dot(axis);
210210
if sign < 0.0 {
211211
-unsigned_angle

itest/rust/src/builtin_tests/geometry/vector_test.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,18 @@ fn vector3_equiv() {
6868
);
6969
}
7070
}
71+
72+
#[itest]
73+
fn vector3_signed_angle_to() {
74+
let outer = Vector3::new(1.0, 1.0, 0.0);
75+
let inner = InnerVector3::from_outer(&outer);
76+
77+
let to = Vector3::new(1.0, 1.0, 1.0);
78+
let axis = Vector3::UP;
79+
80+
assert_eq_approx!(
81+
outer.signed_angle_to(to, axis),
82+
inner.signed_angle_to(to, axis) as real,
83+
"signed_angle_to\n",
84+
);
85+
}

0 commit comments

Comments
 (0)