Пример #1
0
        public void ConstructorValuesAreAccessibleByIndexer()
        {
            Matrix4x2 matrix4x2;

            matrix4x2 = new Matrix4x2();

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    Assert.Equal(0, matrix4x2[x, y], Epsilon);
                }
            }

            double value = 33.33;
            matrix4x2 = new Matrix4x2(value);

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    Assert.Equal(value, matrix4x2[x, y], Epsilon);
                }
            }

            GenerateFilledMatrixWithValues(out matrix4x2);

            for (int y = 0; y < matrix4x2.Rows; y++)
            {
                for (int x = 0; x < matrix4x2.Columns; x++)
                {
                    Assert.Equal(y * matrix4x2.Columns + x, matrix4x2[x, y], Epsilon);
                }
            }
        }
Пример #2
0
        public void MemberGetAndSetValuesCorrectly()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            matrix4x2.M11 = 0;
            matrix4x2.M21 = 1;
            matrix4x2.M31 = 2;
            matrix4x2.M41 = 3;
            matrix4x2.M12 = 4;
            matrix4x2.M22 = 5;
            matrix4x2.M32 = 6;
            matrix4x2.M42 = 7;

            Assert.Equal(0, matrix4x2.M11, Epsilon);
            Assert.Equal(1, matrix4x2.M21, Epsilon);
            Assert.Equal(2, matrix4x2.M31, Epsilon);
            Assert.Equal(3, matrix4x2.M41, Epsilon);
            Assert.Equal(4, matrix4x2.M12, Epsilon);
            Assert.Equal(5, matrix4x2.M22, Epsilon);
            Assert.Equal(6, matrix4x2.M32, Epsilon);
            Assert.Equal(7, matrix4x2.M42, Epsilon);

            Assert.Equal(matrix4x2[0, 0], matrix4x2.M11, Epsilon);
            Assert.Equal(matrix4x2[1, 0], matrix4x2.M21, Epsilon);
            Assert.Equal(matrix4x2[2, 0], matrix4x2.M31, Epsilon);
            Assert.Equal(matrix4x2[3, 0], matrix4x2.M41, Epsilon);
            Assert.Equal(matrix4x2[0, 1], matrix4x2.M12, Epsilon);
            Assert.Equal(matrix4x2[1, 1], matrix4x2.M22, Epsilon);
            Assert.Equal(matrix4x2[2, 1], matrix4x2.M32, Epsilon);
            Assert.Equal(matrix4x2[3, 1], matrix4x2.M42, Epsilon);
        }
Пример #3
0
        public void EqualityOperatorWorksCorrectly()
        {
            Matrix4x2 value1 = new Matrix4x2(100);
            Matrix4x2 value2 = new Matrix4x2(50) * 2;

            Assert.Equal(value1, value2);
            Assert.True(value1 == value2, "Equality operator failed.");
        }
Пример #4
0
        public void ConstantValuesAreCorrect()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            Assert.Equal(4, matrix4x2.Columns);
            Assert.Equal(2, matrix4x2.Rows);
            Assert.Equal(Matrix4x2.ColumnCount, matrix4x2.Columns);
            Assert.Equal(Matrix4x2.RowCount, matrix4x2.Rows);
        }
Пример #5
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x2[-1, 0] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x2[0, -1] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x2[4, 0] = 0; });
            Assert.Throws <ArgumentOutOfRangeException>(() => { matrix4x2[0, 2] = 0; });
        }
Пример #6
0
        public void MuliplyByMatrix4x2ProducesMatrix4x1()
        {
            Matrix2x1 matrix1  = new Matrix2x1(3);
            Matrix4x2 matrix2  = new Matrix4x2(2);
            Matrix4x1 result   = matrix1 * matrix2;
            Matrix4x1 expected = new Matrix4x1(12, 12, 12, 12);

            Assert.Equal(expected, result);
        }
Пример #7
0
        public void ConstantValuesAreCorrect()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            Assert.Equal(4, matrix4x2.Columns);
            Assert.Equal(2, matrix4x2.Rows);
            Assert.Equal(Matrix4x2.ColumnCount, matrix4x2.Columns);
            Assert.Equal(Matrix4x2.RowCount, matrix4x2.Rows);
        }
Пример #8
0
        public void MuliplyByMatrix4x1ProducesMatrix4x2()
        {
            Matrix1x2 matrix1  = new Matrix1x2(3);
            Matrix4x1 matrix2  = new Matrix4x1(2);
            Matrix4x2 result   = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(6, 6, 6, 6,
                                               6, 6, 6, 6);

            Assert.Equal(expected, result);
        }
