Location
→ Coordinates
This commit is contained in:
parent
de5848b69d
commit
7de48c5c78
5 changed files with 30 additions and 29 deletions
|
@ -50,6 +50,6 @@ namespace alterNERDtive.Edna
|
||||||
|
|
||||||
public StarSystem StarSystem { get; private set; }
|
public StarSystem StarSystem { get; private set; }
|
||||||
|
|
||||||
public new Location Coordinates { get; private set; }
|
public new Coordinates Coordinates { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,33 +30,34 @@ namespace alterNERDtive.Edna
|
||||||
/// precision (all in ly).
|
/// precision (all in ly).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Either this or wrong class/struct order 🤷")]
|
[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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Location"/> struct.
|
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The x coordinate.</param>
|
/// <param name="x">The x coordinate.</param>
|
||||||
/// <param name="y">The y coordinate.</param>
|
/// <param name="y">The y coordinate.</param>
|
||||||
/// <param name="z">The z coordinate.</param>
|
/// <param name="z">The z coordinate.</param>
|
||||||
/// <param name="precision">The available precision.</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);
|
=> (this.X, this.Y, this.Z, this.Precision) = (x, y, z, precision);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Location"/> struct.
|
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="x">The x coordinate.</param>
|
/// <param name="x">The x coordinate.</param>
|
||||||
/// <param name="y">The y coordinate.</param>
|
/// <param name="y">The y coordinate.</param>
|
||||||
/// <param name="z">The z 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);
|
=> (this.X, this.Y, this.Z, this.Precision) = (x, y, z, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="Location"/> struct.
|
/// Initializes a new instance of the <see cref="Coordinates"/> struct.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">An EDTS Location to convert.</param>
|
/// <param name="edtsSystem">An EDTS system/location to convert.</param>
|
||||||
public Location(Edts.Location location)
|
public Coordinates(Edts.StarSystem edtsSystem)
|
||||||
=> (this.X, this.Y, this.Z, this.Precision) = (location.X, location.Y, location.Z, location.Precision);
|
=> (this.X, this.Y, this.Z, this.Precision)
|
||||||
|
= ((int)edtsSystem.Position.X, (int)edtsSystem.Position.Y, (int)edtsSystem.Position.Z, (int)edtsSystem.Uncertainty);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the x coordinate.
|
/// Gets the x coordinate.
|
||||||
|
@ -79,15 +80,15 @@ namespace alterNERDtive.Edna
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Precision { get; }
|
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;
|
=> 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);
|
=> !(a == b);
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Equals(object o)
|
public override bool Equals(object o)
|
||||||
=> o is Location location && this == location;
|
=> o is Coordinates location && this == location;
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
|
@ -100,7 +101,7 @@ namespace alterNERDtive.Edna
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">The other location.</param>
|
/// <param name="location">The other location.</param>
|
||||||
/// <returns>The distance between both locations.</returns>
|
/// <returns>The distance between both locations.</returns>
|
||||||
public Distance DistanceTo(Location location)
|
public Distance DistanceTo(Coordinates location)
|
||||||
{
|
{
|
||||||
if (this == location && this.Precision == 0)
|
if (this == location && this.Precision == 0)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +174,7 @@ namespace alterNERDtive.Edna
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the object’s location in the galaxy.
|
/// Gets the object’s location in the galaxy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Coordinates { get; private set; }
|
public Coordinates Coordinates { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The distance to another Locatable object.
|
/// The distance to another Locatable object.
|
||||||
|
@ -190,7 +191,7 @@ namespace alterNERDtive.Edna
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">The Location to compare to.</param>
|
/// <param name="location">The Location to compare to.</param>
|
||||||
/// <returns>The distance to said Location.</returns>
|
/// <returns>The distance to said Location.</returns>
|
||||||
public Distance DistanceTo(Location location)
|
public Distance DistanceTo(Coordinates location)
|
||||||
{
|
{
|
||||||
return this.Coordinates.DistanceTo(location);
|
return this.Coordinates.DistanceTo(location);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace Test.Edna
|
||||||
{
|
{
|
||||||
Distance distance;
|
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: Math.Round(17.3205080756888, 4), actual: Math.Round(distance.Value, 4));
|
||||||
Assert.Equal(expected: 0, actual: distance.Precision);
|
Assert.Equal(expected: 0, actual: distance.Precision);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ namespace Test.Edna
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ZeroLocationEquals()
|
public void ZeroLocationEquals()
|
||||||
{
|
{
|
||||||
Assert.Equal(new Location(0, 0, 0), new Location(0, 0, 0));
|
Assert.Equal(new Coordinates(0, 0, 0), new Coordinates(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, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -49,14 +49,14 @@ namespace Test.Edna
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotEqualIfPrecisionDifferent()
|
public void NotEqualIfPrecisionDifferent()
|
||||||
{
|
{
|
||||||
Assert.NotEqual(new Location(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 Location(0, 0, 0, 0), new Location(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 Coordinates(1, 2, 3), new Coordinates(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, 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 Coordinates(1.1, 2.2, 3.3), new Coordinates(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, 0), new Coordinates(1.1, 2.2, 3.3, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -66,8 +66,8 @@ namespace Test.Edna
|
||||||
[Fact]
|
[Fact]
|
||||||
public void NotEqualIfSameImprecision()
|
public void NotEqualIfSameImprecision()
|
||||||
{
|
{
|
||||||
Assert.NotEqual(new Location(0, 0, 0, 5), new Location(0, 0, 0, 5));
|
Assert.NotEqual(new Coordinates(0, 0, 0, 5), new Coordinates(0, 0, 0, 5));
|
||||||
Assert.NotEqual(new Location(1, 2, 3, 5), new Location(1, 2, 3, 5));
|
Assert.NotEqual(new Coordinates(1, 2, 3, 5), new Coordinates(1, 2, 3, 5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,11 @@ namespace Test.Edna
|
||||||
{
|
{
|
||||||
Distance distance;
|
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.Value);
|
||||||
Assert.Equal(expected: 0, actual: distance.Precision);
|
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.Value);
|
||||||
Assert.Equal(expected: 0, actual: distance.Precision);
|
Assert.Equal(expected: 0, actual: distance.Precision);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue