1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Crow
{
public struct Size
{
internal static Type TSize = typeof(Size);
public static Size Zero
{ get { return new Size(0, 0); } }
int _width;
int _height;
public Size(int width, int height)
{
_width = width;
_height = height;
}
public Size(int size)
{
_width = size;
_height = size;
}
public int Width
{
get { return _width; }
set { _width = value; }
}
public int Height
{
get { return _height; }
set { _height = value; }
}
#region operators
public static implicit operator Rectangle(Size s)
{
return new Rectangle (s);
}
public static implicit operator Size(int i)
{
return new Size(i, i);
}
public static implicit operator string(Size s)
{
return s.ToString ();
}
public static implicit operator Size(string s)
{
return string.IsNullOrEmpty (s) ? Size.Zero : Parse (s);
}
public static bool operator ==(Size s1, Size s2)
{
if (s1.Width == s2.Width && s1.Height == s2.Height)
return true;
else
return false;
}
public static bool operator !=(Size s1, Size s2)
{
if (s1.Width == s2.Width && s1.Height == s2.Height)
return false;
else
return true;
}
public static bool operator >(Size s1, Size s2)
{
if (s1.Width > s2.Width && s1.Height > s2.Height)
return true;
else
return false;
}
public static bool operator >=(Size s1, Size s2)
{
if (s1.Width >= s2.Width && s1.Height >= s2.Height)
return true;
else
return false;
}
public static bool operator <(Size s1, Size s2)
{
if (s1.Width < s2.Width)
if (s1.Height <= s2.Height)
return true;
else
return false;
else if (s1.Width == s2.Width && s1.Height < s2.Height)
return true;
return false;
}
public static bool operator <(Size s, int i)
{
return s.Width < i && s.Height < i ? true : false;
}
public static bool operator <=(Size s, int i)
{
return s.Width <= i && s.Height <= i ? true : false;
}
public static bool operator <=(Size s1, Size s2)
{
if (s1.Width <= s2.Width && s1.Height <= s2.Height)
return true;
else
return false;
}
public static bool operator ==(Size s, int i)
{
if (s.Width == i && s.Height == i)
return true;
else
return false;
}
public static bool operator !=(Size s, int i)
{
if (s.Width == i && s.Height == i)
return false;
else
return true;
}
public static Size operator +(Size s1, Size s2)
{
return new Size(s1.Width + s2.Width, s1.Height + s2.Height);
}
public static Size operator +(Size s, int i)
{
return new Size(s.Width + i, s.Height + i);
}
#endregion
public override int GetHashCode ()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + _width.GetHashCode();
hash = hash * 23 + _height.GetHashCode();
return hash;
}
}
public override bool Equals (object obj)
{
return (obj == null || obj.GetType() != TSize) ?
false :
this == (Size)obj;
}
public override string ToString()
{
return string.Format("{0},{1}", Width, Height);
}
public static Size Parse(string s)
{
string[] d = s.Split(new char[] { ',' });
return d.Length == 1 ? new Size(int.Parse(d[0])) : new Size(
int.Parse(d[0]),
int.Parse(d[1]));
}
}
}
|