Skip to content

Commit 831958c

Browse files
bors[bot]Bromeon
andauthored
Merge #760
760: Fixing bug of fn rotated in Vector3 r=Bromeon a=jo32 based on related code in godot: https://github.com/godotengine/godot/blob/554c776e08c9ee35fa9e2677e02f4005c11ddbc0/core/math/vector3.cpp#L36 Co-authored-by: Jan Haller <[email protected]>
2 parents b6dcf6e + 27e57f6 commit 831958c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

gdnative-core/src/core_types/geom/basis.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,9 @@ impl Basis {
571571
}
572572
}
573573

574-
impl core::ops::Mul<Basis> for Basis {
574+
impl Mul<Basis> for Basis {
575575
type Output = Self;
576+
576577
#[inline]
577578
fn mul(self, rhs: Self) -> Self {
578579
Basis::from_elements([
@@ -600,7 +601,7 @@ impl Mul<Vector3> for Basis {
600601

601602
#[inline]
602603
fn mul(self, rhs: Self::Output) -> Self::Output {
603-
Self::Output::new(self.tdotx(rhs), self.tdoty(rhs), self.tdotz(rhs))
604+
self.xform(rhs)
604605
}
605606
}
606607

gdnative-core/src/core_types/vector3.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,23 @@ godot_test!(
534534
mod tests {
535535
use crate::core_types::Vector3;
536536

537+
/*
538+
* Test introduced due to bug in Basis * Vector3 operator
539+
*
540+
* matching result in GDScript:
541+
* var v1 = Vector3(37.51756, 20.39467, 49.96816)
542+
* var phi = -0.4927880786382844
543+
* var v2 = v1.rotated(Vector3.UP, r)
544+
* print(c)
545+
*/
546+
#[test]
547+
fn rotated() {
548+
let v = Vector3::new(37.51756, 20.39467, 49.96816);
549+
let phi = -0.4927880786382844;
550+
let r = v.rotated(Vector3::UP, phi);
551+
assert!(r.is_equal_approx(Vector3::new(9.414476, 20.39467, 61.77177)));
552+
}
553+
537554
#[test]
538555
fn it_is_copy() {
539556
fn copy<T: Copy>() {}

gdnative-core/src/object.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1017,8 +1017,10 @@ pub trait AsVariant: AsArg<<Self as AsVariant>::Target> {
10171017
pub struct Null<T>(PhantomData<T>);
10181018

10191019
impl<T: GodotObject> Null<T> {
1020-
/// Creates an explicitly null reference that can be used as a method argument.
1020+
/// Creates an explicit null reference that can be used as a method argument.
1021+
// TODO consider something more idiomatic, like module::null::<T>(), similar to std::ptr::null()
10211022
#[inline]
1023+
#[allow(clippy::self_named_constructors)]
10221024
pub fn null() -> Self {
10231025
Null(PhantomData)
10241026
}

0 commit comments

Comments
 (0)