Пример #9
0
 public static void UniformMatrix4x2(int location, bool transpose, ref Matrix4x2 matrix)
 {
     unsafe
     {
         fixed(float *matrix_ptr = &matrix.Row0.X)
         {
             GL.UniformMatrix4x2(location, 1, transpose, matrix_ptr);
         }
     }
 }
Пример #10
0
        public void MuliplyByMatrix4x4ProducesMatrix4x2()
        {
            Matrix4x2 matrix1  = new Matrix4x2(3);
            Matrix4x4 matrix2  = new Matrix4x4(2);
            Matrix4x2 result   = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(24, 24, 24, 24,
                                               24, 24, 24, 24);

            Assert.Equal(expected, result);
        }
Пример #11
0
        public void MuliplyByMatrix4x3ProducesMatrix4x2()
        {
            Matrix3x2 matrix1  = new Matrix3x2(3);
            Matrix4x3 matrix2  = new Matrix4x3(2);
            Matrix4x2 result   = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(18, 18, 18, 18,
                                               18, 18, 18, 18);

            Assert.Equal(expected, result);
        }
Пример #12
0
        public void SetUniform(string name, Matrix4x2 v, bool transpose)
        {
            //If the uniform doesn't exist, get it.
            if (!mUniform.ContainsKey(name))
            {
                mUniform.Add(name, GL.GetUniformLocation(siProgramID, name));
            }

            //Set the uniform.
            GL.ProgramUniformMatrix4x2(siProgramID, mUniform[name], transpose, ref v);
        }
Пример #13
0
        public void HashCodeGenerationWorksCorrectly()
        {
            HashSet <int> hashCodes = new HashSet <int>();
            Matrix4x2     value     = new Matrix4x2(1);

            for (int i = 2; i <= 100; i++)
            {
                Assert.True(hashCodes.Add(value.GetHashCode()), "Unique hash code generation failure.");

                value *= i;
            }
        }
Пример #14
0
        public void SimpleSubtractionGeneratesCorrectValues()
        {
            Matrix4x2 value1 = new Matrix4x2(100);
            Matrix4x2 value2 = new Matrix4x2(1);
            Matrix4x2 result = value1 - value2;

            for (int y = 0; y < Matrix4x2.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x2.ColumnCount; x++)
                {
                    Assert.Equal(100 - 1, result[x, y], Epsilon);
                }
            }
        }
Пример #15
0
        public void ScalarMultiplicationIsCorrect()
        {
            GenerateFilledMatrixWithValues(out Matrix4x2 matrix4x2);

            for (double c = -10; c <= 10; c += 0.5)
            {
                Matrix4x2 result = matrix4x2 * c;

                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    for (int x = 0; x < matrix4x2.Columns; x++)
                    {
                        Assert.Equal(matrix4x2[x, y] * c, result[x, y], Epsilon);
                    }
                }
            }
        }
Пример #16
0
        public void IndexerGetAndSetValuesCorrectly()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    matrix4x2[x, y] = y * matrix4x2.Columns + x;
                }
            }

            for (int y = 0; y < matrix4x2.Rows; y++)
            {
                for (int x = 0; x < matrix4x2.Columns; x++)
                {
                    Assert.Equal(y * matrix4x2.Columns + x, matrix4x2[x, y], Epsilon);
                }
            }
        }
Пример #17
0
        public void IndexerGetAndSetValuesCorrectly()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    matrix4x2[x, y] = y * matrix4x2.Columns + x;
                }
            }

            for (int y = 0; y < matrix4x2.Rows; y++)
            {
                for (int x = 0; x < matrix4x2.Columns; x++)
                {
                    Assert.Equal(y * matrix4x2.Columns + x, matrix4x2[x, y], Epsilon);
                }
            }
        }
Пример #18
0
        public void ConstructorValuesAreAccessibleByIndexer()
        {
            Matrix4x2 matrix4x2;

            matrix4x2 = new Matrix4x2();

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    Assert.Equal(0, matrix4x2[x, y], Epsilon);
                }
            }

            double value = 33.33;

            matrix4x2 = new Matrix4x2(value);

            for (int x = 0; x < matrix4x2.Columns; x++)
            {
                for (int y = 0; y < matrix4x2.Rows; y++)
                {
                    Assert.Equal(value, matrix4x2[x, y], Epsilon);
                }
            }

            GenerateFilledMatrixWithValues(out matrix4x2);

            for (int y = 0; y < matrix4x2.Rows; y++)
            {
                for (int x = 0; x < matrix4x2.Columns; x++)
                {
                    Assert.Equal(y * matrix4x2.Columns + x, matrix4x2[x, y], Epsilon);
                }
            }
        }
