Exemple #1
0
        /// <summary>
        /// Create a 2-dimensional line of type T.
        /// </summary>
        /// <param name="Pixel">A pixel of type T.</param>
        /// <param name="X">The x-component.</param>
        /// <param name="Y">The y-component.</param>
        public Line2D(IPixel <T> Pixel, T X, T Y)
        {
            #region Initial Checks

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

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

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

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.X1 = Pixel.X;
            this.Y1 = Pixel.Y;
            this.X2 = Math.Add(Pixel.X, X);
            this.Y2 = Math.Add(Pixel.Y, Y);

            this.Pixel1 = new Pixel <T>(X1, Y1);
            this.Pixel2 = new Pixel <T>(X2, Y2);

            this.Length = Pixel1.DistanceTo(Pixel2);
        }
Exemple #2
0
        /// <summary>
        /// Create a rectangle of type T.
        /// </summary>
        /// <param name="Pixel">A pixel of type T in the upper left corner of the rectangle.</param>
        /// <param name="Width">The width of the rectangle.</param>
        /// <param name="Height">The height of the rectangle.</param>
        public Rectangle(IPixel <T> Pixel, T Width, T Height)
        {
            #region Initial Checks

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

            if (Width == null || Width.Equals(Math.Zero))
            {
                throw new ArgumentNullException("The given width must not be null or zero!");
            }

            if (Height == null || Height.Equals(Math.Zero))
            {
                throw new ArgumentNullException("The given height must not be null or zero!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.Left   = Pixel.X;
            this.Top    = Pixel.Y;
            this.Right  = Math.Add(Pixel.X, Width);
            this.Bottom = Math.Add(Pixel.Y, Height);

            this.Pixel1 = new Pixel <T>(Left, Top);
            this.Pixel2 = new Pixel <T>(Right, Bottom);

            this.Width    = Math.Distance(Left, Right);
            this.Height   = Math.Distance(Top, Bottom);
            this.Diameter = Pixel1.DistanceTo(Pixel2);
        }
Exemple #3
0
        /// <summary>
        /// Create a rectangle of type T.
        /// </summary>
        /// <param name="Left">The left-coordinate of the rectangle.</param>
        /// <param name="Top">The top-coordinate of the rectangle.</param>
        /// <param name="Right">The right-coordinate of the rectangle.</param>
        /// <param name="Bottom">The bottom-coordinate of the rectangle.</param>
        public Rectangle(T Left, T Top, T Right, T Bottom)
        {
            #region Initial Checks

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

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

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

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

            if (Left.Equals(Right))
            {
                throw new ArgumentException("The width of the rectangle must not be zero!");
            }

            if (Top.Equals(Bottom))
            {
                throw new ArgumentException("The height of the rectangle must not be zero!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.Left   = Math.Min(Left, Right);
            this.Top    = Math.Min(Top, Bottom);
            this.Right  = Math.Max(Left, Right);
            this.Bottom = Math.Max(Top, Bottom);

            this.Pixel1 = new Pixel <T>(Left, Top);
            this.Pixel2 = new Pixel <T>(Right, Bottom);

            this.Width    = Math.Distance(Left, Right);
            this.Height   = Math.Distance(Top, Bottom);
            this.Diameter = Pixel1.DistanceTo(Pixel2);
        }
Exemple #4
0
        /// <summary>
        /// Create a 2-dimensional line of type T.
        /// </summary>
        /// <param name="X1">The first x-coordinate of the line.</param>
        /// <param name="Y1">The first y-coordinate of the line.</param>
        /// <param name="X2">The second x-coordinate of the line.</param>
        /// <param name="Y2">The second y-coordinate of the line.</param>
        public Line2D(T X1, T Y1, T X2, T Y2)
        {
            #region Initial Checks

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

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

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

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

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.X1 = X1;
            this.Y1 = Y1;
            this.X2 = X2;
            this.Y2 = Y2;

            this.Pixel1 = new Pixel <T>(X1, Y1);
            this.Pixel2 = new Pixel <T>(X2, Y2);

            this.Length = Pixel1.DistanceTo(Pixel2);
        }