public void Indexer() { var v = new lvec4(4L, -5L, 5L, 8L); Assert.AreEqual(4L, v[0]); Assert.AreEqual(-5L, v[1]); Assert.AreEqual(5L, v[2]); Assert.AreEqual(8L, v[3]); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-2147483648]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[-2147483648] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[-1]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[-1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[4]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[4] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[2147483647]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[2147483647] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { var s = v[5]; }); Assert.Throws <ArgumentOutOfRangeException>(() => { v[5] = 0; }); v[1] = 0; Assert.AreEqual(0, v[1]); v[1] = 1; Assert.AreEqual(1, v[1]); v[3] = 2L; Assert.AreEqual(2L, v[3]); v[0] = 3L; Assert.AreEqual(3L, v[0]); v[2] = 4L; Assert.AreEqual(4L, v[2]); v[2] = 5L; Assert.AreEqual(5L, v[2]); v[3] = 6L; Assert.AreEqual(6L, v[3]); v[3] = 7L; Assert.AreEqual(7L, v[3]); v[2] = 8L; Assert.AreEqual(8L, v[2]); v[1] = 9L; Assert.AreEqual(9L, v[1]); v[2] = -1L; Assert.AreEqual(-1L, v[2]); v[0] = -2L; Assert.AreEqual(-2L, v[0]); v[1] = -3L; Assert.AreEqual(-3L, v[1]); v[2] = -4L; Assert.AreEqual(-4L, v[2]); v[1] = -5L; Assert.AreEqual(-5L, v[1]); v[0] = -6L; Assert.AreEqual(-6L, v[0]); v[1] = -7L; Assert.AreEqual(-7L, v[1]); v[2] = -8L; Assert.AreEqual(-8L, v[2]); v[3] = -9L; Assert.AreEqual(-9L, v[3]); }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public lmat2x4(lvec4 c0, lvec4 c1) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; }
public void PropertyValues() { var v = new lvec4(-7L, -7L, 1, -5L); var vals = v.Values; Assert.AreEqual(-7L, vals[0]); Assert.AreEqual(-7L, vals[1]); Assert.AreEqual(1, vals[2]); Assert.AreEqual(-5L, vals[3]); Assert.That(vals.SequenceEqual(v.ToArray())); }
public void SerializationJson() { var v0 = new lvec4(-6L, 1, -1L, -7L); var s0 = JsonConvert.SerializeObject(v0); var v1 = JsonConvert.DeserializeObject <lvec4>(s0); var s1 = JsonConvert.SerializeObject(v1); Assert.AreEqual(v0, v1); Assert.AreEqual(s0, s1); }
public void InvariantCommutative() { { var v0 = new lvec4(0, 9L, -3L, 5L); var v1 = new lvec4(7L, 1, 5L, -1L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(0, -7L, -4L, 6L); var v1 = new lvec4(5L, -6L, -4L, -4L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-3L, 2L, 6L, 4L); var v1 = new lvec4(-8L, 4L, -9L, -2L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-8L, -1L, 7L, 7L); var v1 = new lvec4(4L, 4L, 0, 5L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-5L, -2L, -6L, 1); var v1 = new lvec4(7L, 7L, -3L, 3L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-8L, 0, -3L, -4L); var v1 = new lvec4(5L, 9L, -6L, -9L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-1L, -8L, -1L, -8L); var v1 = new lvec4(3L, 1, 7L, -6L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-1L, 1, 7L, -7L); var v1 = new lvec4(-4L, -8L, 5L, -6L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(-7L, 8L, -1L, -3L); var v1 = new lvec4(0, -2L, 5L, 5L); Assert.AreEqual(v0 * v1, v1 * v0); } { var v0 = new lvec4(8L, 3L, 5L, -8L); var v1 = new lvec4(-1L, 4L, 6L, 8L); Assert.AreEqual(v0 * v1, v1 * v0); } }
public void TriangleInequality() { { var v0 = new lvec4(5L, 3L, -3L, 3L); var v1 = new lvec4(9L, -7L, -1L, 5L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(5L, -6L, -5L, -7L); var v1 = new lvec4(-7L, -6L, 7L, 5L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(-9L, -3L, -9L, -9L); var v1 = new lvec4(-1L, -9L, -5L, 9L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(0, 9L, -6L, 8L); var v1 = new lvec4(0, 0, -4L, 0); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(9L, -3L, -2L, -3L); var v1 = new lvec4(-5L, -9L, 4L, 2L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(-8L, 1, -2L, -3L); var v1 = new lvec4(3L, -2L, 3L, -5L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(0, 6L, -4L, 8L); var v1 = new lvec4(8L, -8L, -4L, 5L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(7L, 3L, 3L, 0); var v1 = new lvec4(1, 2L, 4L, 5L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(2L, -5L, 6L, 4L); var v1 = new lvec4(3L, -4L, 9L, 0); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } { var v0 = new lvec4(8L, -7L, 1, 9L); var v1 = new lvec4(7L, 1, 5L, 7L); Assert.GreaterOrEqual(v0.NormMax + v1.NormMax, (v0 + v1).NormMax); } }
public void InvariantCommutativeNeg() { { var v0 = new lvec4(-1L, -6L, -2L, 3L); var v1 = new lvec4(0, -8L, -1L, -3L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(-5L, 8L, -8L, -3L); var v1 = new lvec4(-1L, 0, 0, -7L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(-6L, -5L, 0, 4L); var v1 = new lvec4(-4L, 9L, 7L, -3L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(-7L, -5L, 6L, -1L); var v1 = new lvec4(7L, -2L, -3L, -3L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(1, -9L, 6L, 3L); var v1 = new lvec4(-2L, -5L, 7L, -6L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(7L, 2L, 9L, 5L); var v1 = new lvec4(4L, -8L, 9L, 2L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(6L, -1L, -8L, 1); var v1 = new lvec4(-5L, 0, -3L, 1); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(8L, -8L, 5L, 5L); var v1 = new lvec4(-2L, 0, 5L, 2L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(-5L, 4L, -1L, -1L); var v1 = new lvec4(-3L, -7L, 4L, 0); Assert.AreEqual(v0 - v1, -(v1 - v0)); } { var v0 = new lvec4(7L, 3L, -6L, -2L); var v1 = new lvec4(-9L, 1, 8L, -9L); Assert.AreEqual(v0 - v1, -(v1 - v0)); } }
public void Operators() { var v1 = new lvec4(1, -8L, 9L, 5L); var v2 = new lvec4(1, -8L, 9L, 5L); var v3 = new lvec4(5L, 9L, -8L, 1); Assert.That(v1 == new lvec4(v1)); Assert.That(v2 == new lvec4(v2)); Assert.That(v3 == new lvec4(v3)); Assert.That(v1 == v2); Assert.That(v1 != v3); Assert.That(v2 != v3); }
public void StringInterop() { var v = new lvec4(-5L, 3L, 7L, 6L); var s0 = v.ToString(); var s1 = v.ToString("#"); var v0 = lvec4.Parse(s0); var v1 = lvec4.Parse(s1, "#"); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); var b0 = lvec4.TryParse(s0, out v0); var b1 = lvec4.TryParse(s1, "#", out v1); Assert.That(b0); Assert.That(b1); Assert.AreEqual(v, v0); Assert.AreEqual(v, v1); b0 = lvec4.TryParse(null, out v0); Assert.False(b0); b0 = lvec4.TryParse("", out v0); Assert.False(b0); b0 = lvec4.TryParse(s0 + ", 0", out v0); Assert.False(b0); Assert.Throws <NullReferenceException>(() => { lvec4.Parse(null); }); Assert.Throws <FormatException>(() => { lvec4.Parse(""); }); Assert.Throws <FormatException>(() => { lvec4.Parse(s0 + ", 0"); }); var s2 = v.ToString(";", CultureInfo.InvariantCulture); Assert.That(s2.Length > 0); var s3 = v.ToString("; ", "G"); var s4 = v.ToString("; ", "G", CultureInfo.InvariantCulture); var v3 = lvec4.Parse(s3, "; ", NumberStyles.Number); var v4 = lvec4.Parse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture); Assert.AreEqual(v, v3); Assert.AreEqual(v, v4); var b4 = lvec4.TryParse(s4, "; ", NumberStyles.Number, CultureInfo.InvariantCulture, out v4); Assert.That(b4); Assert.AreEqual(v, v4); }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public lmat3x4(lvec4 c0, lvec4 c1, lvec4 c2) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; this.m20 = c2.x; this.m21 = c2.y; this.m22 = c2.z; this.m23 = c2.w; }
/// <summary> /// Constructs this matrix from a series of column vectors. Non-overwritten fields are from an Identity matrix. /// </summary> public lmat3x4(lvec4 c0, lvec4 c1) { this.m00 = c0.x; this.m01 = c0.y; this.m02 = c0.z; this.m03 = c0.w; this.m10 = c1.x; this.m11 = c1.y; this.m12 = c1.z; this.m13 = c1.w; this.m20 = 0; this.m21 = 0; this.m22 = 1; this.m23 = 0; }
public void InvariantTriple() { { var v0 = new lvec4(-1L, 4L, -9L, 7L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-3L, -4L, 1, -8L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-6L, 0, -8L, 5L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-1L, 9L, -9L, 6L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-1L, 7L, 1, -1L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-9L, 9L, 3L, 0); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(8L, -6L, 9L, -9L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-6L, 4L, -6L, -6L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(-4L, 9L, -1L, 2L); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } { var v0 = new lvec4(0, 5L, -5L, 1); Assert.AreEqual(v0 + v0 + v0, 3 * v0); } }
public void InvariantNorm() { { var v0 = new lvec4(-9L, -4L, -9L, -4L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(5L, -9L, 6L, -7L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(-8L, -2L, 0, 6L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(-9L, 0, 3L, 7L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(5L, -8L, -3L, 9L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(-8L, 7L, 9L, -3L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(5L, 5L, 1, -6L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(7L, 7L, 6L, -2L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(-8L, 4L, -2L, 2L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } { var v0 = new lvec4(0, -3L, -1L, -3L); Assert.LessOrEqual(v0.NormMax, v0.Norm); } }
public void InvariantDouble() { { var v0 = new lvec4(3L, 4L, 8L, -8L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(0, -5L, -7L, 7L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(9L, 9L, -9L, 9L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(5L, 2L, 0, 4L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(9L, 8L, 0, -8L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(9L, 0, 1, 3L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(7L, -7L, 4L, -1L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(-4L, 4L, 5L, -2L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(1, -1L, -3L, 3L); Assert.AreEqual(v0 + v0, 2 * v0); } { var v0 = new lvec4(7L, 8L, 7L, -2L); Assert.AreEqual(v0 + v0, 2 * v0); } }
public void InvariantId() { { var v0 = new lvec4(-3L, 9L, -2L, -3L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(-1L, 3L, 7L, -3L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(-6L, 8L, -7L, 8L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(7L, 2L, -1L, -1L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(4L, 0, 7L, 1); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(-4L, -4L, 5L, 3L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(6L, -9L, 4L, 5L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(-9L, -3L, -4L, 6L); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(7L, 3L, -5L, 1); Assert.AreEqual(v0, +v0); } { var v0 = new lvec4(9L, -7L, -4L, -7L); Assert.AreEqual(v0, +v0); } }
public void InvariantIdNeg() { { var v0 = new lvec4(7L, 4L, 3L, 0); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(-2L, -7L, -4L, 7L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(0, -6L, 4L, -3L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(1, -7L, -1L, 8L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(-1L, 7L, -2L, 0); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(-4L, 0, -1L, 4L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(8L, -3L, 6L, -1L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(-6L, -2L, 1, -6L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(3L, -1L, 3L, -2L); Assert.AreEqual(v0, -(-v0)); } { var v0 = new lvec4(6L, 5L, 7L, -2L); Assert.AreEqual(v0, -(-v0)); } }
public void Constructors() { { var v = new lvec4(3L); Assert.AreEqual(3L, v.x); Assert.AreEqual(3L, v.y); Assert.AreEqual(3L, v.z); Assert.AreEqual(3L, v.w); } { var v = new lvec4(6L, -3L, 5L, 4L); Assert.AreEqual(6L, v.x); Assert.AreEqual(-3L, v.y); Assert.AreEqual(5L, v.z); Assert.AreEqual(4L, v.w); } { var v = new lvec4(new lvec2(-7L, 8L)); Assert.AreEqual(-7L, v.x); Assert.AreEqual(8L, v.y); Assert.AreEqual(0, v.z); Assert.AreEqual(0, v.w); } { var v = new lvec4(new lvec3(2L, -9L, 8L)); Assert.AreEqual(2L, v.x); Assert.AreEqual(-9L, v.y); Assert.AreEqual(8L, v.z); Assert.AreEqual(0, v.w); } { var v = new lvec4(new lvec4(9L, 8L, -6L, -3L)); Assert.AreEqual(9L, v.x); Assert.AreEqual(8L, v.y); Assert.AreEqual(-6L, v.z); Assert.AreEqual(-3L, v.w); } }
/// <summary> /// Returns a lvec4 with independent and identically distributed uniform integer values between minValue (inclusive) and maxValue (exclusive). (minValue == maxValue is allowed and returns minValue. Negative values are allowed.) /// </summary> public static lvec4 RandomUniform(Random random, lvec4 minValue, lvec4 maxValue) => lvec4.RandomUniform(random, minValue, maxValue);
/// <summary> /// Returns true iff this equals rhs component-wise. /// </summary> public static bool Equals(lvec4 v, lvec4 rhs) => v.Equals(rhs);
/// <summary> /// Returns a bvec4 from component-wise application of GreaterThanEqual (lhs >= rhs). /// </summary> public static bvec4 GreaterThanEqual(lvec4 lhs, lvec4 rhs) => lvec4.GreaterThanEqual(lhs, rhs);
/// <summary> /// OuterProduct treats the first parameter c as a column vector (matrix with one column) and the second parameter r as a row vector (matrix with one row) and does a linear algebraic matrix multiply c * r, yielding a matrix whose number of rows is the number of components in c and whose number of columns is the number of components in r. /// </summary> public static lmat4x2 OuterProduct(lvec2 c, lvec4 r) => lvec2.OuterProduct(c, r);
/// <summary> /// Returns a bvec4 from component-wise application of Equal (lhs == rhs). /// </summary> public static bvec4 Equal(lvec4 lhs, lvec4 rhs) => lvec4.Equal(lhs, rhs);
/// <summary> /// Returns a bvec4 from component-wise application of NotEqual (lhs != rhs). /// </summary> public static bvec4 NotEqual(lvec4 lhs, lvec4 rhs) => lvec4.NotEqual(lhs, rhs);
/// <summary> /// Returns a hash code for this instance. /// </summary> public static int GetHashCode(lvec4 v) => v.GetHashCode();
/// <summary> /// Returns true iff this equals rhs type- and component-wise. /// </summary> public static bool Equals(lvec4 v, object obj) => v.Equals(obj);
/// <summary> /// OuterProduct treats the first parameter c as a column vector (matrix with one column) and the second parameter r as a row vector (matrix with one row) and does a linear algebraic matrix multiply c * r, yielding a matrix whose number of rows is the number of components in c and whose number of columns is the number of components in r. /// </summary> public static lmat4x3 OuterProduct(lvec3 c, lvec4 r) => lvec3.OuterProduct(c, r);
/// <summary> /// Returns the number of components (4). /// </summary> public static int Count(lvec4 v) => v.Count;
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format and format provider for each component. /// </summary> public static string ToString(lvec4 v, string sep, string format, IFormatProvider provider) => v.ToString(sep, format, provider);
/// <summary> /// Returns a string representation of this vector using a provided seperator. /// </summary> public static string ToString(lvec4 v, string sep) => v.ToString(sep);
/// <summary> /// Returns a string representation of this vector using a provided seperator and a format for each component. /// </summary> public static string ToString(lvec4 v, string sep, string format) => v.ToString(sep, format);