Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Charting/3.2/Structs/Offset.cs @ 2901

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

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

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