diff --git a/src/Nest/QueryDsl/Geo/GeoLocation.cs b/src/Nest/QueryDsl/Geo/GeoLocation.cs index 6307c86cf70..105feb255fb 100644 --- a/src/Nest/QueryDsl/Geo/GeoLocation.cs +++ b/src/Nest/QueryDsl/Geo/GeoLocation.cs @@ -18,18 +18,8 @@ public class GeoLocation : IEquatable, IFormattable /// /// Represents a Latitude/Longitude as a 2 dimensional point. /// - /// Value between -90 and 90 - /// Value between -180 and 180 - /// If or are invalid public GeoLocation(double latitude, double longitude) { - if (!IsValidLatitude(latitude)) - throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, - "Invalid latitude '{0}'. Valid values are between -90 and 90", latitude)); - if (!IsValidLongitude(longitude)) - throw new ArgumentOutOfRangeException(string.Format(CultureInfo.InvariantCulture, - "Invalid longitude '{0}'. Valid values are between -180 and 180", longitude)); - Latitude = latitude; Longitude = longitude; } @@ -62,14 +52,14 @@ public bool Equals(GeoLocation other) public string ToString(string format, IFormatProvider formatProvider) => ToString(); /// - /// True if is a valid latitude. Otherwise false. + /// Checks if is a valid latitude between -90 and 90, inclusive. /// /// /// public static bool IsValidLatitude(double latitude) => latitude >= -90 && latitude <= 90; /// - /// True if is a valid longitude. Otherwise false. + /// Checks if is a valid longitude between -180 and 180, inclusive. /// /// /// @@ -77,20 +67,12 @@ public bool Equals(GeoLocation other) /// /// Try to create a . - /// Return - /// null - /// if either or are invalid. /// - /// Value between -90 and 90 - /// Value between -180 and 180 + /// + /// /// - public static GeoLocation TryCreate(double latitude, double longitude) - { - if (IsValidLatitude(latitude) && IsValidLongitude(longitude)) - return new GeoLocation(latitude, longitude); - - return null; - } + // TODO: Remove in 8.0 as without bounds checks, provides no value + public static GeoLocation TryCreate(double latitude, double longitude) => new GeoLocation(latitude, longitude); public override string ToString() => Latitude.ToString("#0.0#######", CultureInfo.InvariantCulture) + "," + @@ -157,6 +139,8 @@ public GeoCoordinate(double latitude, double longitude, double z) : base(latitud /// /// Creates a new instance of from an array /// of 2 or 3 doubles, in the order Latitude, Longitude, and optional Z value. + /// Returns null if coordinates are null + /// If the array does not contain 2 or 3 values /// public static implicit operator GeoCoordinate(double[] coordinates) { @@ -168,11 +152,11 @@ public static implicit operator GeoCoordinate(double[] coordinates) return new GeoCoordinate(coordinates[0], coordinates[1]); case 3: return new GeoCoordinate(coordinates[0], coordinates[1], coordinates[2]); + default: + throw new ArgumentOutOfRangeException( + nameof(coordinates), + $"Cannot create a {nameof(GeoCoordinate)} from an array that does not contain 2 or 3 values"); } - - throw new ArgumentOutOfRangeException( - nameof(coordinates), - $"Cannot create a {nameof(GeoCoordinate)} from an array that does not contain 2 or 3 values"); } } }