source: Include/Classes/System/Drawing/RectangleF.ab@ 11

Last change on this file since 11 was 11, checked in by イグトランス (egtra), 17 years ago

misc

File size: 5.0 KB
Line 
1' Classes/System/Drawing/RectangleF.ab
2
3#ifndef __SYSTEM_DRAWING_RECTANGLEF_AB__
4#define __SYSTEM_DRAWING_RECTANGLEF_AB__
5
6#include <Classes/System/Math.ab>
7#include <Classes/System/Drawing/PointF.ab>
8#include <Classes/System/Drawing/SizeF.ab>
9
10Class RectangleF
11Public
12 Sub RectangleF()
13 x = 0
14 y = 0
15 width = 0
16 height = 0
17 End Sub
18
19 Sub RectangleF(x As Single, y As Single, width As Single, height As Single)
20 x = x
21 y = y
22 width = width
23 height = height
24 End Sub
25
26 Sub RectangleF(location As PointF, size As SizeF)
27 x = location.X
28 y = lccation.Y
29 width = size.Height
30 hegiht = size.Height
31 End Sub
32
33 Sub RectangleF(ByRef rc As RectangleF)
34 x = rc.x
35 y = rc.y
36 widht = rc.width
37 height = rc.height
38 End Sub
39
40 Function Location() As PointF
41 Dim pt As PointF(x, y)
42 Return pt
43 End Function
44
45 Sub Location(ByRef point As PointF)
46 x = point.X
47 y = point.Y
48 End Sub
49
50 Function Size() As SizeF
51 Dim size As SizeF(width, height)
52 End Function
53
54 Sub Size(ByRef size As SizeF)
55 width = size.Width
56 height = size.Height
57 End Sub
58
59 Function X() As Single
60 Return x
61 End Function
62
63 Sub X(value As Single)
64 x = value
65 End Sub
66
67 Function Y() As Single
68 Return y
69 End Function
70
71 Sub Y(value As Single)
72 y = value
73 End Sub
74
75 Function Width() As Single
76 Return width
77 End Function
78
79 Sub Width(value As Single)
80 width = value
81 End Sub
82
83 Function Height() As Single
84 Return height
85 End Function
86
87 Sub Height(value As Single)
88 height = value
89 End Sub
90
91 Function Left() As Single
92 Return X
93 End Function
94
95 Function Top() As Single
96 Return Y
97 End Function
98
99 Function Right() As Single
100 Return X + Width
101 End Function
102
103 Function Bottom() As Single
104 Return Y + Height
105 End Function
106
107 Function IsEmpty() As BOOL
108 If Width <= Single_EPSILON Or Height <= Single_EPSILON Then
109 IsEmptyArea = _System_TRUE
110 Else
111 IsEmptyArea = _System_FALSE
112 End If
113 End Function
114
115 Function Operator = (ByRef rc As RectangleF)
116 With rc
117 x = .x
118 y = .y
119 width = .width
120 height = .height
121 End With
122 End Function
123
124 Function Operator == (ByRef rc As RectangleF)
125 Return Equals(rc)
126 End Function
127
128 Function Operator <> (ByRef rc As RectangleF)
129 Return Not Equals(rc)
130 End Function
131
132 Function Equals(ByRef rc As RectangleF) As BOOL
133 If X = rc.X And Y = rc.Y And Width = rc.Width And Height = rc.Height Then
134 Equals = _System_TRUE
135 Else
136 Equals = _System_FALSE
137 End If
138 End Function
139
140 Static Function FromLTRB(l As Single, t As Single, r As Single, b As Single) As RectangleF
141 Dim r As RectangleF(left, top, right - left, bottom - top)
142 return r
143 End Function
144
145 Function Contains(x As Single, y As Single) As BOOL
146 If x >= X And x < X + Width And y >= Y And y < Y + Height Then
147 Contains = _System_TRUE
148 Else
149 Contains = _System_FALSE
150 End If
151 End Function
152
153 Function Contains(ByRef pt As PointF) As BOOL
154 ContainsPTF = Contains(pt.X, pt.Y)
155 End Function
156
157 Function Contains(ByRef rc As RectangleF) As BOOL
158 If X <= rc.X && rc.Right <= Right && Y <= rc.Y && rc.Bottom <= Bottom Then
159 ContainsRCF = _System_TRUE
160 Else
161 ContainsRCF = _System_FALSE
162 End If
163 End Function
164
165 Sub Inflate(dx As Single, dy As Single)
166 X -= dx
167 Y -= dy
168 Width = dx + dx
169 Height = dy + dy
170 End Sub
171
172 Sub Inflate(sz As SizeF)
173 Inflate(sz.Width, sz.Height)
174 End Sub
175
176 Sub Inflate(pt As PointF)
177 Inflate(pt.X, pt.Y)
178 End Sub
179
180 Static Function Inflate(ByRef rc As RectangleF, x As Single, y As Single) As RectangleF
181 Inflate = rc
182 Inflate.Inflate(x, y)
183 End Function
184
185 Function Intersect(ByRef rect As RectangleF) As BOOL
186 Intersect = Intersect(This, This, rect)
187 End Function
188
189 Static Function Intersect(ByRef a As RectangleF, ByRef b As RectangleF) As RectangleF
190 Dim right As Single, bottom As Single, left As Single, top As Single
191 right = Math.Min(a.Right, b.Right)
192 bottom = Math.Min(a.Bottom, b.Bottom)
193 left = Math.Min(a.Left, b.Left)
194 top = Math.Min(a.Top, b.Top)
195 Return FromLTRB(left, top, right, bottom)
196 End Function
197
198 Function IntersectsWith(ByRef rc As RectangleF) As BOOL
199 If Left < rc.Right And _
200 Top < rc.Bottom And _
201 Right > rc.Left And _
202 Bottom > rc.Top Then
203 IntersectsWith = _System_TRUE
204 Else
205 IntersectsWith = _System_FALSE
206 End If
207 End Function
208
209 Static Function Union(ByRef a As RectangleF, ByRef b As RectangleF) As RectangleF
210 Dim right As Single, bottom As Single, left As Single, top As Single
211 right = Math.Max(a.GetRight(), b.GetRight())
212 bottom = Math.Max(a.GetBottom(), b.GetBottom())
213 left = Math.Max(a.GetLeft(), b.GetLeft())
214 top = Math.Max(a.GetTop(), b.GetTop())
215 Return FromLTRB(left, top, right, bottom)
216 End Function
217
218 Sub Offset(pt As PointF)
219 Offset(pt.X, pt.Y)
220 End Sub
221
222 Sub Offset(dx As Single, dy As Single)
223 X += dx
224 Y += dy
225 End Sub
226
227Public
228 x As Single
229 y As Single
230 width As Single
231 height As Single
232End Class
233
234#endif '__SYSTEM_DRAWING_RECTFANGLE_AB__
Note: See TracBrowser for help on using the repository browser.