Skip to content

Commit

Permalink
Fix Vector3::signed_angle_to implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
joriskleiber committed May 13, 2024
1 parent 22fd33d commit cdcdd94
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion godot-core/src/builtin/vectors/vector3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Vector3 {

pub fn signed_angle_to(self, to: Self, axis: Self) -> real {
let cross_to = self.cross(to);
let unsigned_angle = self.dot(to).atan2(cross_to.length());
let unsigned_angle = cross_to.length().atan2(self.dot(to));
let sign = cross_to.dot(axis);
if sign < 0.0 {
-unsigned_angle
Expand Down
15 changes: 15 additions & 0 deletions itest/rust/src/builtin_tests/geometry/vector_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,18 @@ fn vector3_equiv() {
);
}
}

#[itest]
fn vector3_signed_angle_to() {
let outer = Vector3::new(1.0, 1.0, 0.0);
let inner = InnerVector3::from_outer(&outer);

let to = Vector3::new(1.0, 1.0, 1.0);
let axis = Vector3::UP;

assert_eq_approx!(
outer.signed_angle_to(to, axis),
inner.signed_angle_to(to, axis) as real,
"signed_angle_to\n",
);
}

0 comments on commit cdcdd94

Please sign in to comment.