-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector3D.cs
214 lines (188 loc) · 6.8 KB
/
Vector3D.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace ROQWE
{
#pragma warning disable CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
#pragma warning disable CS0660 // Type defines operator == or operator != but does not override Object.Equals(object o)
struct IntVector3D: IComparable<IntVector3D>
#pragma warning restore CS0660 // Type defines operator == or operator != but does not override Object.Equals(object o)
#pragma warning restore CS0661 // Type defines operator == or operator != but does not override Object.GetHashCode()
{
public int X { get; set; }
public int Y { get; set; }
public int Z { get; set; }
public IntVector XY
{
get { return (X, Y); }
set { X = value.X; Y = value.Y; }
}
public IntVector XZ
{
get { return (X, Z); }
set { X = value.X; Z = value.Y; }
}
public IntVector YZ
{
get { return (Y, Z); }
set { Y = value.X; Z = value.Y; }
}
public double Magnitude
{
get { return Math.Sqrt(Math.Pow(X, 2) + Math.Pow(Y, 2)); }
private set { }
}
public Vector Angle
{
get { return IntVectorToRadians(this); }
set { }
}
public override string ToString()
{
return "(" + X + "," + Y + "," + Z + ")";
}
/// <summary>
/// (X, Y)
/// </summary>
/// <param name="coordinate"></param>
public IntVector3D(int x, int y, int z)
{
X = x;
Y = y;
Z = z;
}
/// <summary>
/// creates a vector of (size, size, size)
/// </summary>
/// <param name="size"></param>
public IntVector3D(int size)
{
X = size;
Y = size;
Z = size;
}
public int CompareTo(IntVector3D other)
{
// The magnitude comparison depends on the comparison of
// the underlying Double values.
return Magnitude.CompareTo(other.Magnitude);
}
public static bool operator >(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) == 1;
}
// Define the is less than operator.
public static bool operator <(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) == -1;
}
// Define the is greater than or equal to operator.
public static bool operator >=(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) >= 0;
}
// Define the is less than or equal to operator.
public static bool operator <=(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) <= 0;
}
public static bool operator ==(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) == 0;
}
public static bool operator !=(IntVector3D operand1, IntVector3D operand2)
{
return operand1.CompareTo(operand2) != 0;
}
public static IntVector3D operator +(IntVector3D a, IntVector b)
{
return new IntVector3D(a.X + b.X, a.Y + b.Y, a.Z);
}
public static IntVector3D operator +(IntVector3D a, IntVector3D b)
{
return new IntVector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
public static IntVector3D operator -(IntVector3D a, IntVector3D b)
{
return new IntVector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
public static IntVector3D operator *(IntVector3D a, double b)
{
return new IntVector3D((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b));
}
public static IntVector3D operator *(IntVector3D a, IntVector3D b)
{
return new IntVector3D(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
}
public static IntVector3D operator /(IntVector3D a, double b)
{
return new IntVector3D((int)Math.Round(a.X / b), (int)Math.Round(a.Y / b), (int)Math.Round(a.Z / b));
}
public static IntVector3D operator /(IntVector3D a, IntVector3D b)
{
return new IntVector3D(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
}
public static IntVector3D operator %(IntVector3D a, IntVector3D b)
{
return a - Floor(a / b) * b;
}
public static IntVector3D Floor(Vector3 a)
{
return new IntVector3D((int)Math.Floor(a.X), (int)Math.Floor(a.Y), (int)Math.Floor(a.Z));
}
/// <summary>
/// converts from a Vector to radians;
/// </summary>
/// <param name="v"></param>
/// <returns></returns>
public static Vector IntVectorToRadians(IntVector3D v)
{
return new Vector(Math.Atan2(v.Y,v.X), Math.Atan2(v.Z,v.XY.Magnitude));
}
public static explicit operator string (IntVector3D v)
{
return "("+v.X+", "+ v.Y+", "+v.Z+")";
}
public static implicit operator (int, int, int) (IntVector3D v)
{
return (v.X, v.Y, v.Z);
}
public static implicit operator IntVector3D((int x, int y, int z) position)
{
return new IntVector3D(position.x, position.y, position.z);
}//*/
public static implicit operator IntVector3D((IntVector v, int z) position)
{
return new IntVector3D(position.v.X, position.v.Y, position.z);
}
public static implicit operator IntVector3D(Vector3 v)
{
return new IntVector3D((int)Math.Round(v.X), (int)Math.Round(v.Y), (int)Math.Round(v.Z));
}
public static implicit operator Vector3(IntVector3D v)
{
return new Vector3(v.X,v.Y,v.Z);
}
}
class Vector3D
{
public float X, Y, Z;
public Vector3D(float x,float y, float z)
{
X = x;
Y = y;
Z = z;
}
public static explicit operator Vector3D((float x, float y, float z) position)
{
return new Vector3D(position.x, position.y, position.z);
}//*/
public static implicit operator Vector3(Vector3D v)
{
return new Vector3(v.X, v.Y, v.Z);
}
}
}