diff --git a/MapControl/Shared/AzimuthalEquidistantProjection.cs b/MapControl/Shared/AzimuthalEquidistantProjection.cs index 52027047..06f38874 100644 --- a/MapControl/Shared/AzimuthalEquidistantProjection.cs +++ b/MapControl/Shared/AzimuthalEquidistantProjection.cs @@ -28,8 +28,7 @@ namespace MapControl public override Point? LocationToMap(double latitude, double longitude) { - if (Location.Equals(latitude, Center.Latitude) && - Location.Equals(longitude, Center.Longitude)) + if (Center.Equals(latitude, longitude)) { return new Point(); } diff --git a/MapControl/Shared/GnomonicProjection.cs b/MapControl/Shared/GnomonicProjection.cs index 5013e35c..8e5628cd 100644 --- a/MapControl/Shared/GnomonicProjection.cs +++ b/MapControl/Shared/GnomonicProjection.cs @@ -28,8 +28,7 @@ namespace MapControl public override Point? LocationToMap(double latitude, double longitude) { - if (Location.Equals(latitude, Center.Latitude) && - Location.Equals(longitude, Center.Longitude)) + if (Center.Equals(latitude, longitude)) { return new Point(); } diff --git a/MapControl/Shared/Location.cs b/MapControl/Shared/Location.cs index 74f1a47a..150f6853 100644 --- a/MapControl/Shared/Location.cs +++ b/MapControl/Shared/Location.cs @@ -30,32 +30,15 @@ namespace MapControl public double Latitude { get; } public double Longitude { get; } - public bool Equals(Location location) - { - return location != null && - Equals(Latitude, location.Latitude) && - Equals(Longitude, location.Longitude); - } + public bool Equals(double latitude, double longitude) => Latitude == latitude && Longitude == longitude; - public override bool Equals(object obj) - { - return Equals(obj as Location); - } + public bool Equals(Location location) => location != null && Equals(location.Latitude, location.Longitude); - public override int GetHashCode() - { - return Latitude.GetHashCode() ^ Longitude.GetHashCode(); - } + public override bool Equals(object obj) => Equals(obj as Location); - public override string ToString() - { - return string.Format(CultureInfo.InvariantCulture, "{0},{1}", Latitude, Longitude); - } + public override int GetHashCode() => Latitude.GetHashCode() ^ Longitude.GetHashCode(); - public static bool CoordinateEquals(double coordinate1, double coordinate2) - { - return Math.Abs(coordinate1 - coordinate2) < 1e-9; - } + public override string ToString() => string.Format(CultureInfo.InvariantCulture, "{0:0.########},{1:0.########}", Latitude, Longitude); /// /// Creates a Location instance from a string containing a comma-separated pair of floating point numbers. @@ -66,7 +49,7 @@ namespace MapControl if (!string.IsNullOrEmpty(location)) { - values = location.Split(new char[] { ',' }); + values = location.Split([',']); } if (values?.Length != 2) diff --git a/MapControl/Shared/OrthographicProjection.cs b/MapControl/Shared/OrthographicProjection.cs index 3a764ef5..3ace6910 100644 --- a/MapControl/Shared/OrthographicProjection.cs +++ b/MapControl/Shared/OrthographicProjection.cs @@ -28,8 +28,7 @@ namespace MapControl public override Point? LocationToMap(double latitude, double longitude) { - if (Location.Equals(latitude, Center.Latitude) && - Location.Equals(longitude, Center.Longitude)) + if (Center.Equals(latitude, longitude)) { return new Point(); } diff --git a/MapControl/Shared/StereographicProjection.cs b/MapControl/Shared/StereographicProjection.cs index ef3e396d..083a0c29 100644 --- a/MapControl/Shared/StereographicProjection.cs +++ b/MapControl/Shared/StereographicProjection.cs @@ -28,8 +28,7 @@ namespace MapControl public override Point? LocationToMap(double latitude, double longitude) { - if (Location.Equals(latitude, Center.Latitude) && - Location.Equals(longitude, Center.Longitude)) + if (Center.Equals(latitude, longitude)) { return new Point(); } diff --git a/MapControl/Shared/TileImageLoader.cs b/MapControl/Shared/TileImageLoader.cs index 559a1b57..a620b5fa 100644 --- a/MapControl/Shared/TileImageLoader.cs +++ b/MapControl/Shared/TileImageLoader.cs @@ -180,7 +180,7 @@ namespace MapControl { var extension = Path.GetExtension(uri.LocalPath).ToLower(); - if (string.IsNullOrEmpty(extension) || extension.Equals(".jpeg")) + if (string.IsNullOrEmpty(extension) || extension == ".jpeg") { extension = ".jpg"; } diff --git a/MapControl/Shared/Wgs84UtmProjection.cs b/MapControl/Shared/Wgs84UtmProjection.cs index ed393b58..7f0a8151 100644 --- a/MapControl/Shared/Wgs84UtmProjection.cs +++ b/MapControl/Shared/Wgs84UtmProjection.cs @@ -49,17 +49,16 @@ namespace MapControl { public const string DefaultCrsId = "AUTO2:42001"; - private readonly string autoCrsId; + public Wgs84AutoUtmProjection() + : this(DefaultCrsId) + { + // XAML needs parameterless constructor + } - public Wgs84AutoUtmProjection(string crsId = DefaultCrsId) + public Wgs84AutoUtmProjection(string crsId) : base(31, true) { - autoCrsId = crsId; - - if (!string.IsNullOrEmpty(autoCrsId)) - { - CrsId = autoCrsId; - } + CrsId = crsId; } public override Location Center @@ -77,12 +76,9 @@ namespace MapControl if (Zone != zone || IsNorth != north) { + var crsId = CrsId; SetZone(zone, north); - - if (!string.IsNullOrEmpty(autoCrsId)) - { - CrsId = autoCrsId; - } + CrsId = crsId; } } } diff --git a/MapControl/WinUI/Point.WinUI.cs b/MapControl/WinUI/Point.WinUI.cs index 8a0cf7bf..2c4e3f51 100644 --- a/MapControl/WinUI/Point.WinUI.cs +++ b/MapControl/WinUI/Point.WinUI.cs @@ -1,47 +1,27 @@ -namespace MapControl +using System; + +namespace MapControl { /// /// Replaces Windows.Foundation.Point for double floating point precision. /// - public readonly struct Point + public readonly struct Point(double x, double y) : IEquatable { - public Point(double x, double y) - { - X = x; - Y = y; - } + public double X => x; + public double Y => y; - public double X { get; } - public double Y { get; } + public static implicit operator Windows.Foundation.Point(Point p) => new(p.X, p.Y); - public static implicit operator Windows.Foundation.Point(Point p) - { - return new Windows.Foundation.Point(p.X, p.Y); - } + public static implicit operator Point(Windows.Foundation.Point p) => new(p.X, p.Y); - public static implicit operator Point(Windows.Foundation.Point p) - { - return new Point(p.X, p.Y); - } + public static bool operator ==(Point p1, Point p2) => p1.Equals(p2); - public static bool operator ==(Point p1, Point p2) - { - return p1.X == p2.X && p1.Y == p2.Y; - } + public static bool operator !=(Point p1, Point p2) => !p1.Equals(p2); - public static bool operator !=(Point p1, Point p2) - { - return !(p1 == p2); - } + public bool Equals(Point p) => X == p.X && Y == p.Y; - public override bool Equals(object obj) - { - return obj is Point p && this == p; - } + public override bool Equals(object obj) => obj is Point p && Equals(p); - public override int GetHashCode() - { - return X.GetHashCode() ^ Y.GetHashCode(); - } + public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode(); } } diff --git a/MapControl/WinUI/Rect.WinUI.cs b/MapControl/WinUI/Rect.WinUI.cs index 79f4743a..4596d449 100644 --- a/MapControl/WinUI/Rect.WinUI.cs +++ b/MapControl/WinUI/Rect.WinUI.cs @@ -5,7 +5,7 @@ namespace MapControl /// /// Replaces Windows.Foundation.Rect for double floating point precision. /// - public readonly struct Rect + public readonly struct Rect : IEquatable { public Rect(double x, double y, double width, double height) { @@ -28,19 +28,20 @@ namespace MapControl public double Width { get; } public double Height { get; } - public bool Contains(Point p) - { - return p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height; - } + public static implicit operator Windows.Foundation.Rect(Rect r) => new(r.X, r.Y, r.Width, r.Height); - public static implicit operator Windows.Foundation.Rect(Rect r) - { - return new Windows.Foundation.Rect(r.X, r.Y, r.Width, r.Height); - } + public static implicit operator Rect(Windows.Foundation.Rect r) => new(r.X, r.Y, r.Width, r.Height); - public static implicit operator Rect(Windows.Foundation.Rect r) - { - return new Rect(r.X, r.Y, r.Width, r.Height); - } + public static bool operator ==(Rect r1, Rect r2) => r1.Equals(r2); + + public static bool operator !=(Rect r1, Rect r2) => !r1.Equals(r2); + + public bool Equals(Rect r) => X == r.X && Y == r.Y && Width == r.Width && Height == r.Height; + + public override bool Equals(object obj) => obj is Rect r && Equals(r); + + public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode() ^ Width.GetHashCode() ^ Height.GetHashCode(); + + public bool Contains(Point p) => p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height; } }