1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 |
// *******************************************//
// *********Credits to Kyle Schouviller*******//
// *******for the original implementation*****//
// *******************************************//
using System;
using Microsoft.Xna.Framework;
namespace Brains.Framework.QuadTree
{
/// <summary>
/// Stores a set of four floating-point numbers that represent the location and size of a rectangle.
/// </summary>
public struct RectangleF
{
private Vector2 topLeft;
private Vector2 bottomRight;
public Vector2 TopLeft
{
get { return topLeft; }
set { topLeft = value; }
}
public Vector2 TopRight
{
get { return new Vector2(bottomRight.X, topLeft.Y); }
set
{
bottomRight.X = value.X;
topLeft.Y = value.Y;
}
}
public Vector2 BottomRight
{
get { return bottomRight; }
set { bottomRight = value; }
}
public Vector2 BottomLeft
{
get { return new Vector2(topLeft.X, bottomRight.Y); }
set
{
topLeft.X = value.X;
bottomRight.Y = value.Y;
}
}
public float Top
{
get { return TopLeft.Y; }
set { topLeft.Y = value; }
}
public float Left
{
get { return TopLeft.X; }
set { topLeft.X = value; }
}
public float Bottom
{
get { return BottomRight.Y; }
set { bottomRight.Y = value; }
}
public float Right
{
get { return BottomRight.X; }
set { bottomRight.X = value; }
}
public float Width
{
get { return bottomRight.X - topLeft.X; }
}
public float Height
{
get { return bottomRight.Y - topLeft.Y; }
}
/// <summary>
/// Floating-point rectangle constructor
/// </summary>
/// <param name="topleft">The top left point of the rectangle</param>
/// <param name="bottomright">The bottom right point of the rectangle</param>
public RectangleF(Vector2 topleft, Vector2 bottomright)
{
topLeft = topleft;
bottomRight = bottomright;
}
/// <summary>
/// Floating-point rectangle constructor
/// </summary>
/// <param name="top">The top of the rectangle</param>
/// <param name="left">The left of the rectangle</param>
/// <param name="bottom">The bottom of the rectangle</param>
/// <param name="right">The right of the rectangle</param>
public RectangleF(float top, float left, float bottom, float right)
{
topLeft = new Vector2(left, top);
bottomRight = new Vector2(right, bottom);
}
public bool Contains(Vector2 Point)
{
return (topLeft.X <= Point.X && bottomRight.X >= Point.X &&
topLeft.Y <= Point.Y && bottomRight.Y >= Point.Y);
}
public bool Intersects(RectangleF Rect)
{
return (!(Bottom < Rect.Top ||
Top > Rect.Bottom ||
Right < Rect.Left ||
Left > Rect.Right));
}
}
} |