Exemplo n.º 1
0
        /// <summary>
        /// A method to calculate the distance between this
        /// pixel and the given coordinates of type T.
        /// </summary>
        /// <param name="x">A x-coordinate of type T</param>
        /// <param name="y">A y-coordinate of type T</param>
        /// <returns>The distance between this pixel and the given coordinates.</returns>
        public T DistanceTo(T x, T y)
        {
            #region Initial Checks

            if (x == null)
            {
                throw new ArgumentNullException("The given x-coordinate must not be null!");
            }

            if (y == null)
            {
                throw new ArgumentNullException("The given y-coordinate must not be null!");
            }

            #endregion

            var dX = Math.Distance(X, x);
            var dY = Math.Distance(Y, y);

            return(Math.Sqrt(Math.Add(Math.Mul(dX, dX), Math.Mul(dY, dY))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if the given pixel is located on this line.
        /// </summary>
        /// <param name="Pixel">A pixel of type T.</param>
        /// <returns>True if the pixel is located on this line; False otherwise.</returns>
        public Boolean Contains(IPixel <T> Pixel)
        {
            #region Initial Checks

            if (Pixel == null)
            {
                throw new ArgumentNullException("The given pixel must not be null!");
            }

            #endregion

            #region Check line bounds

            if (Pixel.X.IsLessThan(X1) && Pixel.X.IsLessThan(X2))
            {
                return(false);
            }

            if (Pixel.X.IsLargerThan(X1) && Pixel.X.IsLargerThan(X2))
            {
                return(false);
            }

            if (Pixel.Y.IsLessThan(Y1) && Pixel.Y.IsLessThan(Y2))
            {
                return(false);
            }

            if (Pixel.Y.IsLargerThan(Y1) && Pixel.Y.IsLargerThan(Y2))
            {
                return(false);
            }

            #endregion

            // Check equation: Pixel.Y = m*Pixel.X + t
            return(Pixel.Y.Equals(Math.Add(Math.Mul(Gradient, Pixel.X), YIntercept)));
        }
Exemplo n.º 3
0
        /// <summary>
        /// A method to multiply vectors.
        /// </summary>
        /// <param name="Multiplicators">An array of vectors.</param>
        /// <returns>The multiplication of all multiplicators: v1 * v2 * ...</returns>
        public IVector2D <T> Mul(params IVector2D <T>[] Multiplicators)
        {
            if (Multiplicators == null || Multiplicators.Length == 0)
            {
                throw new ArgumentException("The given multiplicators must not be null!");
            }

            if (Multiplicators.Length == 1)
            {
                return(Multiplicators[0]);
            }

            var _X = Multiplicators[0].X;
            var _Y = Multiplicators[0].Y;

            for (var i = Multiplicators.Length - 1; i >= 1; i--)
            {
                _X = Math.Mul(_X, Multiplicators[i].X);
                _Y = Math.Mul(_Y, Multiplicators[i].Y);
            }

            return(new Vector2D <T>(Math.Zero, Math.Zero, _X, _Y));
        }