/// <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); }
/// <summary> /// Create a cube of type T. /// </summary> /// <param name="Voxel">A Voxel of type T in the upper left front corner of the cube.</param> /// <param name="Width">The width of the cube.</param> /// <param name="Height">The height of the cube.</param> /// <param name="Depth">The depth of the cube.</param> public Cube(Voxel <T> Voxel, T Width, T Height, T Depth) { #region Initial Checks if (Voxel == null) { throw new ArgumentNullException("The given voxel must not be null!"); } if (Width == null) { throw new ArgumentNullException("The given width must not be null!"); } if (Height == null) { throw new ArgumentNullException("The given height must not be null!"); } if (Depth == null) { throw new ArgumentNullException("The given depth 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 = Voxel.X; this.Top = Voxel.Y; this.Front = Voxel.Z; this.Right = Math.Add(Voxel.X, Width); this.Bottom = Math.Add(Voxel.Y, Height); this.Behind = Math.Add(Voxel.Z, Depth); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// A method to calculate the distance between this /// vector 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 vector 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)))); }
/// <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); }
/// <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); }