Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a 1-dimensional line of type T.
        /// </summary>
        /// <param name="Left">The left-coordinate of the line.</param>
        /// <param name="Right">The right-coordinate of the line.</param>
        public Line1D(T Left, T Right)
        {
            #region Initial Checks

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

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

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Math.Distance(Left, Right).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting size must not be zero!");
            }

            #endregion

            this.Left  = Math.Min(Left, Right);
            this.Right = Math.Max(Left, Right);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a cube of type T.
        /// </summary>
        /// <param name="Voxel1">A Voxel of type T.</param>
        /// <param name="Voxel2">A Voxel of type T.</param>
        public Cube(Voxel <T> Voxel1, Voxel <T> Voxel2)
        {
            #region Initial Checks

            if (Voxel1 == null)
            {
                throw new ArgumentNullException("The given first voxel must not be null!");
            }

            if (Voxel2 == null)
            {
                throw new ArgumentNullException("The given second voxel must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Math.Distance(Left, Right).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting width must not be zero!");
            }

            if (Math.Distance(Top, Bottom).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting height must not be zero!");
            }

            if (Math.Distance(Front, Behind).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting depth must not be zero!");
            }

            #endregion

            this.Left   = Math.Min(Voxel1.X, Voxel2.X);
            this.Top    = Math.Min(Voxel1.Y, Voxel2.Y);
            this.Front  = Math.Min(Voxel1.Z, Voxel2.Z);
            this.Right  = Math.Max(Voxel1.X, Voxel2.X);
            this.Bottom = Math.Max(Voxel1.Y, Voxel2.Y);
            this.Behind = Math.Max(Voxel1.Z, Voxel2.Z);
        }
Esempio n. 4
0
        /// <summary>
        /// Create a rectangle of type T.
        /// </summary>
        /// <param name="Pixel1">The left/top pixel of the rectangle.</param>
        /// <param name="Pixel2">The right/bottom pixel of the rectangle.</param>
        public Rectangle(IPixel <T> Pixel1, IPixel <T> Pixel2)
        {
            #region Initial Checks

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

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

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

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

            #endregion

            this.Math = MathsFactory <T> .Instance;

            this.Left   = Math.Min(Pixel1.X, Pixel2.X);
            this.Top    = Math.Min(Pixel1.Y, Pixel2.Y);
            this.Right  = Math.Max(Pixel1.X, Pixel2.X);
            this.Bottom = Math.Max(Pixel1.Y, Pixel2.Y);

            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);
        }
Esempio n. 5
0
        /// <summary>
        /// A method to get the minimum of an array of Doubles.
        /// </summary>
        /// <param name="Values">An array of Doubles.</param>
        /// <returns>The minimum of all values: Min(a, b, ...)</returns>
        public IVector2D <T> Min(params IVector2D <T>[] Values)
        {
            if (Values == null || Values.Length == 0)
            {
                throw new ArgumentException("The given values must not be null or zero!");
            }

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

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

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

            return(new Vector2D <T>(Math.Zero, Math.Zero, _X, _Y));
        }
Esempio n. 6
0
        /// <summary>
        /// Create a cube of type T.
        /// </summary>
        /// <param name="Left">The left parameter.</param>
        /// <param name="Top">The top parameter.</param>
        /// <param name="Front">The front parameter.</param>
        /// <param name="Right">The right parameter.</param>
        /// <param name="Bottom">The bottom parameter.</param>
        /// <param name="Behind">The behind parameter.</param>
        public Cube(T Left, T Top, T Front, T Right, T Bottom, T Behind)
        {
            #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 (Front == null)
            {
                throw new ArgumentNullException("The given front 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 (Behind == null)
            {
                throw new ArgumentNullException("The given behind coordinate must not be null!");
            }

            #endregion

            this.Math = MathsFactory <T> .Instance;

            #region Math Checks

            if (Math.Distance(Left, Right).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting width must not be zero!");
            }

            if (Math.Distance(Top, Bottom).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting height must not be zero!");
            }

            if (Math.Distance(Front, Behind).Equals(Math.Zero))
            {
                throw new ArgumentException("The resulting depth must not be zero!");
            }

            #endregion

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