| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure.Core.GeoJson |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// |
| | 10 | | /// </summary> |
| | 11 | | public readonly struct GeoPosition |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Gets the altitude of the position. |
| | 15 | | /// </summary> |
| 1102 | 16 | | public double? Altitude { get; } |
| | 17 | |
|
| | 18 | | /// <summary> |
| | 19 | | /// Gets the longitude of the position. |
| | 20 | | /// </summary> |
| 850 | 21 | | public double Longitude { get; } |
| | 22 | |
|
| | 23 | | /// <summary> |
| | 24 | | /// Gets the latitude of the position. |
| | 25 | | /// </summary> |
| 850 | 26 | | public double Latitude { get; } |
| | 27 | |
|
| | 28 | | /// <summary> |
| | 29 | | /// Initializes a new instance of <see cref="GeoPosition"/>. |
| | 30 | | /// </summary> |
| | 31 | | /// <param name="longitude">The longitude of the position.</param> |
| | 32 | | /// <param name="latitude">The latitude of the position.</param> |
| 98 | 33 | | public GeoPosition(double longitude, double latitude) : this(longitude, latitude, null) |
| | 34 | | { |
| 98 | 35 | | } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Initializes a new instance of <see cref="GeoPosition"/>. |
| | 39 | | /// </summary> |
| | 40 | | /// <param name="longitude">The longitude of the position.</param> |
| | 41 | | /// <param name="latitude">The latitude of the position.</param> |
| | 42 | | /// <param name="altitude">The altitude of the position.</param> |
| | 43 | | public GeoPosition(double longitude, double latitude, double? altitude) |
| | 44 | | { |
| 866 | 45 | | Longitude = longitude; |
| 866 | 46 | | Latitude = latitude; |
| 866 | 47 | | Altitude = altitude; |
| 866 | 48 | | } |
| | 49 | |
|
| | 50 | |
|
| | 51 | | /// <inheritdoc /> |
| | 52 | | public bool Equals(GeoPosition other) |
| | 53 | | { |
| 168 | 54 | | return Nullable.Equals(Altitude, other.Altitude) && Longitude.Equals(other.Longitude) && Latitude.Equals(oth |
| | 55 | | } |
| | 56 | |
|
| | 57 | | /// <inheritdoc /> |
| | 58 | | public override bool Equals(object? obj) |
| | 59 | | { |
| 168 | 60 | | return obj is GeoPosition other && Equals(other); |
| | 61 | | } |
| | 62 | |
|
| | 63 | | /// <inheritdoc /> |
| 0 | 64 | | public override int GetHashCode() => HashCodeBuilder.Combine(Longitude, Latitude, Altitude); |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Determines whether two specified positions have the same value. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name="left">The first position to compare.</param> |
| | 70 | | /// <param name="right">The first position to compare.</param> |
| | 71 | | /// <returns><c>true</c> if the value of <c>left</c> is the same as the value of <c>b</c>; otherwise, <c>false</ |
| | 72 | | public static bool operator ==(GeoPosition left, GeoPosition right) |
| | 73 | | { |
| 0 | 74 | | return left.Equals(right); |
| | 75 | | } |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Determines whether two specified positions have the same value. |
| | 79 | | /// </summary> |
| | 80 | | /// <param name="left">The first position to compare.</param> |
| | 81 | | /// <param name="right">The first position to compare.</param> |
| | 82 | | /// <returns><c>false</c> if the value of <c>left</c> is the same as the value of <c>b</c>; otherwise, <c>true</ |
| | 83 | | public static bool operator !=(GeoPosition left, GeoPosition right) |
| | 84 | | { |
| 0 | 85 | | return !left.Equals(right); |
| | 86 | | } |
| | 87 | |
|
| | 88 | | /// <inheritdoc /> |
| | 89 | | public override string ToString() |
| | 90 | | { |
| 0 | 91 | | if (Altitude == null) |
| | 92 | | { |
| 0 | 93 | | return $"[{Longitude:G17}, {Latitude:G17}]"; |
| | 94 | | } |
| | 95 | |
|
| 0 | 96 | | return $"[{Longitude:G17}, {Latitude:G17}, {Altitude.Value:G17}]"; |
| | 97 | | } |
| | 98 | | } |
| | 99 | | } |