25 Assert.AreEqual(0, vec.
x,
"x");
26 Assert.AreEqual(1, vec.
y,
"y");
27 Assert.AreEqual(0, vec.
z,
"z");
33 Assert.AreEqual(0, vec.
x,
"x");
34 Assert.AreEqual(-1, vec.
y,
"y");
35 Assert.AreEqual(0, vec.
z,
"z");
41 Assert.AreEqual(0, vec.
x,
"x");
42 Assert.AreEqual(0, vec.
y,
"y");
43 Assert.AreEqual(-1, vec.
z,
"z");
49 Assert.AreEqual(0, vec.
x,
"x");
50 Assert.AreEqual(0, vec.
y,
"y");
51 Assert.AreEqual(1, vec.
z,
"z");
57 Assert.AreEqual(-1, vec.
x,
"x");
58 Assert.AreEqual(0, vec.
y,
"y");
59 Assert.AreEqual(0, vec.
z,
"z");
65 Assert.AreEqual(1, vec.
x,
"x");
66 Assert.AreEqual(0, vec.
y,
"y");
67 Assert.AreEqual(0, vec.
z,
"z");
73 Assert.AreEqual(0, vec.
x,
"x");
74 Assert.AreEqual(0, vec.
y,
"y");
75 Assert.AreEqual(0, vec.
z,
"z");
81 Assert.AreEqual(1, vec.
x,
"x");
82 Assert.AreEqual(0, vec.
y,
"y");
83 Assert.AreEqual(0, vec.
z,
"z");
89 Assert.AreEqual(0, vec.
x,
"x");
90 Assert.AreEqual(1, vec.
y,
"y");
91 Assert.AreEqual(0, vec.
z,
"z");
97 Assert.AreEqual(0, vec.
x,
"x");
98 Assert.AreEqual(0, vec.
y,
"y");
99 Assert.AreEqual(1, vec.
z,
"z");
105 Assert.AreEqual(0.5f, vec.
x,
"x");
106 Assert.AreEqual(200.3f, vec.
y,
"y");
107 Assert.AreEqual(67f, vec.
z,
"z");
109 Assert.AreEqual(0, vec.
x,
"x");
110 Assert.AreEqual(0, vec.
y,
"y");
111 Assert.AreEqual(0, vec.
z,
"z");
118 Assert.AreEqual(3, vec.
x,
"x");
119 Assert.AreEqual(4, vec.
y,
"y");
120 Assert.AreEqual(5, vec.
z,
"z");
122 Assert.AreEqual(3, baseVector.
x,
"z");
136 Assert.IsTrue(
float.IsInfinity(tooBig),
"max value is too large");
138 Assert.IsTrue(
float.IsInfinity(tooSmall),
"min value is too large");
139 Assert.AreEqual((
float)
Math.Sqrt(3f),
new Vector(1, 1, 1).Magnitude,
"(1,1,1) has sqrt(3) length");
140 Assert.AreEqual((
float)
Math.Sqrt(3f),
new Vector(-1, -1, -1).Magnitude,
"(-1,-1,-1) has sqrt(3) length");
154 Assert.IsTrue(
float.IsInfinity(tooBig),
"max value is too large");
156 Assert.IsTrue(
float.IsInfinity(tooSmall),
"min value is too large");
157 Assert.AreEqual(3,
new Vector(1, 1, 1).MagnitudeSquared,
"(1,1,1) has 3 length");
158 Assert.AreEqual(3,
new Vector(-1, -1, -1).MagnitudeSquared,
"(-1,-1,-1) 3 length");
173 Assert.IsTrue(
float.IsInfinity(tooBig),
"max value is too large");
175 Assert.IsTrue(
float.IsInfinity(tooSmall),
"min value is too large");
176 Assert.AreEqual((
float)
Math.Sqrt(3f), origin.
DistanceTo(
new Vector(1, 1, 1)),
"distance to (1,1,1) is sqrt(3)");
177 Assert.AreEqual((
float)
Math.Sqrt(3f), origin.
DistanceTo(
new Vector(-1, -1, -1)),
"distance to (-1,-1,-1) is sqrt(3)");
183 Assert.AreEqual(0,
new Vector(1, -3, 45).AngleTo(
new Vector(1, -3, 45)),
"angle to same");
197 for (; count <= 180; count++) {
200 Assert.AreEqual(count * Constants.DEG_TO_RAD, baseVec.
AngleTo(rotated), 12 * Constants.EPSILON,
"0-180 Angle is " + baseVec.
AngleTo(rotated) * Constants.RAD_TO_DEG);
201 Assert.AreEqual(rotated.
AngleTo(baseVec), baseVec.
AngleTo(rotated), Constants.EPSILON,
"a to b == b to a");
204 for (; count <= 360; count++) {
208 Assert.AreEqual((360 - count) * Constants.DEG_TO_RAD, baseVec.
AngleTo(rotated), 12 * Constants.EPSILON,
"180-360 Angle is " + baseVec.
AngleTo(rotated) * Constants.RAD_TO_DEG);
209 Assert.AreEqual(rotated.
AngleTo(baseVec), baseVec.
AngleTo(rotated), Constants.EPSILON,
"a to b == b to a");
211 for (; count <= 540; count++) {
214 Assert.AreEqual((count - 360) * Constants.DEG_TO_RAD, baseVec.
AngleTo(rotated), 12 * Constants.EPSILON,
"360-540 Angle is " + baseVec.
AngleTo(rotated) * Constants.RAD_TO_DEG);
215 Assert.AreEqual(rotated.
AngleTo(baseVec), baseVec.
AngleTo(rotated), Constants.EPSILON,
"a to b == b to a");
218 for (; count <= 720; count++) {
222 Assert.AreEqual((720 - count) * Constants.DEG_TO_RAD, baseVec.
AngleTo(rotated), 12 * Constants.EPSILON,
"540-720 Angle is " + baseVec.
AngleTo(rotated) * Constants.RAD_TO_DEG);
223 Assert.AreEqual(rotated.
AngleTo(baseVec), baseVec.
AngleTo(rotated), Constants.EPSILON,
"a to b == b to a");
235 for (; count < 180; count++) {
236 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
238 Assert.AreEqual(count * Constants.DEG_TO_RAD, rotated.
Pitch, 12 * Constants.EPSILON,
"0-180 Pitch is " + rotated.
Pitch * Constants.RAD_TO_DEG);
240 for (; count <= 360; count++) {
241 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
243 Assert.AreEqual((-360 + count) * Constants.DEG_TO_RAD, rotated.
Pitch, 12 * Constants.EPSILON,
"180-360 Pitch is " + rotated.
Pitch * Constants.RAD_TO_DEG);
255 for (; count < 180; count++) {
256 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
258 Assert.AreEqual(count * Constants.DEG_TO_RAD, rotated.
Yaw, 12 * Constants.EPSILON,
"0-180 Yaw is " + rotated.
Yaw * Constants.RAD_TO_DEG);
260 for (; count <= 360; count++) {
261 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
263 Assert.AreEqual((-360 + count) * Constants.DEG_TO_RAD, rotated.
Yaw, 12 * Constants.EPSILON,
"180-360 Yaw is " + rotated.
Yaw * Constants.RAD_TO_DEG);
275 for (; count < 180; count++) {
276 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
278 Assert.AreEqual(count * Constants.DEG_TO_RAD, rotated.
Roll, 12 * Constants.EPSILON,
"0-180 Roll is " + rotated.
Roll * Constants.RAD_TO_DEG);
280 for (; count <= 360; count++) {
281 rotator.
SetRotation(axis, count * Constants.DEG_TO_RAD);
283 Assert.AreEqual((-360 + count) * Constants.DEG_TO_RAD, rotated.
Roll, 12 * Constants.EPSILON,
"180-360 Roll is " + rotated.
Roll * Constants.RAD_TO_DEG);
301 Assert.AreEqual(expected, v1.
Cross(v2),
"v1 x v2");
302 Assert.AreEqual(-expected, v2.
Cross(v1),
"v1 x v2");
303 Assert.AreEqual(0, v1.
Dot(v1.
Cross(v2)),
"Orthogonal with v1");
304 Assert.AreEqual(0, v2.
Dot(v1.
Cross(v2)),
"Orthogonal with v2");
314 Vector v5 =
new Vector(-99999999, -99999999, -99999999);
326 Assert.AreEqual(
new Vector(-3, 10, -1), v1 + v2);
333 Assert.AreEqual(
new Vector(5, -6, 7), v1 - v2);
339 Assert.AreEqual(
new Vector(-1, -2, 3), -v1);
345 Assert.AreEqual(
new Vector(5.2f, 10.4f, -15.6f), (v1 * 5.2f));
351 Assert.AreEqual(
new Vector(5f, 30f, -60f), (v1 / 5.0f));
359 Assert.IsTrue(v1.
Equals(v3),
"simple integers 1");
360 Assert.IsTrue(v3.
Equals(v1),
"simple integers 2");
361 Assert.IsTrue(v1.
Equals(v1),
"simple integers 3");
362 Assert.IsTrue(v1 == v3,
"simple integers 4");
363 Assert.IsTrue(v3 == v1,
"simple integers 5");
364 Assert.IsFalse(v1.
Equals(v2),
"simple integers 6");
365 Assert.IsFalse(v2.
Equals(v1),
"simple integers 7");
366 Assert.IsFalse(v1 == v2,
"simple integers 8");
367 Assert.IsFalse(v2 == v1,
"simple integers 9");
371 Assert.IsTrue(v4 == v5,
"MinValue");
375 Assert.IsTrue(v6 == v7,
"MaxValue");
377 Vector v8 =
new Vector(
float.Epsilon,
float.Epsilon,
float.Epsilon);
378 Vector v9 =
new Vector(
float.Epsilon,
float.Epsilon,
float.Epsilon);
379 Assert.IsTrue(v8 == v9,
"Epsilon");
381 Vector v10 =
new Vector(
float.PositiveInfinity,
float.PositiveInfinity,
float.NegativeInfinity);
382 Vector v11 =
new Vector(
float.PositiveInfinity,
float.PositiveInfinity,
float.NegativeInfinity);
383 Assert.IsTrue(v10 == v11,
"Infinity");
385 Vector v12 =
new Vector(
float.NaN,
float.NaN,
float.NaN);
386 Vector v13 =
new Vector(
float.NaN,
float.NaN,
float.NaN);
387 Assert.IsFalse(v12 == v13,
"NaN");
389 Vector v14 =
new Vector(5 +
float.Epsilon, -124.34f +
float.Epsilon,
float.
MaxValue -
float.Epsilon);
391 Assert.IsTrue(v14 == v15,
"+- Epsilon");
393 Vector v16 =
new Vector(5 + Constants.EPSILON, -124.34f + Constants.EPSILON,
float.MaxValue - Constants.EPSILON);
394 Vector v17 =
new Vector(5 - Constants.EPSILON, -124.34f - Constants.EPSILON,
float.MaxValue);
395 Assert.IsTrue(v16 == v17,
"+- Leap Epsilon");
397 float epsilonMultiplier = 11;
398 Vector v18 =
new Vector(5 + Constants.EPSILON * epsilonMultiplier, -124.34f + Constants.EPSILON * epsilonMultiplier,
float.MaxValue - Constants.EPSILON * epsilonMultiplier);
400 Assert.IsFalse(v18 == v19,
"Diff > Leap Epsilon");
407 bool vectorsNotEqual = thisVector != thatVector;
409 Assert.IsTrue(vectorsNotEqual);
415 Assert.IsFalse(xInvalid.
IsValid());
417 Assert.IsFalse(yInvalid.
IsValid());
418 Vector zInvalid =
new Vector(-345.32f, -78.67f,
float.NaN);
419 Assert.IsFalse(zInvalid.
IsValid());
420 Vector xInfinite =
new Vector(
float.PositiveInfinity, 3f, 45f);
421 Assert.IsFalse(xInfinite.
IsValid());
422 Vector yInfinite =
new Vector(-23.7f,
float.NegativeInfinity, 3f);
423 Assert.IsFalse(yInfinite.
IsValid());
424 Vector zInfinite =
new Vector(3f, 45f,
float.PositiveInfinity);
425 Assert.IsFalse(zInfinite.
IsValid());
426 Vector mixed =
new Vector(
float.NaN,
float.NegativeInfinity,
float.PositiveInfinity);
427 Assert.IsFalse(mixed.
IsValid());
void Vector_Magnitude_Squared()
void Vector_Constructor_1()
void Vector_Constructor_2()
The Matrix struct represents a transformation matrix.
void SetRotation(Vector axis, float angleRadians)
Sets this transformation matrix to represent a rotation around the specified vector.
static readonly Matrix Identity
Returns the identity matrix specifying no translation, rotation, and scale.
Vector TransformDirection(Vector direction)
Transforms a vector with this matrix by transforming its rotation and scale only.
The Vector struct represents a three-component mathematical vector or point such as a direction or po...
static readonly Vector Zero
The zero vector: (0, 0, 0)
Vector Normalized
A normalized copy of this vector.
static readonly Vector ZAxis
The z-axis unit vector: (0, 0, 1)
static readonly Vector Forward
The unit vector pointing forward along the negative z-axis: (0, 0, -1)
float AngleTo(Vector other)
The angle between this vector and the specified vector in radians.
static readonly Vector Down
The unit vector pointing down along the negative y-axis: (0, -1, 0)
static readonly Vector Left
The unit vector pointing left along the negative x-axis: (-1, 0, 0)
float Dot(Vector other)
The dot product of this vector with another vector.
float DistanceTo(Vector other)
The distance between the point represented by this Vector object and a point represented by the speci...
static readonly Vector Right
The unit vector pointing right along the positive x-axis: (1, 0, 0)
bool IsValid()
Returns true if all of the vector's components are finite. If any component is NaN or infinite,...
bool Equals(Vector v)
Compare Vector equality component-wise.
static readonly Vector YAxis
The y-axis unit vector: (0, 1, 0)
float Yaw
The yaw angle in radians.
float Pitch
The pitch angle in radians.
Vector Cross(Vector other)
The cross product of this vector and the specified vector.
static readonly Vector XAxis
The x-axis unit vector: (1, 0, 0)
static readonly Vector Backward
The unit vector pointing backward along the positive z-axis: (0, 0, 1)
static readonly Vector Up
The unit vector pointing up along the positive y-axis: (0, 1, 0)
float MagnitudeSquared
The square of the magnitude, or length, of this vector.
float Roll
The roll angle in radians.
float Magnitude
The magnitude, or length, of this vector.