Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CEDMA-Exporter-715/sources/HeuristicLab.Visualization/3.2/Offset.cs @ 2716

Last change on this file since 2716 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 3.1 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;
25
26namespace HeuristicLab.Visualization {
27  public struct Offset {
28    public static readonly Offset Empty = new Offset();
29
30    private double myDX;
31
32    public double DX {
33      get { return myDX; }
34      set { myDX = value; }
35    }
36
37    private double myDY;
38
39    public double DY {
40      get { return myDY; }
41      set { myDY = value; }
42    }
43
44    public bool IsEmpty {
45      get { return this == Empty; }
46    }
47
48    public double Length {
49      get { return Math.Sqrt(DX*DX + DY*DY); }
50    }
51
52    public Offset(double dx, double dy) {
53      myDX = dx;
54      myDY = dy;
55    }
56
57    public Offset(PointD point) {
58      myDX = point.X;
59      myDY = point.Y;
60    }
61
62    public Offset(SizeD size) {
63      myDX = size.Width;
64      myDY = size.Height;
65    }
66
67    public override bool Equals(object obj) {
68      if (obj is Offset) {
69        return ((Offset)obj) == this;
70      } else {
71        return base.Equals(obj);
72      }
73    }
74
75    public override int GetHashCode() {
76      return (int)Math.Pow(DX, DY);
77    }
78
79    public override string ToString() {
80      return string.Format("({0};{1})", DX, DY);
81    }
82
83    public static Offset operator +(Offset offset1, Offset offset2) {
84      return new Offset(offset1.DX + offset2.DX, offset1.DY + offset2.DY);
85    }
86
87    public static Offset operator -(Offset offset1, Offset offset2) {
88      return new Offset(offset1.DX - offset2.DX, offset1.DY - offset2.DY);
89    }
90
91    public static bool operator ==(Offset offset1, Offset offset2) {
92      return (offset1.DX == offset2.DX) && (offset1.DY == offset2.DY);
93    }
94
95    public static bool operator !=(Offset offset1, Offset offset2) {
96      return (offset1.DX != offset2.DX) && (offset1.DY != offset2.DY);
97    }
98
99    public static explicit operator PointD(Offset offset) {
100      return new PointD(offset.DX, offset.DY);
101    }
102
103    public static explicit operator SizeD(Offset offset) {
104      return new SizeD(offset.DX, offset.DY);
105    }
106
107    public static Offset Add(Offset offset1, Offset offset2) {
108      return new Offset(offset1.DX + offset2.DX, offset1.DY + offset2.DY);
109    }
110
111    public static Offset Subtract(Offset offset1, Offset offset2) {
112      return new Offset(offset1.DX - offset2.DX, offset1.DY - offset2.DY);
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.