Skip to content

Commit

Permalink
Fix macOS test, add another test.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Aug 14, 2024
1 parent a7cccce commit 0402763
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Runtime/CesiumFlyToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ private void Reset()
private bool DetectMovementInput()
{
double3 currentPositionECEF = this._globeAnchor.positionGlobeFixed;
bool3 positionEquality = currentPositionECEF == this._previousPositionECEF;
return !positionEquality.x || !positionEquality.y || !positionEquality.z;
double distanceSquared = math.lengthsq(currentPositionECEF - this._previousPositionECEF);
const double distanceConsideredMovement = 1e-6; // 1/1000 of a millimeter
return distanceSquared >= (distanceConsideredMovement * distanceConsideredMovement);
}

/// <summary>
Expand Down
59 changes: 59 additions & 0 deletions Tests/TestCesiumFlyToController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,63 @@ public IEnumerator FlyToLocationLongitudeLatitudeHeight()
Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
}

[UnityTest]
public IEnumerator FlyToLocationLongitudeLatitudeHeightInterrupted()
{
GameObject goGeoreference = new GameObject("Georeference");
CesiumGeoreference georeference = goGeoreference.AddComponent<CesiumGeoreference>();
georeference.longitude = -55.0;
georeference.latitude = 55.0;
georeference.height = 1000.0;

GameObject goFlyer = new GameObject("Flyer");
goFlyer.transform.parent = goGeoreference.transform;

CesiumGlobeAnchor anchor = goFlyer.AddComponent<CesiumGlobeAnchor>();
goFlyer.AddComponent<CesiumOriginShift>();
CesiumFlyToController flyToController = goFlyer.AddComponent<CesiumFlyToController>();

// Make the flight fast so the test doesn't take too long.
flyToController.flyToDuration = 0.25;

anchor.adjustOrientationForGlobeWhenMoving = false;
anchor.longitudeLatitudeHeight = new double3(20.0, -25.0, 1000.0);
anchor.adjustOrientationForGlobeWhenMoving = true;

yield return null;

// The origin should have been shifted so the flyer is at the origin.
Assert.That(goFlyer.transform.position.x, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.y, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));
Assert.That(goFlyer.transform.position.z, Is.EqualTo(0.0f).Using(FloatEqualityComparer.Instance));

// Start a flight to elsewhere
bool flightComplete = false;
flyToController.OnFlightComplete += () =>
{
flightComplete = true;
};

bool flightInterrupted = false;
flyToController.OnFlightInterrupted += () =>
{
flightInterrupted = true;
};

flyToController.FlyToLocationLongitudeLatitudeHeight(new double3(100.0, 25.0, 800.0), 0.0f, 0.0f, true);

yield return null;

Assert.IsFalse(flightComplete);
Assert.IsFalse(flightInterrupted);

// Give the object a new position, which should abort the flight.
goFlyer.transform.position = new Vector3(100.0f, 200.0f, 300.0f);

yield return null;

Assert.IsFalse(flightComplete);
Assert.IsTrue(flightInterrupted);
}
}

0 comments on commit 0402763

Please sign in to comment.