Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Collections/sources/HeuristicLab.Charting/Structs/SizeD.cs @ 440

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

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

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