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