// Copyright © Joerg Battermann 2014, Matt Hunt 2017 using System; using GeoJSON.Text.Converters; using System.Collections.Generic; using System.Text.Json.Serialization; namespace GeoJSON.Text.Geometry { /// /// Defines the Point type. /// In geography, a point refers to a Position on a map, expressed in latitude and longitude. /// /// /// See https://tools.ietf.org/html/rfc7946#section-3.1.2 /// public class Point : GeoJSONObject, IGeometryObject, IEqualityComparer, IEquatable { public Point() { } /// /// Initializes a new instance of the class. /// /// The Position. public Point(IPosition coordinates) { Coordinates = coordinates ?? throw new ArgumentNullException(nameof(coordinates)); } [JsonPropertyName("type")] [JsonIgnore(Condition = JsonIgnoreCondition.Never)] public override GeoJSONObjectType Type => GeoJSONObjectType.Point; /// /// The underlying this point. /// [JsonPropertyName("coordinates")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] [JsonConverter(typeof(PositionConverter))] public IPosition Coordinates { get; set; } #region IEqualityComparer, IEquatable /// /// Determines whether the specified object is equal to the current object /// public override bool Equals(object obj) { return Equals(this, obj as Point); } /// /// Determines whether the specified object is equal to the current object /// public bool Equals(Point other) { return Equals(this, other); } /// /// Determines whether the specified object instances are considered equal /// public bool Equals(Point left, Point right) { if (base.Equals(left, right)) { return left.Coordinates.Equals(right.Coordinates); } return false; } /// /// Determines whether the specified object instances are considered equal /// public static bool operator ==(Point left, Point right) { if (ReferenceEquals(left, right)) { return true; } if (ReferenceEquals(null, right)) { return false; } return left != null && left.Equals(right); } /// /// Determines whether the specified object instances are not considered equal /// public static bool operator !=(Point left, Point right) { return !(left == right); } /// /// Returns the hash code for this instance /// public override int GetHashCode() { int hash = base.GetHashCode(); hash = (hash * 397) ^ Coordinates.GetHashCode(); return hash; } /// /// Returns the hash code for the specified object /// public int GetHashCode(Point other) { return other.GetHashCode(); } #endregion } }