// -----------------------------------------------------------------------
//
// Triangle.NET code by Christian Woltering, http://triangle.codeplex.com/
//
// -----------------------------------------------------------------------
namespace UnityEngine.U2D.Animation.TriangleNet
.Geometry
{
using System;
using System.Diagnostics;
///
/// Represents a 2D point.
///
#if USE_Z
[DebuggerDisplay("ID {ID} [{X}, {Y}, {Z}]")]
#else
[DebuggerDisplay("ID {ID} [{X}, {Y}]")]
#endif
internal class Point : IComparable, IEquatable
{
internal int id;
internal int label;
internal double x;
internal double y;
#if USE_Z
internal double z;
#endif
public Point()
: this(0.0, 0.0, 0)
{
}
public Point(double x, double y)
: this(x, y, 0)
{
}
public Point(double x, double y, int label)
{
this.x = x;
this.y = y;
this.label = label;
}
#region Public properties
///
/// Gets or sets the vertex id.
///
public int ID
{
get { return this.id; }
set { this.id = value; }
}
///
/// Gets or sets the vertex x coordinate.
///
public double X
{
get { return this.x; }
set { this.x = value; }
}
///
/// Gets or sets the vertex y coordinate.
///
public double Y
{
get { return this.y; }
set { this.y = value; }
}
#if USE_Z
///
/// Gets or sets the vertex z coordinate.
///
public double Z
{
get { return this.z; }
set { this.z = value; }
}
#endif
///
/// Gets or sets a general-purpose label.
///
///
/// This is used for the vertex boundary mark.
///
public int Label
{
get { return this.label; }
set { this.label = value; }
}
#endregion
#region Operator overloading / overriding Equals
// Compare "Guidelines for Overriding Equals() and Operator =="
// http://msdn.microsoft.com/en-us/library/ms173147.aspx
public static bool operator==(Point a, Point b)
{
// If both are null, or both are same instance, return true.
if (Object.ReferenceEquals(a, b))
{
return true;
}
// If one is null, but not both, return false.
if (((object)a == null) || ((object)b == null))
{
return false;
}
return a.Equals(b);
}
public static bool operator!=(Point a, Point b)
{
return !(a == b);
}
public override bool Equals(object obj)
{
// If parameter is null return false.
if (obj == null)
{
return false;
}
Point p = obj as Point;
if ((object)p == null)
{
return false;
}
return (x == p.x) && (y == p.y);
}
public bool Equals(Point p)
{
// If vertex is null return false.
if ((object)p == null)
{
return false;
}
// Return true if the fields match:
return (x == p.x) && (y == p.y);
}
#endregion
public int CompareTo(Point other)
{
if (x == other.x && y == other.y)
{
return 0;
}
return (x < other.x || (x == other.x && y < other.y)) ? -1 : 1;
}
public override int GetHashCode()
{
int hash = 19;
hash = hash * 31 + x.GetHashCode();
hash = hash * 31 + y.GetHashCode();
return hash;
}
}
}