Пример #19
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            try
            {
                matrix4x2[-1, 0] = 0;
                Assert.Fail("Matrix4x2[-1, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x2[0, -1] = 0;
                Assert.Fail("Matrix4x2[0, -1] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x2[4, 0] = 0;
                Assert.Fail("Matrix4x2[4, 0] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }

            try
            {
                matrix4x2[0, 2] = 0;
                Assert.Fail("Matrix4x2[0, 2] did not throw when it should have.");
            }
            catch (ArgumentOutOfRangeException)
            { }
        }
Пример #20
0
 private static void Set(int location, Matrix4x2 value) => GL.UniformMatrix4x2(location, false, ref value);
Пример #21
0
        public void MuliplyByMatrix4x1ProducesMatrix4x2()
        {
            Matrix1x2 matrix1 = new Matrix1x2(3);
            Matrix4x1 matrix2 = new Matrix4x1(2);
            Matrix4x2 result = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(6, 6, 6, 6,
                                               6, 6, 6, 6);

            Assert.AreEqual(expected, result);
        }
Пример #22
0
 private void GenerateFilledMatrixWithValues(out Matrix4x2 matrix)
 {
     matrix = new Matrix4x2(0, 1, 2, 3,
                            4, 5, 6, 7);
 }
Пример #23
0
        public void SimpleSubtractionGeneratesCorrectValues()
        {
            Matrix4x2 value1 = new Matrix4x2(100);
            Matrix4x2 value2 = new Matrix4x2(1);
            Matrix4x2 result = value1 - value2;

            for (int y = 0; y < Matrix4x2.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x2.ColumnCount; x++)
                {
                    Assert.AreEqual(100 - 1, result[x, y], Epsilon);
                }
            }
        }
Пример #24
0
        public void SimpleAdditionGeneratesCorrectValues()
        {
            Matrix4x2 value1 = new Matrix4x2(1);
            Matrix4x2 value2 = new Matrix4x2(99);
            Matrix4x2 result = value1 + value2;

            for (int y = 0; y < Matrix4x2.RowCount; y++)
            {
                for (int x = 0; x < Matrix4x2.ColumnCount; x++)
                {
                    Assert.Equal(1 + 99, result[x, y], Epsilon);
                }
            }
        }
Пример #25
0
        /// <summary>
        /// Sets the value of the uniform.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="transpose">Indicates whether to transpose the matrix value before transmitting it to the shader.</param>
        public unsafe void Set(ref Matrix4x2 value, bool transpose)
        {
            this.VerifyAccess();

            fixed (Matrix4x2* pValue = &value)
            {
                GL.ProgramUniformMatrix4x2(this.Program, this.Location, 1, transpose, (float*)pValue);
            }
        }
Пример #26
0
        public void MuliplyByMatrix4x2ProducesMatrix4x3()
        {
            Matrix2x3 matrix1 = new Matrix2x3(3);
            Matrix4x2 matrix2 = new Matrix4x2(2);
            Matrix4x3 result = matrix1 * matrix2;
            Matrix4x3 expected = new Matrix4x3(12, 12, 12, 12, 
                                               12, 12, 12, 12, 
                                               12, 12, 12, 12);

            Assert.Equal(expected, result);
        }
Пример #27
0
        public void MuliplyByMatrix4x2ProducesMatrix4x1()
        {
            Matrix2x1 matrix1 = new Matrix2x1(3);
            Matrix4x2 matrix2 = new Matrix4x2(2);
            Matrix4x1 result = matrix1 * matrix2;
            Matrix4x1 expected = new Matrix4x1(12, 12, 12, 12);

            Assert.AreEqual(expected, result);
        }
Пример #28
0
 public void SetUniform(Matrix4x2 matrix, int id)
 {
     GL.UniformMatrix4x2(id, true, ref matrix);
 }
Пример #29
0
 public static void UniformMatrix4x2(int location, bool transpose, ref Matrix4x2 matrix)
 {
     unsafe
     {
         fixed (float* matrix_ptr = &matrix.Row0.X)
         {
             GL.UniformMatrix4x2(location, 1, transpose, matrix_ptr);
         }
     }
 }
Пример #30
0
 public void SetUniform(string uniform, Matrix4x2 value)
 {
     GL.UniformMatrix4x2(GL.GetUniformLocation(program, uniform), false, ref value);
 }
Пример #31
0
 public void Set(ref Matrix4x2 value, bool transpose)
 {
     this.Uniform.Set(ref value, transpose);
 }
Пример #32
0
        public void AccessorThrowsWhenOutOfBounds()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x2[-1, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x2[0, -1] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x2[4, 0] = 0; });
            Assert.Throws<ArgumentOutOfRangeException>(() => { matrix4x2[0, 2] = 0; });
        }
