// Copyright (C) Stichting Deltares 2024. 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 for pure X,Z coors, to be used in calculation
///
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Point2D : IComparable, IGeometryObject
{
///
/// Initializes a new instance of the class.
///
public Point2D() {}
///
/// Initializes a new instance of the class.
///
/// The x.
/// The z.
public Point2D(double x, double z)
{
X = x;
Z = z;
}
///
/// The x
///
public double X { get; set; }
///
/// The z
///
public double Z { get; set; }
public string Name { get; set; }
///
/// Determines whether the location of the given point and this one are the same.
///
/// The other.
///
public bool LocationEquals(Point2D other)
{
return LocationEquals(other, GeometryConstants.Accuracy);
}
///
/// 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(Point2D 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);
}
///
/// Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
///
/// An object to compare with this instance.
///
/// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the sort order as . Greater than zero This instance follows in the sort order.
///
public int CompareTo(object obj)
{
var point = obj as Point2D;
if (point != null)
{
return X.CompareTo(point.X);
}
return String.Compare(ToString(), obj.ToString(), StringComparison.Ordinal);
}
}