Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Rectangle.cs
浏览该文件的文档.
1namespace Engine {
2 public struct Rectangle : IEquatable<Rectangle> {
3 public int Left;
4
5 public int Top;
6
7 public int Width;
8
9 public int Height;
10
11 public static Rectangle Empty;
12
14 get => new(Left, Top);
15 set {
16 Left = value.X;
17 Top = value.Y;
18 }
19 }
20
21 public Point2 Size {
22 get => new(Width, Height);
23 set {
24 Width = value.X;
25 Height = value.Y;
26 }
27 }
28
29 public int Right => Left + Width;
30
31 public int Bottom => Top + Height;
32
33 public Rectangle(int left, int top, int width, int height) {
34 Left = left;
35 Top = top;
36 Width = width;
37 Height = height;
38 }
39
40 public static implicit operator Rectangle((int Left, int Top, int Width, int Height) v) => new(v.Left, v.Top, v.Width, v.Height);
41
42 public bool Equals(Rectangle other) => Left == other.Left && Top == other.Top && Width == other.Width && Height == other.Height;
43
44 public override bool Equals(object obj) => obj is Rectangle && Equals((Rectangle)obj);
45
46 public override int GetHashCode() => Left + Top + Width + Height;
47
48 public override string ToString() => $"{Left},{Top},{Width},{Height}";
49
50 public bool Contains(Point2 p) => p.X >= Left && p.X < Left + Width && p.Y >= Top && p.Y < Top + Height;
51
52 public bool Intersection(Rectangle r) {
53 int num = MathUtils.Max(Left, r.Left);
54 int num2 = MathUtils.Max(Top, r.Top);
55 int num3 = MathUtils.Min(Left + Width, r.Left + r.Width);
56 int num4 = MathUtils.Min(Top + Height, r.Top + r.Height);
57 return num3 > num && num4 > num2;
58 }
59
60 public static Rectangle Intersection(Rectangle r1, Rectangle r2) {
61 int num = MathUtils.Max(r1.Left, r2.Left);
62 int num2 = MathUtils.Max(r1.Top, r2.Top);
63 int num3 = MathUtils.Min(r1.Left + r1.Width, r2.Left + r2.Width);
64 int num4 = MathUtils.Min(r1.Top + r1.Height, r2.Top + r2.Height);
65 return num3 <= num || num4 <= num2 ? Empty : new Rectangle(num, num2, num3 - num, num4 - num2);
66 }
67
68 public static Rectangle Union(Rectangle r1, Rectangle r2) {
69 int num = MathUtils.Min(r1.Left, r2.Left);
70 int num2 = MathUtils.Min(r1.Top, r2.Top);
71 int num3 = MathUtils.Max(r1.Left + r1.Width, r2.Left + r2.Width);
72 int num4 = MathUtils.Max(r1.Top + r1.Height, r2.Top + r2.Height);
73 return new Rectangle(num, num2, num3 - num, num4 - num2);
74 }
75
76 public static bool operator ==(Rectangle r1, Rectangle r2) => r1.Equals(r2);
77
78 public static bool operator !=(Rectangle r1, Rectangle r2) => !r1.Equals(r2);
79 }
80}
static int Min(int x1, int x2)
static int Max(int x1, int x2)
static bool operator!=(Rectangle r1, Rectangle r2)
bool Intersection(Rectangle r)
bool Equals(Rectangle other)
override bool Equals(object obj)
static Rectangle Intersection(Rectangle r1, Rectangle r2)
static Rectangle Empty
static Rectangle Union(Rectangle r1, Rectangle r2)
static bool operator==(Rectangle r1, Rectangle r2)
bool Contains(Point2 p)
override string ToString()
Rectangle(int left, int top, int width, int height)
override int GetHashCode()