Changed struct Location to class

This commit is contained in:
ClemensFischer 2026-02-01 23:48:56 +01:00
parent 35820aa27e
commit 6429776853
11 changed files with 38 additions and 51 deletions

View file

@ -11,24 +11,20 @@ namespace MapControl
#else
[System.ComponentModel.TypeConverter(typeof(LocationConverter))]
#endif
public readonly struct Location(double latitude, double longitude) : IEquatable<Location>
public class Location(double latitude, double longitude) : IEquatable<Location>
{
public double Latitude { get; } = Math.Min(Math.Max(latitude, -90d), 90d);
public double Longitude => longitude;
public static bool operator ==(Location loc1, Location loc2) => loc1.Equals(loc2);
public static bool operator !=(Location loc1, Location loc2) => !loc1.Equals(loc2);
public bool LatitudeEquals(double latitude) => Math.Abs(Latitude - latitude) < 1e-9;
public bool LongitudeEquals(double longitude) => Math.Abs(Longitude - longitude) < 1e-9;
public bool Equals(double latitude, double longitude) => LatitudeEquals(latitude) && LongitudeEquals(longitude);
public bool Equals(Location location) => Equals(location.Latitude, location.Longitude);
public bool Equals(Location location) => location != null && Equals(location.Latitude, location.Longitude);
public override bool Equals(object obj) => obj is Location location && Equals(location);
public override bool Equals(object obj) => Equals(obj as Location);
public override int GetHashCode() => Latitude.GetHashCode() ^ Longitude.GetHashCode();