fix two wrong expectations in the locomotion math tests
Both were test bugs; MotionInputMath itself is correct. WorldToCameraRelativeInput_Yaw90 expected +1 for the camera-relative x. A camera yawed +90 degrees faces +X, so world +Z is to its left and the value is -1. The conversion applies Quaternion.Euler(0, -cameraYaw, 0) and Unity's Y rotation is clockwise viewed from above, so forward maps to -right. The round-trip test already pinned this convention and passes precisely because of it. ScreenDeltaToWorldPan compared Vector3 with Assert.AreEqual, which is exact. -10f * 0.02f lands one ulp from the -0.2f literal, so a correct result failed a comparison that printed as identical at two decimals. Now compared per component with a tolerance. EditMode suite is 39/39. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
@@ -24,9 +24,16 @@ namespace NightclubArcadia.Locomotion.Math.Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void WorldToCameraRelativeInput_Yaw90_RotatesCorrectly()
|
public void WorldToCameraRelativeInput_Yaw90_RotatesCorrectly()
|
||||||
{
|
{
|
||||||
|
// Camera yawed +90 degrees faces +X. World velocity is +Z, which from
|
||||||
|
// that camera is to the LEFT, so the camera-relative x is -1, not +1.
|
||||||
|
// The conversion applies Quaternion.Euler(0, -cameraYaw, 0), and Unity's
|
||||||
|
// Y rotation is clockwise viewed from above, so forward maps to -right.
|
||||||
|
// WorldToCameraRelativeInput_RoundTripsThroughAtan2 pins the same
|
||||||
|
// convention: it only reconstructs the world direction because the yaw
|
||||||
|
// is subtracted here and added back there.
|
||||||
var world = new Vector3(0f, 0f, 2f);
|
var world = new Vector3(0f, 0f, 2f);
|
||||||
var result = MotionInputMath.WorldToCameraRelativeInput(world, 2f, 90f);
|
var result = MotionInputMath.WorldToCameraRelativeInput(world, 2f, 90f);
|
||||||
Assert.That(result.x, Is.EqualTo(1f).Within(0.001f));
|
Assert.That(result.x, Is.EqualTo(-1f).Within(0.001f));
|
||||||
Assert.That(result.y, Is.EqualTo(0f).Within(0.001f));
|
Assert.That(result.y, Is.EqualTo(0f).Within(0.001f));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +65,13 @@ namespace NightclubArcadia.Locomotion.Math.Tests
|
|||||||
var forward = Vector3.forward;
|
var forward = Vector3.forward;
|
||||||
var delta = new Vector2(10f, 0f);
|
var delta = new Vector2(10f, 0f);
|
||||||
var result = MotionInputMath.ScreenDeltaToWorldPan(delta, right, forward, 0.02f);
|
var result = MotionInputMath.ScreenDeltaToWorldPan(delta, right, forward, 0.02f);
|
||||||
Assert.AreEqual(new Vector3(-0.2f, 0f, 0f), result);
|
|
||||||
|
// Compared per component with a tolerance rather than Assert.AreEqual:
|
||||||
|
// Vector3.Equals is exact, and -10f * 0.02f lands one ulp away from the
|
||||||
|
// -0.2f literal, so an exact comparison fails on a correct result.
|
||||||
|
Assert.That(result.x, Is.EqualTo(-0.2f).Within(0.0001f));
|
||||||
|
Assert.That(result.y, Is.EqualTo(0f).Within(0.0001f));
|
||||||
|
Assert.That(result.z, Is.EqualTo(0f).Within(0.0001f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user