Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/PointD.cs @ 846

Last change on this file since 846 was 635, checked in by mstoeger, 16 years ago

Imported charting framework sources into HeuristicLab.Visualization (#294)

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