-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathPoint.cs
More file actions
181 lines (155 loc) · 4.35 KB
/
Point.cs
File metadata and controls
181 lines (155 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// -----------------------------------------------------------------------
// <copyright file="Point.cs" company="">
// Triangle.NET Copyright (c) 2012-2022 Christian Woltering
// </copyright>
// -----------------------------------------------------------------------
namespace TriangleNet.Geometry
{
using System;
using System.Diagnostics;
/// <summary>
/// Represents a 2D point.
/// </summary>
#if USE_Z
[DebuggerDisplay("ID {ID} [{X}, {Y}, {Z}]")]
#else
[DebuggerDisplay("ID {ID} [{X}, {Y}]")]
#endif
public class Point : IComparable<Point>, IEquatable<Point>
{
internal int id;
internal int label;
internal double x;
internal double y;
#if USE_Z
internal double z;
#endif
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class.
/// </summary>
public Point()
: this(0.0, 0.0, 0)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
public Point(double x, double y)
: this(x, y, 0)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="Point" /> class.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="label">The point label.</param>
public Point(double x, double y, int label)
{
this.x = x;
this.y = y;
this.label = label;
}
#region Public properties
/// <summary>
/// Gets or sets the vertex id.
/// </summary>
public int ID
{
get { return id; }
set { id = value; }
}
/// <summary>
/// Gets or sets the vertex x coordinate.
/// </summary>
public double X
{
get { return x; }
set { x = value; }
}
/// <summary>
/// Gets or sets the vertex y coordinate.
/// </summary>
public double Y
{
get { return y; }
set { y = value; }
}
#if USE_Z
/// <summary>
/// Gets or sets the vertex z coordinate.
/// </summary>
public double Z
{
get { return z; }
set { z = value; }
}
#endif
/// <summary>
/// Gets or sets a general-purpose label.
/// </summary>
/// <remarks>
/// This is used for the vertex boundary mark.
/// </remarks>
public int Label
{
get { return label; }
set { label = value; }
}
#endregion
#region Overriding Equals() and == Operator
/// <inheritdoc />
public static bool operator ==(Point a, Point b)
{
if (a is null)
{
// If one is null, but not both, return false.
return b is null;
}
// If both are same instance, return true.
if (ReferenceEquals(a, b))
{
return true;
}
return a.Equals(b);
}
/// <inheritdoc />
public static bool operator !=(Point a, Point b)
{
return !(a == b);
}
/// <inheritdoc />
public override bool Equals(object obj) => Equals(obj as Point);
/// <inheritdoc />
public bool Equals(Point p)
{
// If object is null return false.
if (p is null)
{
return false;
}
// Return true if the fields match.
return (x == p.x) && (y == p.y);
}
#endregion
/// <inheritdoc />
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;
}
/// <inheritdoc />
public override int GetHashCode()
{
int hash = 19;
hash = hash * 31 + x.GetHashCode();
hash = hash * 31 + y.GetHashCode();
return hash;
}
}
}