Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1265_HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/Offset.cs @ 17021

Last change on this file since 17021 was 13717, checked in by bburlacu, 9 years ago

#1265: Updated license year to 2016.

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