using System; using System.Drawing; namespace HeuristicLab.Problems.RoutePlanning.Utilities { public class RectangleD { private const int Digits = 4; private double x; private double y; private double width; private double height; #region Properties public double X { get { return Math.Round(x, Digits); } set { x = value; } } public double Y { get { return Math.Round(y, Digits); } set { y = value; } } public double Width { get { return Math.Round(width, Digits); } set { width = value; } } public double Height { get { return Math.Round(height, Digits); } set { height = value; } } public PointD TopLeft { get { return new PointD(X, Y); } } public PointD BottomRight { get { return new PointD(X + Width, Y + Height); } } public PointD Center { get { return new PointD(X + Width / 2d, Y + Height / 2d); } } public double MaxSide { get { return Math.Max(width, height); } } public double MinSide { get { return Math.Min(width, height); } } #endregion #region Constructors public RectangleD(double x, double y, double w, double h) { this.x = x; this.y = y; this.width = w; this.height = h; } public RectangleD(RectangleD r) { x = r.X; y = r.Y; width = r.Width; height = r.Height; } #endregion #region Operators public static explicit operator RectangleF(RectangleD r) { return new RectangleF((float)r.X, (float)r.Y, (float)r.Width, (float)r.Height); } #endregion #region Overridden Methods public override bool Equals(object obj) { if (obj is RectangleD) { RectangleD r = (RectangleD)obj; return (X == r.X && Y == r.Y && Width == r.Width && Height == r.Height); } return false; } public override int GetHashCode() { return ((RectangleF)this).GetHashCode(); } #endregion } }