1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 |
|
---|
25 | namespace HeuristicLab.Visualization {
|
---|
26 | public struct PointD {
|
---|
27 | public static readonly PointD Empty;
|
---|
28 |
|
---|
29 | private double myX;
|
---|
30 | public double X {
|
---|
31 | get { return myX; }
|
---|
32 | set { myX = value; }
|
---|
33 | }
|
---|
34 | private double myY;
|
---|
35 | public double Y {
|
---|
36 | get { return myY; }
|
---|
37 | set { myY = value; }
|
---|
38 | }
|
---|
39 | public bool IsEmpty {
|
---|
40 | get { return this == Empty; }
|
---|
41 | }
|
---|
42 |
|
---|
43 | public PointD(double x, double y) {
|
---|
44 | myX = x;
|
---|
45 | myY = y;
|
---|
46 | }
|
---|
47 | public PointD(SizeD size) {
|
---|
48 | myX = size.Width;
|
---|
49 | myY = size.Height;
|
---|
50 | }
|
---|
51 | public PointD(Offset offset) {
|
---|
52 | myX = offset.DX;
|
---|
53 | myY = offset.DY;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public override bool Equals(object obj) {
|
---|
57 | if (obj is PointD) {
|
---|
58 | return ((PointD)obj) == this;
|
---|
59 | } else {
|
---|
60 | return base.Equals(obj);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | public override int GetHashCode() {
|
---|
64 | return (int)Math.Pow(X, Y);
|
---|
65 | }
|
---|
66 | public override string ToString() {
|
---|
67 | return "(" + X.ToString() + ";" + Y.ToString() + ")";
|
---|
68 | }
|
---|
69 |
|
---|
70 | public static PointD operator +(PointD point, Offset offset) {
|
---|
71 | return new PointD(point.X + offset.DX, point.Y + offset.DY);
|
---|
72 | }
|
---|
73 | public static PointD operator -(PointD point, Offset offset) {
|
---|
74 | return new PointD(point.X - offset.DX, point.Y - offset.DY);
|
---|
75 | }
|
---|
76 | public static Offset operator +(PointD point1, PointD point2) {
|
---|
77 | return new Offset(point1.X + point2.X, point1.Y + point2.Y);
|
---|
78 | }
|
---|
79 | public static Offset operator -(PointD point1, PointD point2) {
|
---|
80 | return new Offset(point1.X - point2.X, point1.Y - point2.Y);
|
---|
81 | }
|
---|
82 | public static bool operator ==(PointD point1, PointD point2) {
|
---|
83 | return (point1.X == point2.X) && (point1.Y == point2.Y);
|
---|
84 | }
|
---|
85 | public static bool operator !=(PointD point1, PointD point2) {
|
---|
86 | return !(point1 == point2);
|
---|
87 | }
|
---|
88 | public static explicit operator Point(PointD point) {
|
---|
89 | return new Point((int)Math.Round(point.X), (int)Math.Round(point.Y));
|
---|
90 | }
|
---|
91 | public static explicit operator PointF(PointD point) {
|
---|
92 | float fx = (float)point.X;
|
---|
93 | float fy = (float)point.Y;
|
---|
94 | return new PointF(float.IsPositiveInfinity(fx) ? float.MaxValue : fx, float.IsNegativeInfinity(fy) ? float.MinValue : fy);
|
---|
95 | }
|
---|
96 | public static explicit operator SizeD(PointD point) {
|
---|
97 | return new SizeD(point.X, point.Y);
|
---|
98 | }
|
---|
99 | public static explicit operator Offset(PointD point) {
|
---|
100 | return new Offset(point.X, point.Y);
|
---|
101 | }
|
---|
102 | public static implicit operator PointD(Point point) {
|
---|
103 | return new PointD(point.X, point.Y);
|
---|
104 | }
|
---|
105 | public static implicit operator PointD(PointF point) {
|
---|
106 | return new PointD(point.X, point.Y);
|
---|
107 | }
|
---|
108 |
|
---|
109 | public static PointD Add(PointD point, Offset offset) {
|
---|
110 | return new PointD(point.X + offset.DX, point.Y + offset.DY);
|
---|
111 | }
|
---|
112 | public static PointD Subtract(PointD point, Offset offset) {
|
---|
113 | return new PointD(point.X - offset.DX, point.Y - offset.DY);
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|