aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/Size.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-03 17:05:51 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-03 17:05:51 +0200
commita7363d1f7e4eb1611e4ab522c8cf381b70570b7e (patch)
treed8f9f599fb6c13d55db8bc48a998b0c7430333ef /src/Size.cs
parentef87679b886e5ce8b4defc21e3b9eac6c5030663 (diff)
- min and max dimensions for objects
Diffstat (limited to 'src/Size.cs')
-rwxr-xr-xsrc/Size.cs38
1 files changed, 30 insertions, 8 deletions
diff --git a/src/Size.cs b/src/Size.cs
index 72f8fff1..c2231576 100755
--- a/src/Size.cs
+++ b/src/Size.cs
@@ -9,16 +9,20 @@ namespace go
{
public static Size Zero
{ get { return new Size(0, 0); } }
+
int _width;
int _height;
- //public Size()
- //{ }
public Size(int width, int height)
{
_width = width;
_height = height;
}
+ public Size(int size)
+ {
+ _width = size;
+ _height = size;
+ }
public int Width
{
get { return _width; }
@@ -29,10 +33,7 @@ namespace go
get { return _height; }
set { _height = value; }
}
- public override string ToString()
- {
- return string.Format("({0},{1})", Width, Height);
- }
+ #region operators
public static implicit operator Rectangle(Size s)
{
return new Rectangle (s);
@@ -41,7 +42,15 @@ namespace go
{
return new Size(i, i);
}
- public static bool operator ==(Size s1, Size s2)
+ 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;
@@ -118,6 +127,19 @@ namespace go
{
return new Size(s.Width + i, s.Height + i);
}
- }
+ #endregion
+
+ 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]));
+ }
+ }
}