[8516] | 1 | using System;
|
---|
| 2 | using System.Drawing;
|
---|
| 3 |
|
---|
| 4 | namespace HeuristicLab.Problems.RoutePlanning.Utilities {
|
---|
| 5 | public class RectangleD {
|
---|
| 6 | private const int Digits = 4;
|
---|
| 7 | private double x;
|
---|
| 8 | private double y;
|
---|
| 9 | private double width;
|
---|
| 10 | private double height;
|
---|
| 11 |
|
---|
| 12 | #region Properties
|
---|
| 13 |
|
---|
| 14 | public double X {
|
---|
| 15 | get { return Math.Round(x, Digits); }
|
---|
| 16 | set { x = value; }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | public double Y {
|
---|
| 20 | get { return Math.Round(y, Digits); }
|
---|
| 21 | set { y = value; }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public double Width {
|
---|
| 25 | get { return Math.Round(width, Digits); }
|
---|
| 26 | set { width = value; }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public double Height {
|
---|
| 30 | get { return Math.Round(height, Digits); }
|
---|
| 31 | set { height = value; }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public PointD TopLeft {
|
---|
| 35 | get { return new PointD(X, Y); }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public PointD BottomRight {
|
---|
| 39 | get { return new PointD(X + Width, Y + Height); }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public PointD Center {
|
---|
| 43 | get { return new PointD(X + Width / 2d, Y + Height / 2d); }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public double MaxSide {
|
---|
| 47 | get { return Math.Max(width, height); }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public double MinSide {
|
---|
| 51 | get { return Math.Min(width, height); }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | #endregion
|
---|
| 55 |
|
---|
| 56 | #region Constructors
|
---|
| 57 |
|
---|
| 58 | public RectangleD(double x, double y, double w, double h) {
|
---|
| 59 | this.x = x;
|
---|
| 60 | this.y = y;
|
---|
| 61 | this.width = w;
|
---|
| 62 | this.height = h;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public RectangleD(RectangleD r) {
|
---|
| 66 | x = r.X;
|
---|
| 67 | y = r.Y;
|
---|
| 68 | width = r.Width;
|
---|
| 69 | height = r.Height;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 | #region Operators
|
---|
| 75 |
|
---|
| 76 | public static explicit operator RectangleF(RectangleD r) {
|
---|
| 77 | return new RectangleF((float)r.X, (float)r.Y, (float)r.Width, (float)r.Height);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | #endregion
|
---|
| 81 |
|
---|
| 82 | #region Overridden Methods
|
---|
| 83 |
|
---|
| 84 | public override bool Equals(object obj) {
|
---|
| 85 | if (obj is RectangleD) {
|
---|
| 86 | RectangleD r = (RectangleD)obj;
|
---|
| 87 | return (X == r.X && Y == r.Y && Width == r.Width && Height == r.Height);
|
---|
| 88 | }
|
---|
| 89 | return false;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | public override int GetHashCode() {
|
---|
| 93 | return ((RectangleF)this).GetHashCode();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | #endregion
|
---|
| 97 | }
|
---|
| 98 | }
|
---|