Skip to content

Commit

Permalink
Fix London coordinate mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Dec 5, 2023
1 parent d437f57 commit 437e93c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/RoadCaptain/GameCoordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public GameCoordinate(double x, double y, double z, ZwiftWorldId worldId)
WorldId = worldId;
}

public override string ToString()
{
return $"X: {X} Y: {Y} Z: {Z}";
}

public bool Equals(GameCoordinate other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
Expand Down Expand Up @@ -69,7 +74,7 @@ public TrackPoint ToTrackPoint()
if (WorldId == ZwiftWorldId.London)
{
// London flips inputs
var latitudeAsCentimetersFromOrigin = Z + 572999216.4279556;
var latitudeAsCentimetersFromOrigin = (-Y) + 572999216.4279556;
var latitude = latitudeAsCentimetersFromOrigin * 8.988093472576876E-06 * 0.01;

var longitudeAsCentimetersFromOrigin = X + -1165514.8567129374;
Expand Down
37 changes: 27 additions & 10 deletions test/RoadCaptain.Tests.Unit/Coordinates/LondonMappingRepro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@
// Licensed under Artistic License 2.0
// See LICENSE or https://choosealicense.com/licenses/artistic-2.0/

using System.Diagnostics;
using FluentAssertions;
using Xunit;
using Xunit.Abstractions;

namespace RoadCaptain.Tests.Unit.Coordinates
{
public class LondonMappingRepro
{
[Fact]
public void LondonRegressionTest()
public void ThisIsTheRightMapping()
{
// Note to self: don't ever change this

var a = 156612.37500000f;
var b = -8146.51123000f;
var c = 10324.1376953125f;
var inputY = -53141.75781f;
var inputX = 315245.5f;
var expectedLat = 51.50649f;
var expectedLon = -0.12252f;

var trackPoint = Calculate(-inputY, inputX);

var real = new GameCoordinate(a, b, c, ZwiftWorldId.London).ToTrackPoint();
trackPoint.Latitude.Should().BeApproximately(expectedLat, 0.00001);
trackPoint.Longitude.Should().BeApproximately(expectedLon, 0.00001);
trackPoint.CoordinatesDecimal.Should().Be("N51.50648° W0.12252°");

var trackPointReal = new GameCoordinate(inputX, inputY, 0, ZwiftWorldId.London).ToTrackPoint();

trackPointReal.Should().Be(trackPoint);
}

private static TrackPoint Calculate(float a, float b)
{
// London flips inputs
var latitudeAsCentimetersFromOrigin = a + 572999216.4279556;
var latitude = latitudeAsCentimetersFromOrigin * 8.988093472576876E-06 * 0.01;

real.CoordinatesDecimal.Should().Be("N51.50263° W0.14537°");
real.Latitude.Should().BeApproximately(51.50263f, 0.000002f);
real.Longitude.Should().BeApproximately(-0.14537f, 0.000001f);
var longitudeAsCentimetersFromOrigin = b + -1165514.8567129374;
var longitude = longitudeAsCentimetersFromOrigin * 1.4409163767062611E-05 * 0.01;

return new TrackPoint(latitude, longitude, 0, ZwiftWorldId.London);
}
}
}
Expand Down

0 comments on commit 437e93c

Please sign in to comment.