1
2
3
4
5
6 using System;
7
8 namespace System.Screen
9 {
10 public class Point
11 {
12 public nothrow Point() : x(0), y(0)
13 {
14 }
15 public nothrow Point(int x_, int y_) : x(x_), y(y_)
16 {
17 }
18 public static nothrow Point Default()
19 {
20 return Point(-1, -1);
21 }
22 public nothrow bool IsDefault() const
23 {
24 return x == -1 && y == -1;
25 }
26 public nothrow void Offset(int dx, int dy)
27 {
28 x = x + dx;
29 y = y + dy;
30 }
31 public nothrow string ToString() const
32 {
33 return "(" + ToString(x) + ", " + ToString(y) + ")";
34 }
35 public int x;
36 public int y;
37 }
38
39 public nothrow bool operator==(const Point& left, const Point& right)
40 {
41 return left.x == right.x && left.y == right.y;
42 }
43
44 public class Size
45 {
46 public nothrow Size() : w(0), h(0)
47 {
48 }
49 public nothrow Size(int w_, int h_) : w(w_), h(h_)
50 {
51 }
52 public static nothrow Size Default()
53 {
54 return Size(-1, -1);
55 }
56 public nothrow bool IsDefault() const
57 {
58 return w == -1 && h == -1;
59 }
60 public nothrow string ToString() const
61 {
62 return "(" + ToString(w) + ", " + ToString(h) + ")";
63 }
64 public int w;
65 public int h;
66 }
67
68 public nothrow bool operator==(const Size& left, const Size& right)
69 {
70 return left.w == right.w && left.h == right.h;
71 }
72
73 public class Rect
74 {
75 public nothrow Rect() : location(), size()
76 {
77 }
78 public nothrow Rect(const Point& location_, const Size& size_) : location(location_), size(size_)
79 {
80 }
81 public static nothrow Rect Default()
82 {
83 return Rect(Point.Default(), Size.Default());
84 }
85 public nothrow bool IsDefault() const
86 {
87 return location.IsDefault() && size.IsDefault();
88 }
89 public nothrow bool IsEmpty() const
90 {
91 return size.w == 0 && size.h == 0;
92 }
93 public inline nothrow int Left() const
94 {
95 return location.x;
96 }
97 public inline nothrow int Right() const
98 {
99 return location.x + size.w;
100 }
101 public inline nothrow int Top() const
102 {
103 return location.y;
104 }
105 public inline nothrow int Bottom() const
106 {
107 return location.y + size.h;
108 }
109 public inline nothrow bool Contains(const Point& p)
110 {
111 return p.x >= location.x && p.x < location.x + size.w && p.y >= location.y && p.y < location.y + size.h;
112 }
113 public inline nothrow void Inflate(int dx, int dy)
114 {
115 location.x = location.x - dx;
116 location.y = location.y - dy;
117 size.w = size.w + 2 * dx;
118 size.h = size.h + 2 * dy;
119 }
120 public inline nothrow void Offset(int dx, int dy)
121 {
122 location.Offset(dx, dy);
123 }
124 public nothrow bool IntersectsWith(const Rect& that) const
125 {
126 return Left() < that.Right() && Top() < that.Bottom() && Right() > that.Left() && Bottom() > that.Top();
127 }
128 public static nothrow Rect Union(const Rect& a, const Rect& b)
129 {
130 int right = Max(a.Right(), b.Right());
131 int bottom = Max(a.Bottom(), b.Bottom());
132 int left = Min(a.Left(), b.Left());
133 int top = Min(a.Top(), b.Top());
134 return Rect(Point(left, top), Size(right - left, bottom - top));
135 }
136 public static nothrow Rect Intersection(const Rect& a, const Rect& b)
137 {
138 int right = Min(a.Right(), b.Right());
139 int bottom = Min(a.Bottom(), b.Bottom());
140 int left = Max(a.Left(), b.Left());
141 int top = Max(a.Top(), b.Top());
142 return Rect(Point(left, top), Size(right - left, bottom - top));
143 }
144 public string ToString() const
145 {
146 return "[" + location.ToString() + ", " + size.ToString() + "]";
147 }
148 public Point location;
149 public Size size;
150 }
151
152 public nothrow bool operator==(const Rect& left, const Rect& right)
153 {
154 return left.location == right.location && left.size == right.size;
155 }
156 }