diff --git a/.gitignore b/.gitignore index e09d5d04..315720bd 100644 --- a/.gitignore +++ b/.gitignore @@ -330,3 +330,4 @@ ASALocalRun/ .mfractor/ GoogleMapsComponents/.vscode/* .gitignore +.vscode diff --git a/GoogleMapsComponents/Maps/Coordinates/LatLngBoundsLiteral.cs b/GoogleMapsComponents/Maps/Coordinates/LatLngBoundsLiteral.cs index dca2d710..31c9139e 100644 --- a/GoogleMapsComponents/Maps/Coordinates/LatLngBoundsLiteral.cs +++ b/GoogleMapsComponents/Maps/Coordinates/LatLngBoundsLiteral.cs @@ -11,6 +11,40 @@ namespace GoogleMapsComponents.Maps /// public class LatLngBoundsLiteral { + /// + /// Default constructor. Set East, North, South and West explicitely because here they are initialized to zero. + /// + public LatLngBoundsLiteral() { + } + + /// + /// Constructor with one or two given coordinate points. + /// If the second point is null, the bounds are set to the first point. + /// The points may be positioned arbitrarily. + /// + public LatLngBoundsLiteral(LatLngLiteral latLng1,LatLngLiteral latLng2=null) { + East=latLng1.Lng; + West=latLng1.Lng; + South=latLng1.Lat; + North=latLng1.Lat; + if (latLng2!=null) { + Extend(latLng2); + } + } + + /// + /// Create or extend a LatLngBoundsLiteral with a given coordinate point. + /// Using this method you can initialize a LatLngBoundsLiteral reference with null and call + /// subsequently this method to extend the boundaries by given points. + /// + public static void CreateOrExtend(ref LatLngBoundsLiteral latLngBoundsLiteral,LatLngLiteral latLng) { + if (latLngBoundsLiteral == null) { + latLngBoundsLiteral = new LatLngBoundsLiteral(latLng); + } else { + latLngBoundsLiteral.Extend(latLng); + } + } + /// /// East longitude in degrees. Values outside the range [-180, 180] will be wrapped to the range [-180, 180). /// For example, a value of -190 will be converted to 170. @@ -42,6 +76,38 @@ public class LatLngBoundsLiteral /// public double West { get; set; } + /// + /// Extend these boundaries by a given coordinate point. + /// + public void Extend(double lng, double lat) { + if (lng < West) { + West = lng; + } + if (lng > East) { + East = lng; + } + if (lat < South) { + South = lat; + } + if (lat > North) { + North = lat; + } + } + + /// + /// Extend these boundaries by a given coordinate point. + /// + public void Extend(LatLngLiteral latLng) { + Extend(latLng.Lng,latLng.Lat); + } + + /// + /// Is the area zero? + /// + public bool IsEmpty() { + return (West == East || South == North); + } + public override string ToString() { return $"{North} {East} {South} {West}";