Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Rectangle.cs
Go to the documentation of this file.
4
5namespace System.Drawing;
6
8[TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
9[TypeConverter("System.Drawing.RectangleConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
10public struct Rectangle : IEquatable<Rectangle>
11{
12 public static readonly Rectangle Empty;
13
14 private int x;
15
16 private int y;
17
18 private int width;
19
20 private int height;
21
22 [Browsable(false)]
24 {
25 readonly get
26 {
27 return new Point(X, Y);
28 }
29 set
30 {
31 X = value.X;
32 Y = value.Y;
33 }
34 }
35
36 [Browsable(false)]
37 public Size Size
38 {
39 readonly get
40 {
41 return new Size(Width, Height);
42 }
43 set
44 {
45 Width = value.Width;
46 Height = value.Height;
47 }
48 }
49
50 public int X
51 {
52 readonly get
53 {
54 return x;
55 }
56 set
57 {
58 x = value;
59 }
60 }
61
62 public int Y
63 {
64 readonly get
65 {
66 return y;
67 }
68 set
69 {
70 y = value;
71 }
72 }
73
74 public int Width
75 {
76 readonly get
77 {
78 return width;
79 }
80 set
81 {
82 width = value;
83 }
84 }
85
86 public int Height
87 {
88 readonly get
89 {
90 return height;
91 }
92 set
93 {
94 height = value;
95 }
96 }
97
98 [Browsable(false)]
99 public readonly int Left => X;
100
101 [Browsable(false)]
102 public readonly int Top => Y;
103
104 [Browsable(false)]
105 public readonly int Right => X + Width;
106
107 [Browsable(false)]
108 public readonly int Bottom => Y + Height;
109
110 [Browsable(false)]
111 public readonly bool IsEmpty
112 {
113 get
114 {
115 if (height == 0 && width == 0 && x == 0)
116 {
117 return y == 0;
118 }
119 return false;
120 }
121 }
122
123 public Rectangle(int x, int y, int width, int height)
124 {
125 this.x = x;
126 this.y = y;
127 this.width = width;
128 this.height = height;
129 }
130
131 public Rectangle(Point location, Size size)
132 {
133 x = location.X;
134 y = location.Y;
135 width = size.Width;
136 height = size.Height;
137 }
138
139 public static Rectangle FromLTRB(int left, int top, int right, int bottom)
140 {
141 return new Rectangle(left, top, right - left, bottom - top);
142 }
143
144 public override readonly bool Equals([NotNullWhen(true)] object? obj)
145 {
146 if (obj is Rectangle)
147 {
148 return Equals((Rectangle)obj);
149 }
150 return false;
151 }
152
153 public readonly bool Equals(Rectangle other)
154 {
155 return this == other;
156 }
157
158 public static bool operator ==(Rectangle left, Rectangle right)
159 {
160 if (left.X == right.X && left.Y == right.Y && left.Width == right.Width)
161 {
162 return left.Height == right.Height;
163 }
164 return false;
165 }
166
167 public static bool operator !=(Rectangle left, Rectangle right)
168 {
169 return !(left == right);
170 }
171
173 {
174 return new Rectangle((int)Math.Ceiling(value.X), (int)Math.Ceiling(value.Y), (int)Math.Ceiling(value.Width), (int)Math.Ceiling(value.Height));
175 }
176
178 {
179 return new Rectangle((int)value.X, (int)value.Y, (int)value.Width, (int)value.Height);
180 }
181
183 {
184 return new Rectangle((int)Math.Round(value.X), (int)Math.Round(value.Y), (int)Math.Round(value.Width), (int)Math.Round(value.Height));
185 }
186
187 public readonly bool Contains(int x, int y)
188 {
189 if (X <= x && x < X + Width && Y <= y)
190 {
191 return y < Y + Height;
192 }
193 return false;
194 }
195
196 public readonly bool Contains(Point pt)
197 {
198 return Contains(pt.X, pt.Y);
199 }
200
201 public readonly bool Contains(Rectangle rect)
202 {
203 if (X <= rect.X && rect.X + rect.Width <= X + Width && Y <= rect.Y)
204 {
205 return rect.Y + rect.Height <= Y + Height;
206 }
207 return false;
208 }
209
210 public override readonly int GetHashCode()
211 {
212 return HashCode.Combine(X, Y, Width, Height);
213 }
214
215 public void Inflate(int width, int height)
216 {
217 X -= width;
218 Y -= height;
219 Width += 2 * width;
220 Height += 2 * height;
221 }
222
223 public void Inflate(Size size)
224 {
225 Inflate(size.Width, size.Height);
226 }
227
228 public static Rectangle Inflate(Rectangle rect, int x, int y)
229 {
230 Rectangle result = rect;
231 result.Inflate(x, y);
232 return result;
233 }
234
235 public void Intersect(Rectangle rect)
236 {
237 Rectangle rectangle = Intersect(rect, this);
238 X = rectangle.X;
239 Y = rectangle.Y;
240 Width = rectangle.Width;
241 Height = rectangle.Height;
242 }
243
245 {
246 int num = Math.Max(a.X, b.X);
247 int num2 = Math.Min(a.X + a.Width, b.X + b.Width);
248 int num3 = Math.Max(a.Y, b.Y);
249 int num4 = Math.Min(a.Y + a.Height, b.Y + b.Height);
250 if (num2 >= num && num4 >= num3)
251 {
252 return new Rectangle(num, num3, num2 - num, num4 - num3);
253 }
254 return Empty;
255 }
256
257 public readonly bool IntersectsWith(Rectangle rect)
258 {
259 if (rect.X < X + Width && X < rect.X + rect.Width && rect.Y < Y + Height)
260 {
261 return Y < rect.Y + rect.Height;
262 }
263 return false;
264 }
265
266 public static Rectangle Union(Rectangle a, Rectangle b)
267 {
268 int num = Math.Min(a.X, b.X);
269 int num2 = Math.Max(a.X + a.Width, b.X + b.Width);
270 int num3 = Math.Min(a.Y, b.Y);
271 int num4 = Math.Max(a.Y + a.Height, b.Y + b.Height);
272 return new Rectangle(num, num3, num2 - num, num4 - num3);
273 }
274
275 public void Offset(Point pos)
276 {
277 Offset(pos.X, pos.Y);
278 }
279
280 public void Offset(int x, int y)
281 {
282 X += x;
283 Y += y;
284 }
285
286 public override readonly string ToString()
287 {
288 return $"{{X={X},Y={Y},Width={Width},Height={Height}}}";
289 }
290}
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static decimal Round(decimal d)
Definition Math.cs:1096
static double Ceiling(double a)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
void Offset(int x, int y)
Definition Rectangle.cs:280
static readonly Rectangle Empty
Definition Rectangle.cs:12
void Inflate(Size size)
Definition Rectangle.cs:223
static Rectangle Intersect(Rectangle a, Rectangle b)
Definition Rectangle.cs:244
void Intersect(Rectangle rect)
Definition Rectangle.cs:235
readonly bool IntersectsWith(Rectangle rect)
Definition Rectangle.cs:257
static Rectangle Inflate(Rectangle rect, int x, int y)
Definition Rectangle.cs:228
void Inflate(int width, int height)
Definition Rectangle.cs:215
static bool operator!=(Rectangle left, Rectangle right)
Definition Rectangle.cs:167
static bool operator==(Rectangle left, Rectangle right)
Definition Rectangle.cs:158
readonly bool Contains(int x, int y)
Definition Rectangle.cs:187
override readonly bool Equals([NotNullWhen(true)] object? obj)
Definition Rectangle.cs:144
override readonly string ToString()
Definition Rectangle.cs:286
void Offset(Point pos)
Definition Rectangle.cs:275
readonly bool IsEmpty
Definition Rectangle.cs:112
static Rectangle Ceiling(RectangleF value)
Definition Rectangle.cs:172
Rectangle(Point location, Size size)
Definition Rectangle.cs:131
Rectangle(int x, int y, int width, int height)
Definition Rectangle.cs:123
static Rectangle Union(Rectangle a, Rectangle b)
Definition Rectangle.cs:266
override readonly int GetHashCode()
Definition Rectangle.cs:210
readonly bool Contains(Rectangle rect)
Definition Rectangle.cs:201
readonly bool Contains(Point pt)
Definition Rectangle.cs:196
readonly bool Equals(Rectangle other)
Definition Rectangle.cs:153
static Rectangle Round(RectangleF value)
Definition Rectangle.cs:182
static Rectangle FromLTRB(int left, int top, int right, int bottom)
Definition Rectangle.cs:139
static Rectangle Truncate(RectangleF value)
Definition Rectangle.cs:177