Skip to content

Commit

Permalink
Created world coordinate model.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Jul 26, 2024
1 parent 0686b04 commit 4deb566
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/Weatherstack/WorldCoordinate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

using Weatherstack.Annotations.Suppression;

namespace Weatherstack;

/// <summary>
/// Represents a coordinate in the world.
/// </summary>
public struct WorldCoordinate
: IEquatable<WorldCoordinate>
{
/// <summary>
/// Gets or sets the latitude of the coordinate.
/// </summary>
[JsonPropertyName("lat")]
public double Latitude { get; set; }

/// <summary>
/// Gets or sets the longitude of the coordinate.
/// </summary>
[JsonPropertyName("lon")]
public double Longitude { get; set; }

/// <inheritdoc/>
[SuppressMessage(
category: "Style",
checkId: "IDE0046",
Justification = Justifications.GuardClausesShouldNotBeTerse)]
public override bool Equals(object obj)

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).

Check failure on line 31 in src/Weatherstack/WorldCoordinate.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of type of parameter 'obj' doesn't match overridden member (possibly because of nullability attributes).
{
if (obj is not WorldCoordinate other)
return false;

return Equals(other);
}

public bool Equals(WorldCoordinate other) => Latitude == other.Latitude
&& Longitude == other.Longitude;

/// <inheritdoc/>
public override int GetHashCode()
{
#if NET6_0_OR_GREATER

return HashCode.Combine(Latitude, Longitude);

#else

return 17
* 23 + Latitude.GetHashCode()
* 23 + Longitude.GetHashCode();

#endif
}

public static bool operator ==(WorldCoordinate left, WorldCoordinate right) =>
left.Equals(right);

public static bool operator !=(WorldCoordinate left, WorldCoordinate right) =>
!left.Equals(right);
}

0 comments on commit 4deb566

Please sign in to comment.