-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreeDPoint.cs
243 lines (207 loc) · 5.73 KB
/
ThreeDPoint.cs
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using System;
namespace MTF_Calc
{
//public partial class MainApp
//{
public class ThreeDPoint
{
#region Fields
/// <summary>
/// X coordinate
/// </summary>
private double x = 0.0;
/// <summary>
/// Y coordinate
/// </summary>
private double y = 0.0;
/// <summary>
/// Z coordinate
/// </summary>
private double z = 0.0;
#endregion // Fields
#region Properties
/// <summary>
/// X coordinate
/// </summary>
public double X
{
get
{
return this.x;
}
set
{
this.x = value;
}
}
/// <summary>
/// Y coordinate
/// </summary>
public double Y
{
get
{
return this.y;
}
set
{
this.y = value;
}
}
/// <summary>
/// Z coordinate
/// </summary>
public double Z
{
get
{
return this.z;
}
set
{
this.z = value;
}
}
#endregion // Properties
#region Constructors
/// <summary>
/// Constructor - Initializes x, y, z to 0.0
/// </summary>
public ThreeDPoint()
{
ZeroXYZ();
}
/// <summary>
/// Constructor - Initializes x, y, z to user-defined values
/// </summary>
/// <param name="x">X coordinate</param>
/// <param name="y">Y coordinate</param>
/// <param name="z">Z coordinate</param>
public ThreeDPoint(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
/// <summary>
/// Constructor - Initializes x, y, z from another ThreeDPoint
/// </summary>
/// <param name="point">ThreeDPoint</param>
public ThreeDPoint(ThreeDPoint point)
{
if (point != null)
{
this.x = point.X;
this.y = point.Y;
this.z = point.Z;
}
else
{
ZeroXYZ();
}
}
#endregion // Constructors
#region Operator Overloads
/// <summary>
/// Override to compare 2 ThreeDPoint objects
/// </summary>
/// <param name="obj">Object of type ThreeDPoint</param>
/// <returns>True if equal, else false</returns>
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
ThreeDPoint p = obj as ThreeDPoint;
if ((object)p == null)
{
return false;
}
return ((this.X == p.X) && (this.Y == p.Y) && (this.Z == p.Z));
}
/// <summary>
/// Override to compare 2 ThreeDPoint objects
/// </summary>
/// <param name="p">Object of type ThreeDPoint</param>
/// <returns>True if equal, else false</returns>
public bool Equals(ThreeDPoint p)
{
if ((object)p == null)
{
return false;
}
return ((this.X == p.X) && (this.Y == p.Y) && (this.Z == p.Z));
}
/// <summary>
/// Override of GetHashCode() - functionality unchanged
/// </summary>
/// <returns>Base classes GetHashCode() return</returns>
public override int GetHashCode()
{
return base.GetHashCode();
}
/// <summary>
/// Override of ToString() to provide the full coordinate
/// </summary>
/// <returns>String representation</returns>
public override string ToString()
{
return String.Format("{0},{1},{2}", this.X, this.Y, this.Z);
}
#endregion // Operator Overloads
/// <summary>
/// Sets new values to x, y, z coordinates
/// </summary>
/// <param name="x">X value</param>
/// <param name="y">Y value</param>
/// <param name="z">Z value</param>
public void UpdateAll(double x, double y, double z)
{
this.X = x;
this.Y = y;
this.Z = z;
}
/// <summary>
/// Zeroes the values of x, y, z
/// </summary>
public void ZeroXYZ()
{
this.X = 0.0;
this.Y = 0.0;
this.Z = 0.0;
}
/// <summary>
/// Subtracts the passed in offset from this ThreeDPoint object
/// </summary>
/// <param name="offset">Offset to be subtracted</param>
public void Subtract(ThreeDPoint offset)
{
if (offset != null)
{
this.X = this.X - offset.X;
this.Y = this.Y - offset.Y;
this.Z = this.Z - offset.Z;
}
}
/// <summary>
/// Round the X/Y/Z values to the nearest whole integer
/// </summary>
public void RoundValues()
{
this.X = Math.Round(this.X, 0, MidpointRounding.AwayFromZero);
this.Y = Math.Round(this.Y, 0, MidpointRounding.AwayFromZero);
this.Z = Math.Round(this.Z, 0, MidpointRounding.AwayFromZero);
}
/// <summary>
/// Floor the X/Y/Z values
/// </summary>
public void FloorValues()
{
this.X = Math.Floor(this.X);
this.Y = Math.Floor(this.Y);
this.Z = Math.Floor(this.Z);
}
}
}
//}