Beispiel #1
0
        private Matrix <double> GetAMatrix(double[] arguments)
        {
            Matrix <double> A;

            double[] s = new double[5]; // 0..2m

            MatrixDouble[][] m = new MatrixDouble[3][];
            for (int i = 0; i < 3; i++)
            {
                m[i] = new MatrixDouble[3];
            }

            for (int i = 0; i < 5; i++)
            {
                double sum = 0.0;
                for (int j = 0; j < arguments.Length; j++)
                {
                    sum += IntPow(arguments[j], i);
                }
                s[i] = sum;
            }

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    m[i][j] = new MatrixDouble(s[i + j]);
                }
            }

            A = new Matrix <double>(m);
            return(A);
        }
Beispiel #2
0
        public void MatrixDouble_ToString()
        {
            MatrixDouble m = CreateRandomMatrix(3, 3);

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.DoesNotThrow(() => m.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Calculates the ViewPortTransfrom for the Current Heading and ViewPortCenter.
        /// Invalidates the ViewPort to schedule a redraw.
        /// </summary>
        protected virtual void UpdateViewPortTransform()
        {
            if (ViewPortTransform == null)
            {
                return;
            }

            double scaleFactor = ViewPortProjection.GetZoomFactor(ZoomLevel);

            double w2 = ActualWidth / 2d;
            double h2 = ActualHeight / 2d;

            MatrixDouble vpCenterTranslation = MatrixDouble.CreateTranslation(w2, h2);
            MatrixDouble scale = MatrixDouble.CreateScale(scaleFactor);

            MatrixDouble mapCenterTranslation = MatrixDouble.CreateTranslation(-ViewPortCenter.X, -ViewPortCenter.Y);

            double       heading        = Heading * Math.PI / 180.0;
            Point        center         = new Point(ViewPortCenter.X, ViewPortCenter.Y);
            MatrixDouble mapRotation    = MatrixDouble.CreateRotation(heading, center);
            MatrixDouble objectRotation = MatrixDouble.CreateRotation(heading);

            ViewPortTransform.Matrix    = (mapRotation * mapCenterTranslation * scale * vpCenterTranslation).ToXamlMatrix();
            ScaleRotateTransform.Matrix = (objectRotation * scale).ToXamlMatrix();
            ScaleTransform.Matrix       = scale.ToXamlMatrix();
            RotateTransform.Matrix      = objectRotation.ToXamlMatrix();
            TranslationTransform.Matrix = (mapCenterTranslation * vpCenterTranslation).ToXamlMatrix();

            InvalidateArrange();
            OnViewPortChangedEvent();
        }
Beispiel #4
0
        public virtual void MatrixDouble_Set()
        {
            MatrixDouble m = CreateRandomMatrix(2, 3);
            MatrixDouble z = new MatrixDouble(2, 3);

            m.Set(z);

            for (uint c = 0; c < 2; c++)
            {
                for (uint r = 0; r < 2; r++)
                {
                    Assert.AreEqual(0.0, m[c, r]);
                }
            }

            m = CreateRandomMatrix(2, 3);
            m.Set((IMatrix)z);

            for (uint c = 0; c < 2; c++)
            {
                for (uint r = 0; r < 2; r++)
                {
                    Assert.AreEqual(0.0, m[c, r]);
                }
            }
        }
Beispiel #5
0
        public void DoubleMatrix()
        {
            double[,] _m = new double[, ] {
                { 17, 21, 5, 8, 18, 5, 20, 19, 11, 7, 31, 7, 36, 15, 15, 27, 31, 3, 15, 2, 11, 30, 7, 34, 42 },
                { 36, 28, 0, 12, 31, 12, 29, 13, 31, 26, 27, 38, 7, 19, 0, 38, 15, 15, 16, 28, 37, 6, 34, 25, 42 },
                { 33, 22, 4, 10, 39, 31, 29, 27, 13, 11, 12, 30, 4, 8, 27, 39, 18, 18, 16, 10, 28, 16, 19, 11, 42 },
                { 3, 17, 27, 35, 14, 19, 36, 29, 33, 14, 18, 9, 7, 18, 13, 39, 36, 0, 24, 36, 7, 9, 33, 6, 42 },
                { 28, 16, 10, 19, 30, 24, 37, 16, 2, 32, 7, 22, 4, 34, 12, 34, 15, 22, 37, 29, 30, 18, 32, 39, 42 },
                { 4, 17, 13, 27, 32, 23, 4, 33, 23, 20, 7, 37, 9, 16, 39, 8, 17, 1, 6, 14, 11, 30, 35, 2, 42 },
                { 27, 30, 20, 24, 12, 3, 16, 9, 24, 10, 15, 12, 11, 9, 24, 19, 28, 14, 39, 24, 27, 15, 24, 38, 42 },
                { 23, 29, 12, 28, 12, 17, 28, 13, 21, 11, 0, 1, 2, 20, 20, 19, 3, 37, 12, 39, 1, 26, 36, 7, 42 },
                { 16, 27, 25, 36, 31, 11, 14, 12, 5, 22, 1, 23, 31, 28, 36, 6, 22, 1, 31, 39, 9, 22, 16, 8, 42 },
                { 33, 19, 20, 29, 2, 25, 37, 36, 32, 4, 11, 25, 32, 31, 21, 10, 36, 27, 36, 20, 19, 37, 28, 15, 42 },
                { 0, 5, 17, 39, 35, 37, 38, 34, 10, 17, 3, 12, 30, 25, 9, 20, 24, 4, 31, 26, 16, 11, 14, 30, 42 },
                { 19, 20, 2, 21, 26, 36, 29, 35, 30, 5, 28, 36, 8, 38, 1, 34, 6, 17, 14, 14, 27, 9, 20, 11, 42 },
                { 17, 15, 36, 14, 6, 2, 39, 29, 31, 26, 19, 15, 34, 17, 7, 14, 28, 8, 21, 25, 36, 13, 11, 25, 42 },
                { 2, 36, 19, 38, 37, 39, 2, 10, 39, 31, 3, 10, 39, 14, 28, 28, 5, 39, 5, 21, 18, 26, 0, 29, 42 },
                { 9, 0, 26, 19, 28, 35, 15, 4, 3, 10, 11, 10, 22, 0, 31, 31, 24, 9, 15, 3, 13, 37, 14, 13, 42 },
                { 19, 32, 19, 36, 8, 30, 7, 16, 36, 29, 28, 36, 13, 22, 21, 4, 16, 38, 6, 29, 2, 18, 5, 5, 42 },
                { 7, 13, 37, 9, 10, 36, 15, 12, 25, 12, 0, 36, 16, 18, 36, 13, 3, 35, 14, 32, 12, 35, 18, 1, 42 },
                { 27, 10, 27, 15, 30, 24, 11, 0, 26, 13, 29, 34, 32, 37, 5, 39, 14, 15, 10, 0, 21, 25, 28, 37, 42 },
                { 2, 33, 26, 7, 4, 12, 33, 12, 35, 36, 21, 0, 9, 0, 22, 1, 1, 0, 9, 2, 28, 2, 21, 5, 42 },
                { 29, 14, 18, 36, 24, 17, 19, 2, 21, 29, 13, 37, 38, 3, 35, 13, 20, 16, 38, 36, 15, 5, 30, 13, 42 },
                { 33, 9, 38, 21, 15, 26, 9, 39, 11, 20, 18, 30, 34, 36, 28, 17, 16, 18, 18, 19, 27, 25, 2, 38, 42 }
            };

            MatrixDouble dM = new MatrixDouble(_m);

            dM.GaussElim();
        }
Beispiel #6
0
        public void MatrixDouble_Constructor5_Exceptions()
        {
            // ReSharper disable once NotAccessedVariable
            MatrixDouble m;

            Assert.Throws <ArgumentNullException>(() => m = new MatrixDouble((IMatrix)null));
        }
Beispiel #7
0
        public void MatrixDouble_Constructor1_Exceptions()
        {
            // ReSharper disable once NotAccessedVariable
            MatrixDouble m;

            Assert.Throws <ArgumentException>(() => m = new MatrixDouble(0, 2));
            Assert.Throws <ArgumentException>(() => m = new MatrixDouble(2, 0));
        }
Beispiel #8
0
        public void MatrixDouble_Constructor3()
        {
            MatrixDouble m = CreateRandomMatrix(3, 3);

            AssertComplement(m, 0, 0);
            AssertComplement(m, 1, 2);
            AssertComplement(m, 2, 1);
        }
Beispiel #9
0
        public void MatrixDouble_Transpose()
        {
            MatrixDouble m = CreateRandomMatrix(2, 3);
            MatrixDouble t = m.Transpose();

            Assert.AreEqual(m.Width, t.Height);
            Assert.AreEqual(m.Height, t.Width);
        }
Beispiel #10
0
        public void MatrixDouble_Clone()
        {
            MatrixDouble m = CreateRandomMatrix(2, 2);
            MatrixDouble c = null;

            Assert.DoesNotThrow(() => c = m.Clone());
            Assert.AreNotSame(m, c);
            Assert.AreEqual(m.GetType(), c.GetType(), "Clone() mast return the same matrix type");
        }
Beispiel #11
0
        public void MatrixDouble_EqualsObject()
        {
            MatrixDouble m = CreateRandomMatrix(3, 3);

            Assert.IsTrue(m.Equals((object)m));
            Assert.IsFalse(m.Equals((object)null));
            // ReSharper disable once SuspiciousTypeConversion.Global
            Assert.IsFalse(m.Equals(1.0f));
        }
Beispiel #12
0
        public void Matrix_SetIdentity()
        {
            MatrixDouble m = CreateRandomMatrix(3, 3);

            Assert.IsFalse(m.IsIdentity());

            m.SetIdentity();
            Assert.IsTrue(m.IsIdentity());
        }
Beispiel #13
0
    public void SizeConstructor()
    {
        const int sizeRows = 10, sizeColumns = 5;

        var matrix = new MatrixDouble(sizeRows, sizeColumns);

        Assert.AreEqual(sizeRows, matrix.Rows);
        Assert.AreEqual(sizeColumns, matrix.Columns);
    }
Beispiel #14
0
        public void MatrixDouble_OperatorAdd_Exceptions()
        {
            // ReSharper disable once NotAccessedVariable
            MatrixDouble m = CreateRandomMatrix(2, 2), r;

            Assert.Throws <ArgumentNullException>(() => r = m + null);
            Assert.Throws <ArgumentNullException>(() => r = null + m);
            Assert.Throws <ArgumentException>(() => r     = m + new MatrixDouble(1, 2));
            Assert.Throws <ArgumentException>(() => r     = m + new MatrixDouble(2, 1));
        }
Beispiel #15
0
        public void MatrixDouble_Constructor3_Exceptions()
        {
            // ReSharper disable once NotAccessedVariable
            MatrixDouble m;

            Assert.Throws <ArgumentNullException>(() => m       = new MatrixDouble(null, 0, 0));
            Assert.Throws <ArgumentException>(() => m           = new MatrixDouble(new MatrixDouble(1, 1), 0, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => m = new MatrixDouble(new MatrixDouble(2, 2), 2, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => m = new MatrixDouble(new MatrixDouble(2, 2), 0, 2));
        }
Beispiel #16
0
        public void MatrixDouble_Accessor_Exceptions()
        {
            MatrixDouble m = CreateRandomMatrix(2, 2);
            // ReSharper disable once NotAccessedVariable
            double c;

            Assert.Throws <ArgumentException>(() => c       = m[2, 0]);
            Assert.Throws <ArgumentException>(() => c       = m[0, 2]);
            Assert.Throws <ArgumentException>(() => m[2, 0] = double.NaN);
            Assert.Throws <ArgumentException>(() => m[0, 2] = double.NaN);
        }
Beispiel #17
0
        public void MatrixDouble_GetHashCode()
        {
            MatrixDouble m = CreateRandomMatrix(3, 3);

            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Assert.DoesNotThrow(() => m.GetHashCode());

            MatrixDouble c = m.Clone();

            Assert.AreNotEqual(m.GetHashCode(), c.GetHashCode());
        }
Beispiel #18
0
        public void MatrixDouble_Constructor2_Exceptions()
        {
            // ReSharper disable once NotAccessedVariable
            MatrixDouble m;

            Assert.Throws <ArgumentException>(() => m     = new MatrixDouble(0, 2, null));
            Assert.Throws <ArgumentException>(() => m     = new MatrixDouble(2, 0, null));
            Assert.Throws <ArgumentNullException>(() => m = new MatrixDouble(2, 2, null));
            Assert.Throws <ArgumentException>(() => m     = new MatrixDouble(2, 2, 1.0f, 2.0f, 3.0f));
            Assert.DoesNotThrow(() => m = new MatrixDouble(2, 2, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f));
        }
Beispiel #19
0
        public CartesianPoint GetCartesianFromPoint(Point point)
        {
            double zoomFactor = 1 / ViewPortProjection.GetZoomFactor(ZoomLevel);

            double x = (point.X - RenderSize.Width / 2d) * zoomFactor + ViewPortCenter.X;
            double y = (point.Y - RenderSize.Height / 2d) * zoomFactor + ViewPortCenter.Y;

            MatrixDouble reverseRotationMatrix = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(Heading), ViewPortCenter.ToPoint());

            return(new CartesianPoint(reverseRotationMatrix.Transform(new Point(x, y))));
        }
Beispiel #20
0
        public void MatrixDouble_ToArray(uint w, uint h)
        {
            MatrixDouble m = CreateRandomMatrix(w, h);

            double[] mArray = m.ToArray();

            Assert.IsNotNull(mArray);
            Assert.AreEqual(w * h, (uint)mArray.Length);
            Assert.AreNotSame(m.ToArray(), mArray);
            CollectionAssert.AreEqual(m.Buffer, mArray);
        }
Beispiel #21
0
        public void Matrix_GetInverseMatrix(uint size)
        {
            MatrixDouble m = CreateRandomMatrix(size, size);
            MatrixDouble i = m.GetInverseMatrix();

            Assert.AreEqual(m.Width, i.Width);
            Assert.AreEqual(m.Height, i.Height);

            MatrixDouble r = m * i;

            Assert.IsTrue(r.IsIdentity(1e-4));
        }
Beispiel #22
0
        private void OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            _headingBeforeManipulation        = _map.Heading;
            _zoomFactorBeforeManipulation     = _map.ViewPortProjection.GetZoomFactor(_map.ZoomLevel);
            _viewPortCenterBeforeManipulation = _map.ViewPortCenter.ToPoint();

            _reverseRotationMatrix = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(_headingBeforeManipulation), _viewPortCenterBeforeManipulation);

            _manipulationStartPoint = _map.GetCartesianFromPoint(e.Position).ToPoint();

            e.Handled = true;
        }
Beispiel #23
0
        protected virtual void UpdateZoomOnlyManipulation(double zoomDelta, Point position)
        {
            Point zoomCenter = _map.GetCartesianFromPoint(position).ToPoint();

            double oldZoomLevel = _map.ZoomLevel;
            double newZoomLevel = oldZoomLevel + zoomDelta;
            double scaleFactor  = 1 / (_map.ViewPortProjection.GetZoomFactor(newZoomLevel) / _map.ViewPortProjection.GetZoomFactor(oldZoomLevel));

            MatrixDouble scale = MatrixDouble.CreateScale(scaleFactor, zoomCenter);

            _map.ViewPortCenter = new CartesianPoint(scale.Transform(_map.ViewPortCenter.ToPoint()));
            _map.ZoomLevel      = newZoomLevel;
        }
Beispiel #24
0
        public virtual void MatrixDouble_Set_Exceptions()
        {
            MatrixDouble m = CreateRandomMatrix(2, 3);

            Assert.Throws <ArgumentNullException>(() => m.Set(null));
            Assert.Throws <ArgumentNullException>(() => m.Set((IMatrix)null));

            Assert.Throws <ArgumentException>(() => m.Set(new MatrixDouble(3, 3)));
            Assert.Throws <ArgumentException>(() => m.Set((IMatrix) new MatrixDouble(3, 3)));

            Assert.Throws <ArgumentException>(() => m.Set(new MatrixDouble(2, 2)));
            Assert.Throws <ArgumentException>(() => m.Set((IMatrix) new MatrixDouble(2, 2)));
        }
Beispiel #25
0
        protected virtual void UpdateManipulation(ManipulationDelta delta)
        {
            double newHeading  = _headingBeforeManipulation;
            double newZoomFact = _zoomFactorBeforeManipulation * delta.Scale;

            MatrixDouble m = MatrixDouble.Identity;

            if (TranslationEnabled)
            {
                m = MatrixDouble.CreateTranslation(-(delta.Translation.X / _zoomFactorBeforeManipulation), -(delta.Translation.Y / _zoomFactorBeforeManipulation));
                m = m * _reverseRotationMatrix;
            }

            if (ZoomEnabled)
            {
                double scaleFactor = _zoomFactorBeforeManipulation / newZoomFact;
                m = m * MatrixDouble.CreateScale(scaleFactor, _manipulationStartPoint);
            }

            if ((delta.Rotation != 0.0) && RotationEnabled)
            {
                //Add the Rotation from the Manipulation
                MatrixDouble rotation = MatrixDouble.CreateRotation(-TransformHelper.DegToRad(delta.Rotation), _manipulationStartPoint);
                m = m * rotation;

                newHeading = (_headingBeforeManipulation + delta.Rotation) % 360;
                if (newHeading < 0)
                {
                    newHeading += 360;
                }
            }

            double         zoomLevel      = _map.ViewPortProjection.GetZoomLevel(newZoomFact);
            CartesianPoint viewPortCenter = new CartesianPoint(m.Transform(_viewPortCenterBeforeManipulation));

            if (Update != null)
            {
                TouchMapEventArgs eventArgs = new TouchMapEventArgs();
                eventArgs.Heading        = newHeading;
                eventArgs.ZoomLevel      = zoomLevel;
                eventArgs.ViewPortCenter = viewPortCenter;
                OnUpdate(eventArgs);
            }
            if (AutoUpdateMap)
            {
                _map.Heading        = newHeading;
                _map.ZoomLevel      = zoomLevel;
                _map.ViewPortCenter = viewPortCenter;
            }
        }
Beispiel #26
0
        public void MatrixDouble_GetRow()
        {
            MatrixDouble m = CreateRandomMatrix(2, 2);

            double[] c;

            c = m.GetRow(0);
            Assert.IsNotNull(c);
            Assert.AreEqual(2, c.Length);

            c = m.GetRow(1);
            Assert.IsNotNull(c);
            Assert.AreEqual(2, c.Length);
        }
Beispiel #27
0
        public virtual void MatrixDouble_SetVoid()
        {
            MatrixDouble m = CreateRandomMatrix(2, 3);

            m.SetVoid();

            for (uint c = 0; c < 2; c++)
            {
                for (uint r = 0; r < 2; r++)
                {
                    Assert.AreEqual(0.0f, m[c, r]);
                }
            }
        }
Beispiel #28
0
        public void MatrixDouble_OperatorAdd()
        {
            MatrixDouble m = new MatrixDouble(2, 2, +1.0, -0.5, +2.0, -1.5);
            MatrixDouble n = new MatrixDouble(2, 2, -1.0, +0.5, -2.0, +1.5);
            MatrixDouble o = m + n;

            for (uint c = 0; c < m.Width; c++)
            {
                for (uint r = 0; r < m.Height; r++)
                {
                    Assert.AreEqual(0.0f, o[c, r]);
                }
            }
        }
Beispiel #29
0
        public void MatrixDouble_Constructor4(uint w, uint h)
        {
            MatrixDouble m  = CreateRandomMatrix(w, h);
            MatrixDouble cm = new MatrixDouble(m);

            Assert.AreEqual(m.Width, cm.Width);
            Assert.AreEqual(m.Height, cm.Height);
            for (uint c = 0; c < w; c++)
            {
                for (uint r = 0; r < h; r++)
                {
                    Assert.AreEqual(m[c, r], cm[c, r]);
                }
            }
        }
Beispiel #30
0
        public void MatrixDouble_Constructor1(uint w, uint h)
        {
            MatrixDouble m = new MatrixDouble(w, h);

            Assert.AreEqual(w, m.Width);
            Assert.AreEqual(h, m.Height);

            for (uint c = 0; c < w; c++)
            {
                for (uint r = 0; r < h; r++)
                {
                    Assert.AreEqual(0.0, m[c, r]);
                }
            }
        }
		/// <summary>
		/// Set uniform state variable (mat3 variable).
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="GraphicsContext"/> used for operations.
		/// </param>
		/// <param name="uniformName">
		/// A <see cref="String"/> that specify the variable name in the shader source.
		/// </param>
		/// <param name="m">
		/// A <see cref="MatrixDouble"/> holding the uniform variabile data.
		/// </param>
		public void SetUniform(GraphicsContext ctx, string uniformName, MatrixDouble m)
		{
			if (ctx == null)
				throw new ArgumentNullException("ctx");
			if (m == null)
				throw new ArgumentNullException("m");

			UniformBinding uniform = GetUniform(uniformName);

			CheckProgramBinding();

			switch (uniform.UniformType) {
				case ShaderUniformType.Mat2x2:
					if ((m.Width != 2) || (m.Height != 2))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix2(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat2x3:
					if ((m.Width != 2) || (m.Height != 3))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix2x3(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat2x4:
					if ((m.Width != 2) || (m.Height != 4))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix2x4(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat3x2:
					if ((m.Width != 3) || (m.Height != 2))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix3x2(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat3x3:
					if ((m.Width != 3) || (m.Height != 3))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix3(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat3x4:
					if ((m.Width != 3) || (m.Height != 4))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix3x4(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat4x2:
					if ((m.Width != 4) || (m.Height != 2))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix4x2(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat4x3:
					if ((m.Width != 4) || (m.Height != 3))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix4x3(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				case ShaderUniformType.Mat4x4:
					if ((m.Width != 4) || (m.Height != 4))
						throw new ArgumentException("matrix size mismatch");
					Gl.UniformMatrix4(uniform.Location, 1, false, m.MatrixBuffer);
					break;
				default:
					throw new NotSupportedException(String.Format("uniform type {0} not assignable from Matrix{1}x{2}", uniform.UniformType, m.Width, m.Height));
			}
		}