public void ConstructorValuesAreAccessibleByIndexer() { Matrix3x1 matrix3x1; matrix3x1 = new Matrix3x1(); for (int x = 0; x < matrix3x1.Columns; x++) { for (int y = 0; y < matrix3x1.Rows; y++) { Assert.AreEqual(0, matrix3x1[x, y], Epsilon); } } double value = 33.33; matrix3x1 = new Matrix3x1(value); for (int x = 0; x < matrix3x1.Columns; x++) { for (int y = 0; y < matrix3x1.Rows; y++) { Assert.AreEqual(value, matrix3x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix3x1); for (int y = 0; y < matrix3x1.Rows; y++) { for (int x = 0; x < matrix3x1.Columns; x++) { Assert.AreEqual(y * matrix3x1.Columns + x, matrix3x1[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { GenerateFilledMatrixWithValues(out Matrix3x4 value); Matrix3x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } Matrix3x1 row2 = value.Row2; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 1], row2[x, 0]); } Matrix3x1 row3 = value.Row3; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 2], row3[x, 0]); } }
public void EqualityOperatorWorksCorrectly() { Matrix3x1 value1 = new Matrix3x1(100); Matrix3x1 value2 = new Matrix3x1(50) * 2; Assert.Equal(value1, value2); Assert.True(value1 == value2, "Equality operator failed."); }
public void ConstantValuesAreCorrect() { Matrix3x1 matrix3x1 = new Matrix3x1(); Assert.AreEqual(3, matrix3x1.Columns); Assert.AreEqual(1, matrix3x1.Rows); Assert.AreEqual(Matrix3x1.ColumnCount, matrix3x1.Columns); Assert.AreEqual(Matrix3x1.RowCount, matrix3x1.Rows); }
public void MuliplyByMatrix3x2ProducesMatrix3x1() { Matrix2x1 matrix1 = new Matrix2x1(3); Matrix3x2 matrix2 = new Matrix3x2(2); Matrix3x1 result = matrix1 * matrix2; Matrix3x1 expected = new Matrix3x1(12, 12, 12); Assert.Equal(expected, result); }
public void AccessorThrowsWhenOutOfBounds() { Matrix3x1 matrix3x1 = new Matrix3x1(); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix3x1[-1, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix3x1[0, -1] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix3x1[3, 0] = 0; }); Assert.Throws <ArgumentOutOfRangeException>(() => { matrix3x1[0, 1] = 0; }); }
public void MuliplyByMatrix4x3ProducesMatrix4x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix4x3 matrix2 = new Matrix4x3(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(18, 18, 18, 18); Assert.Equal(expected, result); }
public void ConstantValuesAreCorrect() { Matrix3x1 matrix3x1 = new Matrix3x1(); Assert.Equal(3, matrix3x1.Columns); Assert.Equal(1, matrix3x1.Rows); Assert.Equal(Matrix3x1.ColumnCount, matrix3x1.Columns); Assert.Equal(Matrix3x1.RowCount, matrix3x1.Rows); }
static Matrix3x1 mul(Matrix3x3 A, Matrix3x1 B) // float3x1 mul(float3x3 A, float3x1 B); { Matrix3x1 result = new Matrix3x1(); result.m00 = (float)((double)A.m00 * (double)B.m00 + (double)A.m01 * (double)B.m10 + (double)A.m02 * (double)B.m20); result.m10 = (float)((double)A.m10 * (double)B.m00 + (double)A.m11 * (double)B.m10 + (double)A.m12 * (double)B.m20); result.m20 = (float)((double)A.m20 * (double)B.m00 + (double)A.m21 * (double)B.m10 + (double)A.m22 * (double)B.m20); return(result); }
public void MuliplyByMatrix3x4ProducesMatrix3x1() { Matrix4x1 matrix1 = new Matrix4x1(3); Matrix3x4 matrix2 = new Matrix3x4(2); Matrix3x1 result = matrix1 * matrix2; Matrix3x1 expected = new Matrix3x1(24, 24, 24); Assert.Equal(expected, result); }
public void MuliplyByMatrix3x1ProducesMatrix3x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix3x1 matrix2 = new Matrix3x1(2); Matrix3x2 result = matrix1 * matrix2; Matrix3x2 expected = new Matrix3x2(6, 6, 6, 6, 6, 6); Assert.Equal(expected, result); }
public void HashCodeGenerationWorksCorrectly() { HashSet <int> hashCodes = new HashSet <int>(); Matrix3x1 value = new Matrix3x1(1); for (int i = 2; i <= 100; i++) { Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure."); value *= i; } }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix3x1 value1 = new Matrix3x1(100); Matrix3x1 value2 = new Matrix3x1(1); Matrix3x1 result = value1 - value2; for (int y = 0; y < Matrix3x1.RowCount; y++) { for (int x = 0; x < Matrix3x1.ColumnCount; x++) { Assert.Equal(100 - 1, result[x, y], Epsilon); } } }
public void RowAccessorAreCorrect() { Matrix3x2 value; GenerateFilledMatrixWithValues(out value); Matrix3x1 row1 = value.Row1; for (int x = 0; x < value.Columns; x++) { Assert.Equal(value[x, 0], row1[x, 0]); } }
public void MemberGetAndSetValuesCorrectly() { Matrix3x1 matrix3x1 = new Matrix3x1(); matrix3x1.M11 = 0; matrix3x1.M21 = 1; matrix3x1.M31 = 2; Assert.Equal(0, matrix3x1.M11, Epsilon); Assert.Equal(1, matrix3x1.M21, Epsilon); Assert.Equal(2, matrix3x1.M31, Epsilon); Assert.Equal(matrix3x1[0, 0], matrix3x1.M11, Epsilon); Assert.Equal(matrix3x1[1, 0], matrix3x1.M21, Epsilon); Assert.Equal(matrix3x1[2, 0], matrix3x1.M31, Epsilon); }
private void OnEnable() { Mesh mesh = skinnedMeshRenderer.sharedMesh; normal = mesh.normals[Random.Range(0, mesh.normals.Length - 1)]; tangent = mesh.tangents[Random.Range(0, mesh.tangents.Length - 1)]; unity_WorldToObject = skinnedMeshRenderer.worldToLocalMatrix; unity_ObjectToWorld = skinnedMeshRenderer.localToWorldMatrix; // gameObject.transform.localToWorldMatrix // NORMAL Matrix1x3 n1 = new Matrix1x3(normal); normal1x3 = mul(n1, unity_WorldToObject); normal1x3.Normalize(); Matrix3x1 n2 = new Matrix3x1(normal); normal3x1 = mul(unity_ObjectToWorld, n2); // unity_WorldToObject.MultiplyVector(normal); normal3x1.Normalize(); // TANGENT Matrix1x3 t1 = new Matrix1x3(tangent); tangent1x3NOK = mul(t1, unity_ObjectToWorld); //tangent1x3NOK.Normalize(); Matrix3x1 t2 = new Matrix3x1(tangent); tangent3x1OK = mul(unity_ObjectToWorld, t2);// unity_ObjectToWorld.MultiplyVector(tangent); //tangent3x1OK.Normalize(); Vector3 a = new Vector3(1, 2, 3); // Vector4 a = new Vector4(1, 2, 3, 4); Matrix1x3 b = new Matrix1x3(a); // Matrix1x4 b = new Matrix1x4(a); Matrix3x1 c = new Matrix3x1(a); // Matrix4x1 c = new Matrix4x1(a); Matrix3x3 m = new Matrix3x3(new Vector3(1, 3, 1), new Vector3(2, 2, 2), new Vector3(3, 1, 3)); // Matrix4x4 m = new Matrix4x4(new Vector4(1, 4, 1, 4), new Vector4(2, 3, 2, 3), new Vector4(3, 2, 3, 2), new Vector4(4, 1, 4, 1)); // Debug.Log(mul(a, m)); // Debug.Log(mul(b, m)); // Debug.Log(mul(m, c)); // Matrix4x4 shrink = new Matrix4x4(new Vector4(1, 5, 9, 13), new Vector4(2, 6, 10, 14), new Vector4(3, 7, 11, 15), new Vector4(4, 8, 12, 13)); // Debug.Log((Matrix3x3) shrink); }
public void ScalarMultiplicationIsCorrect() { GenerateFilledMatrixWithValues(out Matrix3x1 matrix3x1); for (double c = -10; c <= 10; c += 0.5) { Matrix3x1 result = matrix3x1 * c; for (int y = 0; y < matrix3x1.Rows; y++) { for (int x = 0; x < matrix3x1.Columns; x++) { Assert.Equal(matrix3x1[x, y] * c, result[x, y], Epsilon); } } } }
public void IndexerGetAndSetValuesCorrectly() { Matrix3x1 matrix3x1 = new Matrix3x1(); for (int x = 0; x < matrix3x1.Columns; x++) { for (int y = 0; y < matrix3x1.Rows; y++) { matrix3x1[x, y] = y * matrix3x1.Columns + x; } } for (int y = 0; y < matrix3x1.Rows; y++) { for (int x = 0; x < matrix3x1.Columns; x++) { Assert.Equal(y * matrix3x1.Columns + x, matrix3x1[x, y], Epsilon); } } }
public void CanMultiplyMatrices() { var firstMatrix = new Matrix1x3(); var secondMatrix = new Matrix3x1(); firstMatrix[0, 0] = 1; firstMatrix[0, 1] = 2; firstMatrix[0, 2] = 3; secondMatrix[0, 0] = 2; secondMatrix[1, 0] = 1; secondMatrix[2, 0] = 2; var matrixProduct = MatrixUtils.Multiply <Matrix1x1>(firstMatrix, secondMatrix); Assert.AreEqual(matrixProduct[0, 0], 10); // -------------------------------- var thirdMatrix = new Matrix3x3 {
public void ConstructorValuesAreAccessibleByIndexer() { Matrix3x1 matrix3x1; matrix3x1 = new Matrix3x1(); for (int x = 0; x < matrix3x1.Columns; x++) { for (int y = 0; y < matrix3x1.Rows; y++) { Assert.Equal(0, matrix3x1[x, y], Epsilon); } } double value = 33.33; matrix3x1 = new Matrix3x1(value); for (int x = 0; x < matrix3x1.Columns; x++) { for (int y = 0; y < matrix3x1.Rows; y++) { Assert.Equal(value, matrix3x1[x, y], Epsilon); } } GenerateFilledMatrixWithValues(out matrix3x1); for (int y = 0; y < matrix3x1.Rows; y++) { for (int x = 0; x < matrix3x1.Columns; x++) { Assert.Equal(y * matrix3x1.Columns + x, matrix3x1[x, y], Epsilon); } } }
public void AccessorThrowsWhenOutOfBounds() { Matrix3x1 matrix3x1 = new Matrix3x1(); try { matrix3x1[-1, 0] = 0; Assert.Fail("Matrix3x1[-1, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix3x1[0, -1] = 0; Assert.Fail("Matrix3x1[0, -1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix3x1[3, 0] = 0; Assert.Fail("Matrix3x1[3, 0] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } try { matrix3x1[0, 1] = 0; Assert.Fail("Matrix3x1[0, 1] did not throw when it should have."); } catch (ArgumentOutOfRangeException) { } }
public void MuliplyByMatrix3x1ProducesMatrix3x2() { Matrix1x2 matrix1 = new Matrix1x2(3); Matrix3x1 matrix2 = new Matrix3x1(2); Matrix3x2 result = matrix1 * matrix2; Matrix3x2 expected = new Matrix3x2(6, 6, 6, 6, 6, 6); Assert.AreEqual(expected, result); }
public void SimpleAdditionGeneratesCorrectValues() { Matrix3x1 value1 = new Matrix3x1(1); Matrix3x1 value2 = new Matrix3x1(99); Matrix3x1 result = value1 + value2; for (int y = 0; y < Matrix3x1.RowCount; y++) { for (int x = 0; x < Matrix3x1.ColumnCount; x++) { Assert.Equal(1 + 99, result[x, y], Epsilon); } } }
public void AccessorThrowsWhenOutOfBounds() { Matrix3x1 matrix3x1 = new Matrix3x1(); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix3x1[-1, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix3x1[0, -1] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix3x1[3, 0] = 0; }); Assert.Throws<ArgumentOutOfRangeException>(() => { matrix3x1[0, 1] = 0; }); }
public void MuliplyByMatrix3x2ProducesMatrix3x1() { Matrix2x1 matrix1 = new Matrix2x1(3); Matrix3x2 matrix2 = new Matrix3x2(2); Matrix3x1 result = matrix1 * matrix2; Matrix3x1 expected = new Matrix3x1(12, 12, 12); Assert.AreEqual(expected, result); }
public void SimpleSubtractionGeneratesCorrectValues() { Matrix3x1 value1 = new Matrix3x1(100); Matrix3x1 value2 = new Matrix3x1(1); Matrix3x1 result = value1 - value2; for (int y = 0; y < Matrix3x1.RowCount; y++) { for (int x = 0; x < Matrix3x1.ColumnCount; x++) { Assert.AreEqual(100 - 1, result[x, y], Epsilon); } } }
private void GenerateFilledMatrixWithValues(out Matrix3x1 matrix) { matrix = new Matrix3x1(0, 1, 2); }
public void MuliplyByMatrix4x3ProducesMatrix4x1() { Matrix3x1 matrix1 = new Matrix3x1(3); Matrix4x3 matrix2 = new Matrix4x3(2); Matrix4x1 result = matrix1 * matrix2; Matrix4x1 expected = new Matrix4x1(18, 18, 18, 18); Assert.AreEqual(expected, result); }
public void MuliplyByMatrix3x1ProducesMatrix3x3() { Matrix1x3 matrix1 = new Matrix1x3(3); Matrix3x1 matrix2 = new Matrix3x1(2); Matrix3x3 result = matrix1 * matrix2; Matrix3x3 expected = new Matrix3x3(6, 6, 6, 6, 6, 6, 6, 6, 6); Assert.Equal(expected, result); }
public void EqualityOperatorWorksCorrectly() { Matrix3x1 value1 = new Matrix3x1(100); Matrix3x1 value2 = new Matrix3x1(50) * 2; Assert.AreEqual(value1, value2); Assert.IsTrue(value1 == value2, "Equality operator failed."); }
public void MuliplyByMatrix3x4ProducesMatrix3x1() { Matrix4x1 matrix1 = new Matrix4x1(3); Matrix3x4 matrix2 = new Matrix3x4(2); Matrix3x1 result = matrix1 * matrix2; Matrix3x1 expected = new Matrix3x1(24, 24, 24); Assert.AreEqual(expected, result); }
public void HashCodeGenerationWorksCorrectly() { HashSet<int> hashCodes = new HashSet<int>(); Matrix3x1 value = new Matrix3x1(1); for (int i = 2; i <= 100; i++) { if (!hashCodes.Add(value.GetHashCode())) { Assert.Fail("Unique hash code generation failure."); } value *= i; } }
public void MemberGetAndSetValuesCorrectly() { Matrix3x1 matrix3x1 = new Matrix3x1(); matrix3x1.M11 = 0; matrix3x1.M21 = 1; matrix3x1.M31 = 2; Assert.AreEqual(0, matrix3x1.M11, Epsilon); Assert.AreEqual(1, matrix3x1.M21, Epsilon); Assert.AreEqual(2, matrix3x1.M31, Epsilon); Assert.AreEqual(matrix3x1[0, 0], matrix3x1.M11, Epsilon); Assert.AreEqual(matrix3x1[1, 0], matrix3x1.M21, Epsilon); Assert.AreEqual(matrix3x1[2, 0], matrix3x1.M31, Epsilon); }