Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/SizeD.cs @ 1235

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

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

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