Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.0/sources/HeuristicLab.Charting/Structs/PointD.cs @ 13365

Last change on this file since 13365 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Drawing;
26
27namespace HeuristicLab.Charting {
28  public struct PointD {
29    public static readonly PointD Empty;
30
31    private double myX;
32    public double X {
33      get { return myX; }
34      set { myX = value; }
35    }
36    private double myY;
37    public double Y {
38      get { return myY; }
39      set { myY = value; }
40    }
41    public bool IsEmpty {
42      get { return this == Empty; }
43    }
44
45    public PointD(double x, double y) {
46      myX = x;
47      myY = y;
48    }
49    public PointD(SizeD size) {
50      myX = size.Width;
51      myY = size.Height;
52    }
53    public PointD(Offset offset) {
54      myX = offset.DX;
55      myY = offset.DY;
56    }
57
58    public override bool Equals(object obj) {
59      if (obj is PointD) {
60        return ((PointD)obj) == this;
61      } else {
62        return base.Equals(obj);
63      }
64    }
65    public override int GetHashCode() {
66      return (int)Math.Pow(X, Y);
67    }
68    public override string ToString() {
69      return "(" + X.ToString() + ";" + Y.ToString() + ")";
70    }
71
72    public static PointD operator +(PointD point, Offset offset) {
73      return new PointD(point.X + offset.DX, point.Y + offset.DY);
74    }
75    public static PointD operator -(PointD point, Offset offset) {
76      return new PointD(point.X - offset.DX, point.Y - offset.DY);
77    }
78    public static Offset operator +(PointD point1, PointD point2) {
79      return new Offset(point1.X + point2.X, point1.Y + point2.Y);
80    }
81    public static Offset operator -(PointD point1, PointD point2) {
82      return new Offset(point1.X - point2.X, point1.Y - point2.Y);
83    }
84    public static bool operator ==(PointD point1, PointD point2) {
85      return (point1.X == point2.X) && (point1.Y == point2.Y);
86    }
87    public static bool operator !=(PointD point1, PointD point2) {
88      return (point1.X != point2.X) && (point1.Y != point2.Y);
89    }
90    public static explicit operator SizeD(PointD point) {
91      return new SizeD(point.X, point.Y);
92    }
93    public static explicit operator Offset(PointD point) {
94      return new Offset(point.X, point.Y);
95    }
96    public static implicit operator PointD(Point point) {
97      return new PointD(point.X, point.Y);
98    }
99    public static implicit operator PointD(PointF point) {
100      return new PointD(point.X, point.Y);
101    }
102
103    public static PointD Add(PointD point, Offset offset) {
104      return new PointD(point.X + offset.DX, point.Y + offset.DY);
105    }
106    public static PointD Subtract(PointD point, Offset offset) {
107      return new PointD(point.X - offset.DX, point.Y - offset.DY);
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.