// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser 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.Globalization;
namespace Core.Common.Base.Geometry
{
///
/// Defines a mathematical, immutable point in 3D Euclidean space.
///
public sealed class Point3D
{
///
/// Creates a new instance of .
///
/// The x-coordinate of the new .
/// The y-coordinate of the new .
/// The z-coordinate of the new .
public Point3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
///
/// Gets or sets the x coordinate.
///
public double X { get; }
///
/// Gets or sets the y coordinate.
///
public double Y { get; }
///
/// Gets or sets the z coordinate.
///
public double Z { get; }
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((Point3D) obj);
}
public override int GetHashCode()
{
unchecked
{
int hashCode = X.GetHashCode();
hashCode = (hashCode * 397) ^ Y.GetHashCode();
hashCode = (hashCode * 397) ^ Z.GetHashCode();
return hashCode;
}
}
public override string ToString()
{
return string.Format(CultureInfo.CurrentCulture,
"({0}, {1}, {2})",
X, Y, Z);
}
///
/// Compares the with based on , and .
///
/// A to compare with.
/// True if the coordinates of the matches the coordinate of . False otherwise.
private bool Equals(Point3D other)
{
return X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z);
}
}
}