// Copyright (C) Stichting Deltares 2023. All rights reserved. // // This file is part of the Dam Engine. // // The Dam Engine is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.ComponentModel; using Deltares.DamEngine.Data.Standard; namespace Deltares.DamEngine.Data.Geometry; /// /// Class to manage a geometry point. /// [Serializable] [TypeConverter(typeof(ExpandableObjectConverter))] public class GeometryPoint : GeometryObject, ICloneable, IComparable { /// /// The precision /// public const double Precision = GeometryConstants.Accuracy; private object owner; /// /// Initializes a new instance of the class. /// public GeometryPoint() : this(0.0, 0.0) {} /// /// Initializes a new instance of the class. /// /// A point. public GeometryPoint(GeometryPoint aPoint) : this(aPoint.X, aPoint.Z) {} /// /// Initializes a new instance of the class. /// /// A x. /// A z. public GeometryPoint(double aX, double aZ) { X = aX; Z = aZ; } /// /// Gets or sets the X coordinate of GeometryPoint /// public virtual double X { get; set; } /// /// Gets or sets the Y coordinate of GeometryPoint /// public virtual double Y { get; set; } /// /// Gets or sets the Z coordinate of GeometryPoint /// public virtual double Z { get; set; } /// /// Identifies the object which owns this point. /// /// /// Usually set by a delegated list, such as in . /// public object Owner { get { return owner; } set { owner = value; } } /// /// Determines whether the location of the given point and this one are the same. /// /// The other. /// public bool LocationEquals(GeometryPoint other) { return LocationEquals(other, Precision); } /// /// Determines whether the difference between the location of the given point and /// this one are within the given precision. /// /// The other. /// The precision. /// public bool LocationEquals(GeometryPoint other, double precision) { if (ReferenceEquals(other, null)) { return false; } if (ReferenceEquals(other, this)) { return true; } return X.AlmostEquals(other.X, precision) && Z.AlmostEquals(other.Z, precision); } /// /// Gets the geometry bounds. /// /// public override GeometryBounds GetGeometryBounds() { return new GeometryBounds(X, X, Z, Z); } /// /// Returns a that represents this instance. /// /// /// A that represents this instance. /// public override string ToString() { return "(" + X.ToString("F3") + ";" + Z.ToString("F3") + ")"; } #region ICloneable Members /// /// Clones this instance. /// /// Only copies and . public virtual object Clone() { return new GeometryPoint(this); } #endregion #region IComparable Members /// /// Compares the current instance with another object of the same type /// Eventhough this method does not seem to be used it is! (via GPstring which is a delegated list, using a Sort which needs this). /// So do NOT delete this as long as GPS stays a delegated list. /// /// An object to compare with this instance. /// /// Result of comparing the X values /// public int CompareTo(object obj) { var point = obj as GeometryPoint; if (point != null) { return X.CompareTo(point.X); } return ToString().CompareTo(obj.ToString()); } #endregion }