public void GetRow() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(new Vector2F(1.0f, 2.0f), m.GetRow(0)); Assert.AreEqual(new Vector2F(3.0f, 4.0f), m.GetRow(1)); }
public void SerializationBinary() { Matrix22F m1 = new Matrix22F(12, 23, 45, 56.3f); Matrix22F m2; string fileName = "SerializationMatrix22F.bin"; if (File.Exists(fileName)) { File.Delete(fileName); } FileStream fs = new FileStream(fileName, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, m1); fs.Close(); fs = new FileStream(fileName, FileMode.Open); formatter = new BinaryFormatter(); m2 = (Matrix22F)formatter.Deserialize(fs); fs.Close(); Assert.AreEqual(m1, m2); }
public void SerializationXml2() { Matrix22F m1 = new Matrix22F(12, 23, 45, 56.3f); Matrix22F m2; string fileName = "SerializationMatrix22F_DataContractSerializer.xml"; if (File.Exists(fileName)) { File.Delete(fileName); } var serializer = new DataContractSerializer(typeof(Matrix22F)); using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) using (var writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8)) serializer.WriteObject(writer, m1); using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var reader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas())) m2 = (Matrix22F)serializer.ReadObject(reader); Assert.AreEqual(m1, m2); }
/// <summary> /// Transforms a position. /// </summary> /// <param name="position">The position in screen coordinates.</param> /// <returns>The transformed position in screen coordinates.</returns> public Vector2F ToRenderPosition(Vector2F position) { // Given: // p .... point in screen space // p' ... transformed point in screen space // o .... the center of the scaling and rotation in screen space // S .... scaling matrix // R .... rotation matrix // t .... translation vector // // The transformation is: // p' = R S (p - o) + o + t position -= Origin; position *= Scale; position = Matrix22F.CreateRotation(Rotation) * position; position += Origin; position += Translation; return(position); // ----- Alternatively, using a 3x3 matrix: //Vector3 p = new Vector3(point.X, point.Y, 1); //p = ToMatrix() * p; //return new Vector2F(p.X, p.Y); }
public void CreateRotation2() { float angle = (float)MathHelper.ToRadians(30); Matrix22F m = Matrix22F.CreateRotation(angle); Assert.IsTrue(Vector2F.AreNumericallyEqual(new Vector2F((float)Math.Cos(angle), (float)Math.Sin(angle)), m * Vector2F.UnitX)); }
public void Transposed() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F mt = new Matrix22F(rowMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(mt, m.Transposed); Assert.AreEqual(Matrix22F.Identity, Matrix22F.Identity.Transposed); }
public void Trace() { Matrix22F m = new Matrix22F(new float[2, 2] { { 1, 2 }, { 2, 4 } }); Assert.AreEqual(5, m.Trace); }
/// <summary> /// Converts this render transformation to a 2x2 matrix that only represents the scaling and the /// rotation (no translation). /// </summary> /// <returns> /// A 2x2-matrix that represents the scaling and the rotation (no translation). /// </returns> public Matrix22F ToMatrix22F() { Matrix22F s = new Matrix22F(Scale.X, 0, 0, Scale.Y); Matrix22F r = Matrix22F.CreateRotation(Rotation); return(r * s); }
public void Addition() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = Matrix22F.One; Matrix22F result = Matrix22F.Add(m1, m2); for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i] + 1.0f, result[i]); }
public void AdditionOperator() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor) * 3; Matrix22F result = m1 + m2; for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i] * 4, result[i]); }
public void CreateRotation() { Matrix22F m = Matrix22F.CreateRotation(0.0f); Assert.AreEqual(Matrix22F.Identity, m); m = Matrix22F.CreateRotation((float)Math.PI / 2); Assert.IsTrue(Vector2F.AreNumericallyEqual(Vector2F.UnitY, m * Vector2F.UnitX)); }
public void Negation() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) { Assert.AreEqual(-rowMajor[i], Matrix22F.Negate(m)[i]); } }
public void Determinant() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(-2.0, m.Determinant); Assert.AreEqual(0.0, Matrix22F.Zero.Determinant); Assert.AreEqual(0.0, Matrix22F.One.Determinant); Assert.AreEqual(1.0f, Matrix22F.Identity.Determinant); }
public void InverseWithNearSingularMatrix() { Matrix22F m = new Matrix22F(0.0001f, 0, 0, 0.0001f); Vector2F v = Vector2F.One; Vector2F w = m * v; Assert.IsTrue(Vector2F.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * m.Inverse)); }
public void Multiplication() { float s = 0.1234f; Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m = Matrix22F.Multiply(s, m); for (int i = 0; i < 4; i++) { Assert.AreEqual(rowMajor[i] * s, m[i]); } }
public void ToMatrix22D() { float m00 = 23.5f; float m01 = 0.0f; float m10 = 33.5f; float m11 = 1.1f; Matrix22D matrix22D = new Matrix22F(m00, m01, m10, m11).ToMatrix22D(); Assert.IsTrue(Numeric.AreEqual(m00, (float)matrix22D[0, 0])); Assert.IsTrue(Numeric.AreEqual(m01, (float)matrix22D[0, 1])); Assert.IsTrue(Numeric.AreEqual(m10, (float)matrix22D[1, 0])); Assert.IsTrue(Numeric.AreEqual(m11, (float)matrix22D[1, 1])); }
public void ExplicitMatrix22FCast() { double m00 = 23.5; double m01 = 0.0; double m10 = 33.5; double m11 = 1.1; Matrix22F matrix22F = (Matrix22F) new Matrix22D(m00, m01, m10, m11); Assert.IsTrue(Numeric.AreEqual((float)m00, matrix22F[0, 0])); Assert.IsTrue(Numeric.AreEqual((float)m01, matrix22F[0, 1])); Assert.IsTrue(Numeric.AreEqual((float)m10, matrix22F[1, 0])); Assert.IsTrue(Numeric.AreEqual((float)m11, matrix22F[1, 1])); }
public void Subtraction() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = Matrix22F.One; Matrix22F result = Matrix22F.Subtract(m1, m2); for (int i = 0; i < 4; i++) { Assert.AreEqual(rowMajor[i] - 1.0f, result[i]); } }
public void SubtractionOperator() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor) * 3; Matrix22F result = m1 - m2; for (int i = 0; i < 4; i++) { Assert.AreEqual(-rowMajor[i] * 2, result[i]); } }
public void Division() { float s = 0.1234f; Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m = Matrix22F.Divide(m, s); for (int i = 0; i < 4; i++) { Assert.IsTrue(Numeric.AreEqual(rowMajor[i] / s, m[i])); } }
public void Inverse() { Assert.AreEqual(Matrix22F.Identity, Matrix22F.Identity.Inverse); Matrix22F m = new Matrix22F(1, 2, 3, 4); Vector2F v = Vector2F.One; Vector2F w = m * v; Assert.IsTrue(Vector2F.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * m.Inverse)); }
public void RandomMatrix22F() { Matrix22F matrix = RandomHelper.Random.NextMatrix22F(10.0f, 100.0f); for (int i = 0; i < 4; i++) { Assert.IsTrue(10.0f <= matrix[i] && matrix[i] <= 100.0f); } // Must not throw exception. RandomHelper.NextMatrix22F(null, 1, 3); }
public void SetRow() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m.SetRow(0, new Vector2F(0.1f, 0.2f)); Assert.AreEqual(new Vector2F(0.1f, 0.2f), m.GetRow(0)); Assert.AreEqual(new Vector2F(3.0f, 4.0f), m.GetRow(1)); m.SetRow(1, new Vector2F(0.4f, 0.5f)); Assert.AreEqual(new Vector2F(0.1f, 0.2f), m.GetRow(0)); Assert.AreEqual(new Vector2F(0.4f, 0.5f), m.GetRow(1)); }
/// <summary> /// Multiplies two render transformation. /// </summary> /// <param name="transform2">The first render transformation.</param> /// <param name="transform1">The second render transformation.</param> /// <returns> /// The product <paramref name="transform2"/> * <paramref name="transform1"/>. /// </returns> public static RenderTransform operator *(RenderTransform transform2, RenderTransform transform1) { // Concatenation of transformations: // // p' = R1 S1 (p - o1) + o1 + t1 // p'' = R2 S2 (p' - o2) + o2 + t2 // = R2 S2 (R1 S1 (p - o1) + o1 + t1 - o2) + o2 + t2 // = R2 S2 R1 S1 (p - o1) + R2 S2 o1 + R2 S2 t1 - R2 S2 o2 + o2 + t2 // // Assuming only UNIFORM SCALINGS we can reorder the matrix product: // = R2 R1 S2 S1 (p - o1) + R2 S2 o1 + R2 S2 t1 - R2 S2 o2 + o2 + t2 // // We can add o1 - o1. This allows to bring the equation in the standard form: // = R2 R1 S2 S1 (p - o1) + R2 S2 o1 + R2 S2 t1 - R2 S2 o2 + o2 + t2 + o1 - o1 // = R2 R1 S2 S1 (p - o1) + o1 + R2 S2 o1 + R2 S2 t1 - R2 S2 o2 + o2 + t2 - o1 // = R S (p - o) + o + t // => S = S2 S1 // R = R2 R1 // o = o1 // t = R2 S2 o1 + R2 S2 t1 - R2 S2 o2 + o2 + t2 - o1 = // = -o1 + o2 + t2 + R2 S2 (o1 + t1 - o2) // Note: In the following we treat the scalings as uniform scaling. In practice, // combining non-uniform scalings with rotations creates an error. We simply ignore // these errors. (See also remarks in class description.) RenderTransform result; var s1 = transform1.Scale; var s2 = transform2.Scale; var θ1 = transform1.Rotation; var θ2 = transform2.Rotation; var o1 = transform1.Origin; var o2 = transform2.Origin; var t1 = transform1.Translation; var t2 = transform2.Translation; // S = S2 S1 // Scalings are combined by multiplying the scale factors. result.Scale = s2 * s1; // R = R2 R1 // Rotations in 2D are combined by adding the rotation angles. result.Rotation = θ2 + θ1; // o = o1 result.Origin = o1; // t = -o1 + o2 + t2 + R2 S2 (o1 + t1 - o2) result.Translation = -o1 + o2 + t2 + Matrix22F.CreateRotation(θ2) * (s2 * (o1 + t1 - o2)); return(result); }
// Compute the animation value for the given time and stores it in result. // This animation does not need defaultSource and defaultTarget parameters. protected override void GetValueCore(TimeSpan time, ref Vector2F defaultSource, ref Vector2F defaultTarget, ref Vector2F result) { const float circlePeriod = 4.0f; float angle = (float)time.TotalSeconds / circlePeriod * ConstantsF.TwoPi; Matrix22F rotation = Matrix22F.CreateRotation(angle); Vector2F offset = new Vector2F(200, 0); Vector2F rotatedOffset = rotation * offset; result.X = 500 + rotatedOffset.X; result.Y = 350 + rotatedOffset.Y; }
public void Transpose() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m.Transpose(); Matrix22F mt = new Matrix22F(rowMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(mt, m); Matrix22F i = Matrix22F.Identity; i.Transpose(); Assert.AreEqual(Matrix22F.Identity, i); }
public void IsSymmetric() { Matrix22F m = new Matrix22F(new float[2, 2] { { 1, 2 }, { 2, 4 } }); Assert.AreEqual(true, m.IsSymmetric); m = new Matrix22F(new float[2, 2] { { 2, 1 }, { 4, 2 } }); Assert.AreEqual(false, m.IsSymmetric); }
public void ToArray1D() { Matrix22F m = new Matrix22F(1, 2, 3, 4); float[] array = m.ToArray1D(MatrixOrder.RowMajor); for (int i = 0; i < 4; i++) { Assert.AreEqual(rowMajor[i], array[i]); } array = m.ToArray1D(MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) { Assert.AreEqual(columnMajor[i], array[i]); } }
public void ToList() { Matrix22F m = new Matrix22F(1, 2, 3, 4); IList <float> list = m.ToList(MatrixOrder.RowMajor); for (int i = 0; i < 4; i++) { Assert.AreEqual(rowMajor[i], list[i]); } list = m.ToList(MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) { Assert.AreEqual(columnMajor[i], list[i]); } }
public void AreEqualWithEpsilon() { float epsilon = 0.001f; Matrix22F m0 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m1 += new Matrix22F(0.002f); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2 += new Matrix22F(0.0001f); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m0, epsilon)); Assert.IsFalse(Matrix22F.AreNumericallyEqual(m0, m1, epsilon)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m2, epsilon)); }
public void EqualityOperators() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.IsTrue(m1 == m2); Assert.IsFalse(m1 != m2); for (int i = 0; i < 4; i++) { m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2[i] += 0.1f; Assert.IsFalse(m1 == m2); Assert.IsTrue(m1 != m2); } }
public void MultiplyVector() { Vector2F v = new Vector2F(2.34f, 3.45f); Assert.AreEqual(v, Matrix22F.Multiply(Matrix22F.Identity, v)); Assert.AreEqual(Vector2F.Zero, Matrix22F.Multiply(Matrix22F.Zero, v)); Matrix22F m = new Matrix22F(12, 23, 45, 67); Assert.IsTrue(Vector2F.AreNumericallyEqual(v, Matrix22F.Multiply(m * m.Inverse, v))); for (int i = 0; i < 2; i++) { Assert.AreEqual(Vector2F.Dot(m.GetRow(i), v), Matrix22F.Multiply(m, v)[i]); } }
public void AbsoluteStatic() { Matrix22F m = new Matrix22F(-1, -2, -3, -4); Matrix22F absoluteM = Matrix22F.Absolute(m); Assert.AreEqual(1, absoluteM.M00); Assert.AreEqual(2, absoluteM.M01); Assert.AreEqual(3, absoluteM.M10); Assert.AreEqual(4, absoluteM.M11); m = new Matrix22F(1, 2, 3, 4); absoluteM = Matrix22F.Absolute(m); Assert.AreEqual(1, absoluteM.M00); Assert.AreEqual(2, absoluteM.M01); Assert.AreEqual(3, absoluteM.M10); Assert.AreEqual(4, absoluteM.M11); }
public void TestToString() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.IsFalse(String.IsNullOrEmpty(m.ToString())); }
public void MultiplicationOperator() { float s = 0.1234f; Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m = s * m; for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i] * s, m[i]); m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m = m * s; for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i] * s, m[i]); }
public void Indexer2d() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); for (int column = 0; column < 2; column++) for (int row = 0; row < 2; row++) Assert.AreEqual(columnMajor[column * 2 + row], m[row, column]); m = Matrix22F.Zero; for (int column = 0; column < 2; column++) for (int row = 0; row < 2; row++) m[row, column] = (row * 2 + column + 1); Assert.AreEqual(new Matrix22F(columnMajor, MatrixOrder.ColumnMajor), m); }
public void InverseException() { Matrix22F m = new Matrix22F(1, 2, 4, 8); m = m.Inverse; }
public void Invert() { Assert.AreEqual(Matrix22F.Identity, Matrix22F.Identity.Inverse); Matrix22F m = new Matrix22F(1, 2, 3, 4); Vector2F v = Vector2F.One; Vector2F w = m * v; Matrix22F im = m; im.Invert(); Assert.IsTrue(Vector2F.AreNumericallyEqual(v, im * w)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * im)); }
public void IsNaN() { const int numberOfRows = 2; const int numberOfColumns = 2; Assert.IsFalse(new Matrix22F().IsNaN); for (int r = 0; r < numberOfRows; r++) { for (int c = 0; c < numberOfColumns; c++) { Matrix22F m = new Matrix22F(); m[r, c] = float.NaN; Assert.IsTrue(m.IsNaN); } } }
public void IsSymmetric() { Matrix22F m = new Matrix22F(new float[2, 2] {{ 1, 2 }, { 2, 4 } }); Assert.AreEqual(true, m.IsSymmetric); m = new Matrix22F(new float[2, 2] {{ 2, 1 }, { 4, 2 } }); Assert.AreEqual(false, m.IsSymmetric); }
public void SerializationBinary() { Matrix22F m1 = new Matrix22F(12, 23, 45, 56.3f); Matrix22F m2; string fileName = "SerializationMatrix22F.bin"; if (File.Exists(fileName)) File.Delete(fileName); FileStream fs = new FileStream(fileName, FileMode.Create); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, m1); fs.Close(); fs = new FileStream(fileName, FileMode.Open); formatter = new BinaryFormatter(); m2 = (Matrix22F) formatter.Deserialize(fs); fs.Close(); Assert.AreEqual(m1, m2); }
public void ToList() { Matrix22F m = new Matrix22F(1, 2, 3, 4); IList<float> list = m.ToList(MatrixOrder.RowMajor); for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i], list[i]); list = m.ToList(MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) Assert.AreEqual(columnMajor[i], list[i]); }
public void ToArrayJagged() { Matrix22F m = new Matrix22F(1, 2, 3, 4); float[][] array = m.ToArrayJagged(); for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) Assert.AreEqual(i * 2 + j + 1, array[i][j]); array = (float[][]) m; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) Assert.AreEqual(i * 2 + j + 1, array[i][j]); }
public void SerializationJson() { Matrix22F m1 = new Matrix22F(12, 23, 45, 56.3f); Matrix22F m2; string fileName = "SerializationMatrix22F.json"; if (File.Exists(fileName)) File.Delete(fileName); var serializer = new DataContractJsonSerializer(typeof(Matrix22F)); using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) serializer.WriteObject(stream, m1); using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) m2 = (Matrix22F)serializer.ReadObject(stream); Assert.AreEqual(m1, m2); }
public void SerializationXml() { Matrix22F m1 = new Matrix22F(12, 23, 45, 67); Matrix22F m2; string fileName = "SerializationMatrix22F.xml"; if (File.Exists(fileName)) File.Delete(fileName); XmlSerializer serializer = new XmlSerializer(typeof(Matrix22F)); StreamWriter writer = new StreamWriter(fileName); serializer.Serialize(writer, m1); writer.Close(); serializer = new XmlSerializer(typeof(Matrix22F)); FileStream fileStream = new FileStream(fileName, FileMode.Open); m2 = (Matrix22F) serializer.Deserialize(fileStream); Assert.AreEqual(m1, m2); }
public void SerializationXml2() { Matrix22F m1 = new Matrix22F(12, 23, 45, 56.3f); Matrix22F m2; string fileName = "SerializationMatrix22F_DataContractSerializer.xml"; if (File.Exists(fileName)) File.Delete(fileName); var serializer = new DataContractSerializer(typeof(Matrix22F)); using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) using (var writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8)) serializer.WriteObject(writer, m1); using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) using (var reader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas())) m2 = (Matrix22F)serializer.ReadObject(reader); Assert.AreEqual(m1, m2); }
public void TestEquals() { Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.IsTrue(m1.Equals(m1)); Assert.IsTrue(m1.Equals(m2)); for (int i = 0; i < 4; i++) { m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2[i] += 0.1f; Assert.IsFalse(m1.Equals(m2)); } Assert.IsFalse(m1.Equals(m1.ToString())); }
public void SetRowException2() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m.SetRow(2, Vector2F.One); }
public void Multiplication() { float s = 0.1234f; Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m = Matrix22F.Multiply(s, m); for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i] * s, m[i]); }
public void NegationOperator() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) Assert.AreEqual(-rowMajor[i], (-m)[i]); }
public void AreEqual() { float originalEpsilon = Numeric.EpsilonF; Numeric.EpsilonF = 1e-8f; Matrix22F m0 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m1 += new Matrix22F(0.000001f); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2 += new Matrix22F(0.00000001f); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m0)); Assert.IsFalse(Matrix22F.AreNumericallyEqual(m0, m1)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m2)); Numeric.EpsilonF = originalEpsilon; }
public void ToArray1D() { Matrix22F m = new Matrix22F(1, 2, 3, 4); float[] array = m.ToArray1D(MatrixOrder.RowMajor); for (int i = 0; i < 4; i++) Assert.AreEqual(rowMajor[i], array[i]); array = m.ToArray1D(MatrixOrder.ColumnMajor); for (int i = 0; i < 4; i++) Assert.AreEqual(columnMajor[i], array[i]); }
public void InvertException() { Matrix22F m = new Matrix22F(1, 2, 4, 8); m.Invert(); }
public void MultiplyVectorOperator() { Vector2F v = new Vector2F(2.34f, 3.45f); Assert.AreEqual(v, Matrix22F.Identity * v); Assert.AreEqual(Vector2F.Zero, Matrix22F.Zero * v); Matrix22F m = new Matrix22F(12, 23, 45, 67); Assert.IsTrue(Vector2F.AreNumericallyEqual(v, m * m.Inverse * v)); for (int i = 0; i < 2; i++) Assert.AreEqual(Vector2F.Dot(m.GetRow(i), v), (m * v)[i]); }
public void MultiplyMatrixOperator() { Matrix22F m = new Matrix22F(12, 23, 45, 67); Assert.AreEqual(Matrix22F.Zero, m * Matrix22F.Zero); Assert.AreEqual(Matrix22F.Zero, Matrix22F.Zero * m); Assert.AreEqual(m, m * Matrix22F.Identity); Assert.AreEqual(m, Matrix22F.Identity * m); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * m.Inverse)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m.Inverse * m)); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(12, 23, 45, 67); Matrix22F result = m1 * m2; for (int column = 0; column < 2; column++) for (int row = 0; row < 2; row++) Assert.AreEqual(Vector2F.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); }
public void Properties() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(1.0f, m.M00); Assert.AreEqual(2.0f, m.M01); Assert.AreEqual(3.0f, m.M10); Assert.AreEqual(4.0f, m.M11); m = Matrix22F.Zero; m.M00 = 1.0f; m.M01 = 2.0f; m.M10 = 3.0f; m.M11 = 4.0f; Assert.AreEqual(new Matrix22F(columnMajor, MatrixOrder.ColumnMajor), m); }
public void SetColumnException1() { Matrix22F m = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m.SetColumn(-1, Vector2F.One); }
public void Indexer1dException4() { Matrix22F m = new Matrix22F(); float x = m[4]; }