fix mutually canceling orbits

This commit is contained in:
2026-06-17 20:50:31 +02:00
parent 0cf3d64983
commit e0e11b7933
6 changed files with 54 additions and 11 deletions

View File

@@ -1260,3 +1260,22 @@ TEST_CASE("OrbitMath: orbit sign follows the ship's tangential velocity",
// Zero velocity (e.g. freshly spawned) → fallback +1.
REQUIRE(OrbitMath::resolveOrbitSign(shipPos, center, QVector2D(0.0f, 0.0f)) == Approx(1.0f));
}
TEST_CASE("OrbitMath: orbit sense uses velocity relative to a moving center",
"[orbit]")
{
const QVector2D center(0.0f, 0.0f);
const QVector2D shipPos(5.0f, 0.0f); // radial points +x
// Two ships orbiting each other can translate in parallel: the ship and the
// center share the same velocity, so relative velocity cancels → fallback +1
// (both ships agree on the sign and break into a real mutual orbit).
const QVector2D sharedVelocity(0.0f, 3.0f);
REQUIRE(OrbitMath::resolveOrbitSign(shipPos, center, sharedVelocity, sharedVelocity)
== Approx(1.0f));
// A moving center's own motion is removed: the ship is stationary while the
// center drifts +y, so relative motion is -y → clockwise → -1.
REQUIRE(OrbitMath::resolveOrbitSign(shipPos, center, QVector2D(0.0f, 0.0f),
QVector2D(0.0f, 3.0f)) == Approx(-1.0f));
}