Skip to content

Commit

Permalink
Merge pull request #81 from Franz1960/LatLngBoundsLiteral_Extend
Browse files Browse the repository at this point in the history
Added several convenience methods to LatLngBoundsLiteral.
  • Loading branch information
valentasm1 authored Dec 22, 2020
2 parents 9005c6a + 6643803 commit e9b197f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,4 @@ ASALocalRun/
.mfractor/
GoogleMapsComponents/.vscode/*
.gitignore
.vscode
66 changes: 66 additions & 0 deletions GoogleMapsComponents/Maps/Coordinates/LatLngBoundsLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ namespace GoogleMapsComponents.Maps
/// </summary>
public class LatLngBoundsLiteral
{
/// <summary>
/// Default constructor. Set East, North, South and West explicitely because here they are initialized to zero.
/// </summary>
public LatLngBoundsLiteral() {
}

/// <summary>
/// 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.
/// </summary>
public LatLngBoundsLiteral(LatLngLiteral latLng1,LatLngLiteral latLng2=null) {
East=latLng1.Lng;
West=latLng1.Lng;
South=latLng1.Lat;
North=latLng1.Lat;
if (latLng2!=null) {
Extend(latLng2);
}
}

/// <summary>
/// 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.
/// </summary>
public static void CreateOrExtend(ref LatLngBoundsLiteral latLngBoundsLiteral,LatLngLiteral latLng) {
if (latLngBoundsLiteral == null) {
latLngBoundsLiteral = new LatLngBoundsLiteral(latLng);
} else {
latLngBoundsLiteral.Extend(latLng);
}
}

/// <summary>
/// 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.
Expand Down Expand Up @@ -42,6 +76,38 @@ public class LatLngBoundsLiteral
/// </summary>
public double West { get; set; }

/// <summary>
/// Extend these boundaries by a given coordinate point.
/// </summary>
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;
}
}

/// <summary>
/// Extend these boundaries by a given coordinate point.
/// </summary>
public void Extend(LatLngLiteral latLng) {
Extend(latLng.Lng,latLng.Lat);
}

/// <summary>
/// Is the area zero?
/// </summary>
public bool IsEmpty() {
return (West == East || South == North);
}

public override string ToString()
{
return $"{North} {East} {South} {West}";
Expand Down

0 comments on commit e9b197f

Please sign in to comment.