Пример #33
0
 /// <summary>
 /// Sets the value of the uniform.
 /// </summary>
 /// <remarks>The value will not be transposed.</remarks>
 /// <param name="value">The value.</param>
 public void Set(ref Matrix4x2 value)
 {
     this.Set(ref value, false);
 }
Пример #34
0
        public void HashCodeGenerationWorksCorrectly()
        {
            HashSet<int> hashCodes = new HashSet<int>();
            Matrix4x2 value = new Matrix4x2(1);

            for (int i = 2; i <= 100; i++)
            {
                if (!hashCodes.Add(value.GetHashCode()))
                {
                    Assert.Fail("Unique hash code generation failure.");
                }

                value *= i;
            }
        }
Пример #35
0
 private void GenerateFilledMatrixWithValues(out Matrix4x2 matrix)
 {
     matrix = new Matrix4x2(0, 1, 2, 3,
                            4, 5, 6, 7);
 }
Пример #36
0
        public void MemberGetAndSetValuesCorrectly()
        {
            Matrix4x2 matrix4x2 = new Matrix4x2();

            matrix4x2.M11 = 0;
            matrix4x2.M21 = 1;
            matrix4x2.M31 = 2;
            matrix4x2.M41 = 3;
            matrix4x2.M12 = 4;
            matrix4x2.M22 = 5;
            matrix4x2.M32 = 6;
            matrix4x2.M42 = 7;

            Assert.AreEqual(0, matrix4x2.M11, Epsilon);
            Assert.AreEqual(1, matrix4x2.M21, Epsilon);
            Assert.AreEqual(2, matrix4x2.M31, Epsilon);
            Assert.AreEqual(3, matrix4x2.M41, Epsilon);
            Assert.AreEqual(4, matrix4x2.M12, Epsilon);
            Assert.AreEqual(5, matrix4x2.M22, Epsilon);
            Assert.AreEqual(6, matrix4x2.M32, Epsilon);
            Assert.AreEqual(7, matrix4x2.M42, Epsilon);

            Assert.AreEqual(matrix4x2[0, 0], matrix4x2.M11, Epsilon);
            Assert.AreEqual(matrix4x2[1, 0], matrix4x2.M21, Epsilon);
            Assert.AreEqual(matrix4x2[2, 0], matrix4x2.M31, Epsilon);
            Assert.AreEqual(matrix4x2[3, 0], matrix4x2.M41, Epsilon);
            Assert.AreEqual(matrix4x2[0, 1], matrix4x2.M12, Epsilon);
            Assert.AreEqual(matrix4x2[1, 1], matrix4x2.M22, Epsilon);
            Assert.AreEqual(matrix4x2[2, 1], matrix4x2.M32, Epsilon);
            Assert.AreEqual(matrix4x2[3, 1], matrix4x2.M42, Epsilon);
        }
Пример #37
0
        public void MuliplyByMatrix4x4ProducesMatrix4x2()
        {
            Matrix4x2 matrix1 = new Matrix4x2(3);
            Matrix4x4 matrix2 = new Matrix4x4(2);
            Matrix4x2 result = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(24, 24, 24, 24,
                                               24, 24, 24, 24);

            Assert.AreEqual(expected, result);
        }
Пример #38
0
        public void MuliplyByMatrix4x3ProducesMatrix4x2()
        {
            Matrix3x2 matrix1 = new Matrix3x2(3);
            Matrix4x3 matrix2 = new Matrix4x3(2);
            Matrix4x2 result = matrix1 * matrix2;
            Matrix4x2 expected = new Matrix4x2(18, 18, 18, 18,
                                               18, 18, 18, 18);

            Assert.AreEqual(expected, result);
        }
Пример #39
0
        public void EqualityOperatorWorksCorrectly()
        {
            Matrix4x2 value1 = new Matrix4x2(100);
            Matrix4x2 value2 = new Matrix4x2(50) * 2;

            Assert.AreEqual(value1, value2);
            Assert.IsTrue(value1 == value2, "Equality operator failed.");
        }
Пример #40
0
 public void Set(ref Matrix4x2 value)
 {
     this.Uniform.Set(ref value);
 }