Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2287 | - | 1 | |
2 | namespace GMap.NET |
||
3 | { |
||
4 | using System.Globalization; |
||
5 | |||
6 | /// <summary> |
||
7 | /// the size |
||
8 | /// </summary> |
||
9 | public struct GSize |
||
10 | { |
||
11 | public static readonly GSize Empty = new GSize(); |
||
12 | |||
13 | private long width; |
||
14 | private long height; |
||
15 | |||
16 | public GSize(GPoint pt) |
||
17 | { |
||
18 | width = pt.X; |
||
19 | height = pt.Y; |
||
20 | } |
||
21 | |||
22 | public GSize(long width, long height) |
||
23 | { |
||
24 | this.width = width; |
||
25 | this.height = height; |
||
26 | } |
||
27 | |||
28 | public static GSize operator +(GSize sz1, GSize sz2) |
||
29 | { |
||
30 | return Add(sz1, sz2); |
||
31 | } |
||
32 | |||
33 | public static GSize operator -(GSize sz1, GSize sz2) |
||
34 | { |
||
35 | return Subtract(sz1, sz2); |
||
36 | } |
||
37 | |||
38 | public static bool operator ==(GSize sz1, GSize sz2) |
||
39 | { |
||
40 | return sz1.Width == sz2.Width && sz1.Height == sz2.Height; |
||
41 | } |
||
42 | |||
43 | public static bool operator !=(GSize sz1, GSize sz2) |
||
44 | { |
||
45 | return !(sz1 == sz2); |
||
46 | } |
||
47 | |||
48 | public static explicit operator GPoint(GSize size) |
||
49 | { |
||
50 | return new GPoint(size.Width, size.Height); |
||
51 | } |
||
52 | |||
53 | public bool IsEmpty |
||
54 | { |
||
55 | get |
||
56 | { |
||
57 | return width == 0 && height == 0; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | public long Width |
||
62 | { |
||
63 | get |
||
64 | { |
||
65 | return width; |
||
66 | } |
||
67 | set |
||
68 | { |
||
69 | width = value; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | public long Height |
||
74 | { |
||
75 | get |
||
76 | { |
||
77 | return height; |
||
78 | } |
||
79 | set |
||
80 | { |
||
81 | height = value; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | public static GSize Add(GSize sz1, GSize sz2) |
||
86 | { |
||
87 | return new GSize(sz1.Width + sz2.Width, sz1.Height + sz2.Height); |
||
88 | } |
||
89 | |||
90 | public static GSize Subtract(GSize sz1, GSize sz2) |
||
91 | { |
||
92 | return new GSize(sz1.Width - sz2.Width, sz1.Height - sz2.Height); |
||
93 | } |
||
94 | |||
95 | public override bool Equals(object obj) |
||
96 | { |
||
97 | if(!(obj is GSize)) |
||
98 | return false; |
||
99 | |||
100 | GSize comp = (GSize)obj; |
||
101 | // Note value types can't have derived classes, so we don't need to |
||
102 | // |
||
103 | return (comp.width == this.width) && |
||
104 | (comp.height == this.height); |
||
105 | } |
||
106 | |||
107 | public override int GetHashCode() |
||
108 | { |
||
109 | if(this.IsEmpty) |
||
110 | { |
||
111 | return 0; |
||
112 | } |
||
113 | return (Width.GetHashCode() ^ Height.GetHashCode()); |
||
114 | } |
||
115 | |||
116 | public override string ToString() |
||
117 | { |
||
118 | return "{Width=" + width.ToString(CultureInfo.CurrentCulture) + ", Height=" + height.ToString(CultureInfo.CurrentCulture) + "}"; |
||
119 | } |
||
120 | } |
||
121 | } |