LocationCoordinates

This commit is contained in:
alterNERDtive 2022-02-15 13:22:59 +01:00
parent de5848b69d
commit 7de48c5c78
5 changed files with 30 additions and 29 deletions

View file

@ -50,6 +50,6 @@ namespace alterNERDtive.Edna
public StarSystem StarSystem { get; private set; }
public new Location Coordinates { get; private set; }
public new Coordinates Coordinates { get; private set; }
}
}

View file

@ -30,33 +30,34 @@ namespace alterNERDtive.Edna
/// precision (all in ly).
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Either this or wrong class/struct order 🤷")]
public struct Location
public struct Coordinates
{
/// <summary>
/// Initializes a new instance of the <see cref="Location"/> struct.
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
/// <param name="precision">The available precision.</param>
public Location(double x, double y, double z, int precision)
public Coordinates(double x, double y, double z, int precision)
=> (this.X, this.Y, this.Z, this.Precision) = (x, y, z, precision);
/// <summary>
/// Initializes a new instance of the <see cref="Location"/> struct.
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="z">The z coordinate.</param>
public Location(double x, double y, double z)
public Coordinates(double x, double y, double z)
=> (this.X, this.Y, this.Z, this.Precision) = (x, y, z, 0);
/// <summary>
/// Initializes a new instance of the <see cref="Location"/> struct.
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
/// </summary>
/// <param name="location">An EDTS Location to convert.</param>
public Location(Edts.Location location)
=> (this.X, this.Y, this.Z, this.Precision) = (location.X, location.Y, location.Z, location.Precision);
/// <param name="edtsSystem">An EDTS system/location to convert.</param>
public Coordinates(Edts.StarSystem edtsSystem)
=> (this.X, this.Y, this.Z, this.Precision)
= ((int)edtsSystem.Position.X, (int)edtsSystem.Position.Y, (int)edtsSystem.Position.Z, (int)edtsSystem.Uncertainty);
/// <summary>
/// Gets the x coordinate.
@ -79,15 +80,15 @@ namespace alterNERDtive.Edna
/// </summary>
public int Precision { get; }
public static bool operator ==(Location a, Location b)
public static bool operator ==(Coordinates a, Coordinates b)
=> a.X == b.X && a.Y == b.Y && a.Z == b.Z && a.Precision == 0 && b.Precision == 0;
public static bool operator !=(Location a, Location b)
public static bool operator !=(Coordinates a, Coordinates b)
=> !(a == b);
/// <inheritdoc/>
public override bool Equals(object o)
=> o is Location location && this == location;
=> o is Coordinates location && this == location;
/// <inheritdoc/>
public override int GetHashCode()
@ -100,7 +101,7 @@ namespace alterNERDtive.Edna
/// </summary>
/// <param name="location">The other location.</param>
/// <returns>The distance between both locations.</returns>
public Distance DistanceTo(Location location)
public Distance DistanceTo(Coordinates location)
{
if (this == location && this.Precision == 0)
{
@ -173,7 +174,7 @@ namespace alterNERDtive.Edna
/// <summary>
/// Gets the objects location in the galaxy.
/// </summary>
public Location Coordinates { get; private set; }
public Coordinates Coordinates { get; private set; }
/// <summary>
/// The distance to another Locatable object.
@ -190,7 +191,7 @@ namespace alterNERDtive.Edna
/// </summary>
/// <param name="location">The Location to compare to.</param>
/// <returns>The distance to said Location.</returns>
public Distance DistanceTo(Location location)
public Distance DistanceTo(Coordinates location)
{
return this.Coordinates.DistanceTo(location);
}

View file

@ -40,7 +40,7 @@ namespace Test.Edna
{
Distance distance;
distance = new Location(0, 0, 0).DistanceTo(new Location(10, 10, 10));
distance = new Coordinates(0, 0, 0).DistanceTo(new Coordinates(10, 10, 10));
Assert.Equal(expected: Math.Round(17.3205080756888, 4), actual: Math.Round(distance.Value, 4));
Assert.Equal(expected: 0, actual: distance.Precision);
}

View file

@ -38,8 +38,8 @@ namespace Test.Edna
[Fact]
public void ZeroLocationEquals()
{
Assert.Equal(new Location(0, 0, 0), new Location(0, 0, 0));
Assert.Equal(new Location(0, 0, 0), new Location(0, 0, 0, 0));
Assert.Equal(new Coordinates(0, 0, 0), new Coordinates(0, 0, 0));
Assert.Equal(new Coordinates(0, 0, 0), new Coordinates(0, 0, 0, 0));
}
/// <summary>
@ -49,14 +49,14 @@ namespace Test.Edna
[Fact]
public void NotEqualIfPrecisionDifferent()
{
Assert.NotEqual(new Location(0, 0, 0), new Location(0, 0, 0, 1));
Assert.NotEqual(new Location(0, 0, 0, 0), new Location(0, 0, 0, 1));
Assert.NotEqual(new Coordinates(0, 0, 0), new Coordinates(0, 0, 0, 1));
Assert.NotEqual(new Coordinates(0, 0, 0, 0), new Coordinates(0, 0, 0, 1));
Assert.NotEqual(new Location(1, 2, 3), new Location(1, 2, 3, 1));
Assert.NotEqual(new Location(1, 2, 3, 0), new Location(1, 2, 3, 1));
Assert.NotEqual(new Coordinates(1, 2, 3), new Coordinates(1, 2, 3, 1));
Assert.NotEqual(new Coordinates(1, 2, 3, 0), new Coordinates(1, 2, 3, 1));
Assert.NotEqual(new Location(1.1, 2.2, 3.3), new Location(1.1, 2.2, 3.3, 1));
Assert.NotEqual(new Location(1.1, 2.2, 3.3, 0), new Location(1.1, 2.2, 3.3, 1));
Assert.NotEqual(new Coordinates(1.1, 2.2, 3.3), new Coordinates(1.1, 2.2, 3.3, 1));
Assert.NotEqual(new Coordinates(1.1, 2.2, 3.3, 0), new Coordinates(1.1, 2.2, 3.3, 1));
}
/// <summary>
@ -66,8 +66,8 @@ namespace Test.Edna
[Fact]
public void NotEqualIfSameImprecision()
{
Assert.NotEqual(new Location(0, 0, 0, 5), new Location(0, 0, 0, 5));
Assert.NotEqual(new Location(1, 2, 3, 5), new Location(1, 2, 3, 5));
Assert.NotEqual(new Coordinates(0, 0, 0, 5), new Coordinates(0, 0, 0, 5));
Assert.NotEqual(new Coordinates(1, 2, 3, 5), new Coordinates(1, 2, 3, 5));
}
}
}

View file

@ -35,11 +35,11 @@ namespace Test.Edna
{
Distance distance;
distance = StarSystem.Find("Sol").DistanceTo(new Location(0, 0, 0));
distance = StarSystem.Find("Sol").DistanceTo(new Coordinates(0, 0, 0));
Assert.Equal(expected: 0, actual: distance.Value);
Assert.Equal(expected: 0, actual: distance.Precision);
distance = StarSystem.Find("Sol").DistanceTo(new Location(0, 0, 0, 0));
distance = StarSystem.Find("Sol").DistanceTo(new Coordinates(0, 0, 0, 0));
Assert.Equal(expected: 0, actual: distance.Value);
Assert.Equal(expected: 0, actual: distance.Precision);
}