Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1265_HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Structs/SizeD.cs @ 17399

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

#1265: Updated license year to 2016.

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