author | Claus Gittinger <cg@exept.de> |
Thu, 07 Oct 1999 01:45:37 +0200 | |
changeset 4864 | 3ff21a7f977d |
parent 4863 | 9544c9e5c17e |
child 4868 | 339707d6cc2a |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
186 | 3 |
All Rights Reserved |
1 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
356 | 13 |
Geometric subclass:#Rectangle |
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
14 |
instanceVariableNames:'left top width height' |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
15 |
classVariableNames:'' |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
16 |
poolDictionaries:'' |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
17 |
category:'Graphics-Geometry' |
1 | 18 |
! |
19 |
||
77 | 20 |
!Rectangle class methodsFor:'documentation'! |
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
186 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
77 | 36 |
documentation |
37 |
" |
|
38 |
Rectangles represent a rectangular area in 2D space. |
|
39 |
||
40 |
notice, my implementation does not use origin/corner as instance objects |
|
41 |
but left/top/width/height to save space and allocations. This means, that my |
|
42 |
Rectangles cannot be used to represent Rectangles in a higher than 2D |
|
43 |
space. (i.e. only valid if origin/corner are 2D Points) |
|
44 |
||
45 |
(aside from that, you will not see any difference from the outside) |
|
46 |
||
47 |
Instance variables: |
|
48 |
||
1290 | 49 |
left <Number> the left coordinate (i.e origin x) |
50 |
top <Number> the top coordinate (i.e origin y) |
|
51 |
width <Number> the width of the rectangle |
|
52 |
height <Number> the height of the rectangle |
|
77 | 53 |
|
54 |
I am not certain, if implementing Rectangle different was a good idea - |
|
55 |
subclasses may expect things to be different ... |
|
56 |
Therefore, this may change. |
|
1290 | 57 |
|
58 |
[author:] |
|
59 |
Claus Gittinger |
|
60 |
||
1314 | 61 |
[see also:] |
1355 | 62 |
Point Polygon Circle EllipticalArc Spline |
1314 | 63 |
LayoutOrigin LayoutFrame AlignmentOrigin Layout |
1390 | 64 |
View GraphicsContext StrokingWrapper FillingWrapper |
77 | 65 |
" |
66 |
! ! |
|
67 |
||
1 | 68 |
!Rectangle class methodsFor:'instance creation'! |
69 |
||
3239
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
70 |
decodeFromLiteralArray:anArray |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
71 |
"create & return a new instance from information encoded in anArray. |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
72 |
Redefined for faster creation." |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
73 |
|
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
74 |
|l t w h| |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
75 |
|
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
76 |
l := anArray at:2. |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
77 |
t := anArray at:3. |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
78 |
w := (anArray at:4) - l. |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
79 |
h := (anArray at:5) - t. |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
80 |
^ self left:l top:t width:w height:h |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
81 |
|
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
82 |
" |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
83 |
Rectangle decodeFromLiteralArray:#(Rectangle 100 200 300 500) |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
84 |
" |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
85 |
|
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
86 |
"Created: / 28.1.1998 / 17:46:52 / cg" |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
87 |
! |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
88 |
|
4864 | 89 |
encompassing:listOfPoints |
90 |
"Return a rectangle, which encompasses all of the given points." |
|
91 |
||
92 |
|topLeft bottomRight| |
|
93 |
||
94 |
topLeft := bottomRight := nil. |
|
95 |
listOfPoints do:[:p | |
|
96 |
topLeft == nil |
|
97 |
ifTrue: [topLeft := bottomRight := p] |
|
98 |
ifFalse: [topLeft := topLeft min: p. |
|
99 |
bottomRight := bottomRight max: p] |
|
100 |
]. |
|
101 |
^ topLeft corner: bottomRight |
|
102 |
||
103 |
" |
|
104 |
Rectangle encompassing:(Array with:10@10 with:50@0 with:0@50) |
|
105 |
" |
|
106 |
! |
|
107 |
||
637 | 108 |
fromUser |
109 |
"let user specify a rectangle on the screen, return it" |
|
110 |
||
111 |
^ Screen current rectangleFromUser |
|
112 |
||
113 |
" |
|
114 |
Rectangle fromUser |
|
115 |
" |
|
116 |
! |
|
117 |
||
118 |
left:left right:right top:top bottom:bottom |
|
119 |
"create and return a new Rectangle giving left, top, right and bottom coordinates" |
|
120 |
||
121 |
^ (self basicNew) left:left right:right top:top bottom:bottom |
|
122 |
! |
|
123 |
||
1356 | 124 |
left:left top:top extent:extent |
125 |
"create and return a new Rectangle giving left, top, and |
|
126 |
an extent point." |
|
127 |
||
128 |
^ (self basicNew) left:left top:top extent:extent |
|
129 |
||
130 |
"Created: 8.5.1996 / 20:56:29 / cg" |
|
131 |
! |
|
132 |
||
637 | 133 |
left:left top:top right:right bottom:bottom |
134 |
"create and return a new Rectangle giving left, top, right and bottom coordinates" |
|
135 |
||
136 |
^ (self basicNew) left:left top:top right:right bottom:bottom |
|
137 |
! |
|
138 |
||
139 |
left:left top:top width:w height:h |
|
140 |
"create and return a new Rectangle giving left and top coordinates |
|
141 |
and width, height" |
|
142 |
||
143 |
%{ /* NOCONTEXT */ |
|
144 |
REGISTER OBJ newRect; |
|
145 |
OBJ t; |
|
146 |
int spc; |
|
147 |
||
2894 | 148 |
if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) { /* OBJECT ALLOCATION */ |
637 | 149 |
if (self == Rectangle) { |
835 | 150 |
/* |
151 |
* short cut - rectangles are created so often ... |
|
152 |
*/ |
|
153 |
__qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ)); |
|
637 | 154 |
|
1133 | 155 |
__InstPtr(newRect)->o_class = Rectangle; |
156 |
__InstPtr(newRect)->i_instvars[0] = left; |
|
157 |
__InstPtr(newRect)->i_instvars[1] = top; |
|
158 |
__InstPtr(newRect)->i_instvars[2] = w; |
|
159 |
__InstPtr(newRect)->i_instvars[3] = h; |
|
637 | 160 |
|
161 |
if (! (__bothSmallInteger(left, top) && |
|
162 |
__bothSmallInteger(w, h))) { |
|
163 |
spc = __qSpace(newRect); |
|
164 |
__STORE_SPC(newRect, left, spc); |
|
165 |
__STORE_SPC(newRect, top, spc); |
|
166 |
__STORE_SPC(newRect, w, spc); |
|
167 |
__STORE_SPC(newRect, h, spc); |
|
168 |
} |
|
169 |
||
170 |
RETURN ( newRect ); |
|
171 |
} |
|
172 |
} |
|
1507 | 173 |
%}. |
637 | 174 |
^ (self basicNew) left:left top:top width:w height:h |
175 |
! |
|
176 |
||
1 | 177 |
origin:origin corner:corner |
178 |
"create and return a new Rectangle giving top-left and bottom-right points" |
|
179 |
||
180 |
^ (self basicNew) origin:origin corner:corner |
|
181 |
! |
|
182 |
||
183 |
origin:origin extent:extent |
|
184 |
"create and return a new Rectangle giving top-left point and extent point" |
|
185 |
||
186 |
%{ /* NOCONTEXT */ |
|
59 | 187 |
REGISTER OBJ newRect; |
293 | 188 |
OBJ t; |
189 |
int spc; |
|
1 | 190 |
|
2894 | 191 |
if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) { /* OBJECT ALLOCATION */ |
835 | 192 |
/* |
193 |
* short cut - rectangles are created so often ... |
|
194 |
*/ |
|
186 | 195 |
if (self == Rectangle) { |
196 |
if (__isPoint(origin) && __isPoint(extent)) { |
|
835 | 197 |
__qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ)); |
1133 | 198 |
__InstPtr(newRect)->o_class = Rectangle; |
325 | 199 |
spc = __qSpace(newRect); |
59 | 200 |
|
1133 | 201 |
t = __PointInstPtr(origin)->p_x; |
202 |
__InstPtr(newRect)->i_instvars[0] = t; |
|
293 | 203 |
__STORE_SPC(newRect, t, spc); |
204 |
||
1133 | 205 |
t = __PointInstPtr(origin)->p_y; |
206 |
__InstPtr(newRect)->i_instvars[1] = t; |
|
293 | 207 |
__STORE_SPC(newRect, t, spc); |
59 | 208 |
|
1133 | 209 |
t = __PointInstPtr(extent)->p_x; |
210 |
__InstPtr(newRect)->i_instvars[2] = t; |
|
293 | 211 |
__STORE_SPC(newRect, t, spc); |
212 |
||
1133 | 213 |
t = __PointInstPtr(extent)->p_y; |
214 |
__InstPtr(newRect)->i_instvars[3] = t; |
|
293 | 215 |
__STORE_SPC(newRect, t, spc); |
186 | 216 |
RETURN ( newRect ); |
217 |
} |
|
218 |
} |
|
1 | 219 |
} |
1507 | 220 |
%}. |
1 | 221 |
^ (self basicNew) origin:origin extent:extent |
1356 | 222 |
! |
223 |
||
224 |
origin:origin width:w height:h |
|
225 |
"create and return a new Rectangle giving top-left and extent |
|
226 |
as individual width/height" |
|
227 |
||
228 |
^ (self basicNew) origin:origin width:w height:h |
|
229 |
||
230 |
"Created: 8.5.1996 / 20:55:53 / cg" |
|
2372
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
231 |
! |
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
232 |
|
3239
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
233 |
vertex:vertex1Point vertex:vertex2Point |
2372
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
234 |
"create and return a new instance of the receiver, |
3239
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
235 |
given two diagonally opposite vertices." |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
236 |
|
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
237 |
^ self |
1114c37ca259
faster decodeFromLiteralEncoding
Claus Gittinger <cg@exept.de>
parents:
2894
diff
changeset
|
238 |
origin: (vertex1Point min: vertex2Point) |
2372
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
239 |
corner: (vertex1Point max: vertex2Point) |
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
240 |
|
9a98e1acd063
added #vertex:vertex: - ST-80 compatibility.
Claus Gittinger <cg@exept.de>
parents:
2274
diff
changeset
|
241 |
"Created: 10.2.1997 / 12:14:32 / cg" |
1 | 242 |
! ! |
243 |
||
244 |
!Rectangle methodsFor:'accessing'! |
|
245 |
||
637 | 246 |
area |
247 |
"return the area |
|
248 |
- for screen Rectangles this is the number of pixels" |
|
249 |
||
250 |
^ width * height |
|
251 |
! |
|
252 |
||
253 |
bottom |
|
254 |
"return the y coordinate of the bottom" |
|
255 |
||
256 |
^ (top + height) |
|
257 |
! |
|
258 |
||
259 |
bottom:aNumber |
|
4860 | 260 |
"set the bottom edge - warning: destructive" |
637 | 261 |
|
262 |
height := aNumber - top |
|
263 |
! |
|
264 |
||
265 |
bottomCenter |
|
266 |
"return the bottom center point" |
|
267 |
||
1453
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
268 |
^ (left + (width / 2)) @ (top + height) |
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
269 |
|
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
270 |
"Modified: 4.6.1996 / 16:04:08 / cg" |
637 | 271 |
! |
272 |
||
273 |
bottomLeft |
|
274 |
"return the bottom-left point" |
|
275 |
||
276 |
^ left @ (top + height) |
|
277 |
! |
|
278 |
||
279 |
bottomRight |
|
280 |
"return the bottom-right point" |
|
281 |
||
282 |
^ (left + width) @ (top + height) |
|
283 |
! |
|
284 |
||
285 |
center |
|
286 |
"return the point in the center of the receiver" |
|
287 |
||
1453
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
288 |
^ (left + (width / 2)) @ (top + (height / 2)) |
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
289 |
|
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
290 |
"Modified: 4.6.1996 / 16:03:53 / cg" |
637 | 291 |
! |
292 |
||
293 |
corner |
|
294 |
"return the corner" |
|
295 |
||
296 |
^ (left + width) @ (top + height) |
|
297 |
! |
|
298 |
||
299 |
corner:aPoint |
|
4860 | 300 |
"set the bottom-right corner - warning: destructive" |
637 | 301 |
|
302 |
width := aPoint x - left. |
|
303 |
height := aPoint y - top |
|
304 |
! |
|
305 |
||
306 |
extent |
|
307 |
"return the extent" |
|
308 |
||
309 |
^ width @ height |
|
310 |
! |
|
311 |
||
312 |
extent:aPoint |
|
313 |
"set the extent from the argument, aPoint with width taken from aPoint x |
|
4860 | 314 |
and height taken from aPoint y. |
315 |
warning: destructive" |
|
637 | 316 |
|
317 |
width := aPoint x. |
|
318 |
height := aPoint y |
|
319 |
! |
|
320 |
||
321 |
height |
|
322 |
"return the height of the rectangle" |
|
323 |
||
324 |
^ height |
|
325 |
! |
|
326 |
||
2441 | 327 |
height:aNumber |
328 |
"change the height of the rectangle. |
|
4860 | 329 |
logically, this changes the corner to get the given height. |
330 |
warning: destructive" |
|
2441 | 331 |
|
332 |
height := aNumber |
|
333 |
||
334 |
"Created: 3.3.1997 / 16:33:22 / cg" |
|
335 |
! |
|
336 |
||
637 | 337 |
left |
338 |
"return the x-coordinate of the top-left origin" |
|
339 |
||
340 |
^ left |
|
341 |
! |
|
342 |
||
343 |
left:aNumber |
|
4860 | 344 |
"set the left edge - warning: destructive" |
637 | 345 |
|
346 |
width := width + (left - aNumber). |
|
347 |
left := aNumber |
|
348 |
! |
|
349 |
||
1 | 350 |
left:newLeft right:right top:newTop bottom:bottom |
4860 | 351 |
"set the rectangle given left, top, right and bottom coordinates. |
352 |
warning: destructive" |
|
1 | 353 |
|
354 |
left := newLeft. |
|
355 |
top := newTop. |
|
356 |
width := right - left. |
|
357 |
height := bottom - top |
|
358 |
! |
|
359 |
||
1356 | 360 |
left:newLeft top:newTop extent:extent |
4860 | 361 |
"set the rectangle given left, top, coordinates and an extent. |
362 |
warning: destructive" |
|
1356 | 363 |
|
364 |
left := newLeft. |
|
365 |
top := newTop. |
|
366 |
width := extent x. |
|
367 |
height := extent y |
|
368 |
||
369 |
"Created: 8.5.1996 / 20:55:10 / cg" |
|
370 |
! |
|
371 |
||
1 | 372 |
left:newLeft top:newTop right:right bottom:bottom |
4860 | 373 |
"set the rectangle given left, top, right and bottom coordinates. |
374 |
warning: destructive" |
|
1 | 375 |
|
376 |
left := newLeft. |
|
377 |
top := newTop. |
|
378 |
width := right - left. |
|
379 |
height := bottom - top |
|
380 |
! |
|
381 |
||
382 |
left:newLeft top:newTop width:newWidth height:newHeight |
|
4860 | 383 |
"set the rectangle given left, top coordinates and width, height. |
384 |
warning: destructive" |
|
1 | 385 |
|
386 |
left := newLeft. |
|
387 |
top := newTop. |
|
388 |
width := newWidth. |
|
389 |
height := newHeight |
|
390 |
! |
|
391 |
||
637 | 392 |
leftCenter |
393 |
"return the left center point" |
|
394 |
||
1453
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
395 |
^ left @ (top + (height / 2)) |
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
396 |
|
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
397 |
"Modified: 4.6.1996 / 16:04:01 / cg" |
637 | 398 |
! |
399 |
||
400 |
origin |
|
401 |
"return the origin" |
|
402 |
||
403 |
^ left @ top |
|
404 |
! |
|
405 |
||
1 | 406 |
origin:aPoint |
4860 | 407 |
"set the top-left origin. The corner remains unchanged. |
408 |
warning: destructive" |
|
77 | 409 |
|
410 |
|newTop newLeft| |
|
1 | 411 |
|
77 | 412 |
newTop := aPoint y. |
413 |
newLeft := aPoint x. |
|
414 |
height := height + (top - newTop). |
|
415 |
width := width + (left - newLeft). |
|
416 |
left := newLeft. |
|
417 |
top := newTop |
|
1 | 418 |
! |
419 |
||
637 | 420 |
origin:origin corner:corner |
4860 | 421 |
"set both origin and corner - warning: destructive" |
637 | 422 |
|
423 |
left := origin x. |
|
424 |
top := origin y. |
|
425 |
width := corner x - left. |
|
426 |
height := corner y - top |
|
427 |
! |
|
428 |
||
429 |
origin:origin extent:extent |
|
4860 | 430 |
"set both origin and extent - warning: destructive" |
637 | 431 |
|
432 |
left := origin x. |
|
433 |
top := origin y. |
|
434 |
width := extent x. |
|
435 |
height := extent y |
|
436 |
! |
|
1 | 437 |
|
1356 | 438 |
origin:origin width:w height:h |
439 |
"set both origin and extent; |
|
4860 | 440 |
the extent is given as individual width and height. |
441 |
warning: destructive" |
|
1356 | 442 |
|
443 |
left := origin x. |
|
444 |
top := origin y. |
|
445 |
width := w. |
|
446 |
height := h |
|
447 |
||
448 |
"Created: 8.5.1996 / 20:53:53 / cg" |
|
449 |
! |
|
450 |
||
637 | 451 |
right |
452 |
"return the x coordinate of the right" |
|
453 |
||
454 |
^ (left + width) |
|
455 |
! |
|
456 |
||
457 |
right:aNumber |
|
4860 | 458 |
"set the right edge - warning: destructive" |
637 | 459 |
|
460 |
width := aNumber - left |
|
461 |
! |
|
462 |
||
463 |
rightCenter |
|
464 |
"return the right center point" |
|
465 |
||
1453
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
466 |
^ (left + width) @ (top + (height / 2)) |
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
467 |
|
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
468 |
"Modified: 4.6.1996 / 16:09:05 / cg" |
637 | 469 |
! |
470 |
||
3269 | 471 |
setLeft:newLeft |
4860 | 472 |
"set left without adjusting width - warning: destructive" |
3269 | 473 |
|
474 |
left := newLeft. |
|
475 |
||
476 |
"Modified: / 22.1.1998 / 09:40:35 / av" |
|
477 |
"Created: / 3.2.1998 / 19:01:06 / cg" |
|
478 |
! |
|
479 |
||
4860 | 480 |
setOrigin:newOrigin corner:newCorner |
481 |
"set the rectangles dimensions - warning: destructive" |
|
482 |
||
483 |
self origin:newOrigin corner:newCorner |
|
484 |
! |
|
485 |
||
3269 | 486 |
setTop:newTop |
4860 | 487 |
"set top without adjusting height - warning: destructive" |
3269 | 488 |
|
489 |
top := newTop. |
|
490 |
||
491 |
"Modified: / 20.1.1998 / 18:25:35 / av" |
|
492 |
"Created: / 3.2.1998 / 19:01:01 / cg" |
|
493 |
! |
|
494 |
||
637 | 495 |
top |
496 |
"return the y-coordinate of the top-left" |
|
497 |
||
498 |
^ top |
|
1 | 499 |
! |
500 |
||
501 |
top:aNumber |
|
4860 | 502 |
"set the top edge - warning: destructive" |
1 | 503 |
|
504 |
height := height + (top - aNumber). |
|
505 |
top := aNumber |
|
506 |
! |
|
507 |
||
637 | 508 |
topCenter |
509 |
"return the top center point" |
|
1 | 510 |
|
1453
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
511 |
^ (left + (width / 2)) @ top |
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
512 |
|
eb73ecdb25ab
center methods should not use //
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
513 |
"Modified: 4.6.1996 / 16:09:09 / cg" |
1 | 514 |
! |
515 |
||
637 | 516 |
topLeft |
517 |
"return the top-left point - the same as origin" |
|
77 | 518 |
|
637 | 519 |
^ left @ top |
77 | 520 |
! |
521 |
||
522 |
topLeft:aPoint |
|
523 |
"Set the top and left edges. |
|
4860 | 524 |
The bottom right remains unchanged. |
525 |
warning: destructive" |
|
77 | 526 |
|
527 |
|newTop| |
|
528 |
||
529 |
newTop := aPoint y. |
|
530 |
height := height + (top - newTop). |
|
531 |
top := newTop. |
|
532 |
width := aPoint x - left |
|
533 |
! |
|
534 |
||
637 | 535 |
topRight |
536 |
"return the top-right point" |
|
537 |
||
538 |
^ (left + width) @ top |
|
539 |
! |
|
540 |
||
77 | 541 |
topRight:aPoint |
542 |
"Set the top and right edges. |
|
4860 | 543 |
The bottom left remains unchanged. |
544 |
warning: destructive" |
|
77 | 545 |
|
546 |
|newTop| |
|
547 |
||
548 |
newTop := aPoint y. |
|
549 |
height := height + (top - newTop). |
|
550 |
top := newTop. |
|
551 |
width := aPoint x - left |
|
552 |
! |
|
553 |
||
554 |
width |
|
555 |
"return the width of the rectangle" |
|
556 |
||
557 |
^ width |
|
2441 | 558 |
! |
559 |
||
560 |
width:aNumber |
|
561 |
"change the width of the rectangle. |
|
4860 | 562 |
logically, this changes the corner to get the given width. |
563 |
warning: destructive" |
|
2441 | 564 |
|
565 |
width := aNumber |
|
566 |
||
567 |
"Created: 3.3.1997 / 16:33:48 / cg" |
|
1 | 568 |
! ! |
569 |
||
570 |
!Rectangle methodsFor:'comparing'! |
|
571 |
||
572 |
= aRectangle |
|
573 |
"return true, if the argument aRectangle represents the same |
|
574 |
rectangle as the receiver" |
|
575 |
||
576 |
%{ /* NOCONTEXT */ |
|
59 | 577 |
/* |
1151 | 578 |
* because rectangles are often compared in the graphics code, |
59 | 579 |
* handle the common case quickly |
580 |
*/ |
|
329 | 581 |
if (__isNonNilObject(aRectangle) |
582 |
&& __qClass(aRectangle) == Rectangle) { |
|
1133 | 583 |
if ((__InstPtr(self)->i_instvars[0] == __InstPtr(aRectangle)->i_instvars[0]) |
584 |
&& (__InstPtr(self)->i_instvars[1] == __InstPtr(aRectangle)->i_instvars[1]) |
|
585 |
&& (__InstPtr(self)->i_instvars[2] == __InstPtr(aRectangle)->i_instvars[2]) |
|
586 |
&& (__InstPtr(self)->i_instvars[3] == __InstPtr(aRectangle)->i_instvars[3])) { |
|
186 | 587 |
RETURN ( true ); |
588 |
} |
|
1133 | 589 |
if (__bothSmallInteger(__InstPtr(self)->i_instvars[0], __InstPtr(aRectangle)->i_instvars[0]) |
590 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[1], __InstPtr(aRectangle)->i_instvars[1]) |
|
591 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[2], __InstPtr(aRectangle)->i_instvars[2]) |
|
592 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[3], __InstPtr(aRectangle)->i_instvars[3])) { |
|
325 | 593 |
RETURN ( false ); |
594 |
} |
|
1 | 595 |
} |
1151 | 596 |
%}. |
259 | 597 |
(aRectangle species ~~ self species) ifTrue:[^ false]. |
1 | 598 |
|
599 |
left = aRectangle left ifFalse:[^ false]. |
|
600 |
top = aRectangle top ifFalse:[^ false]. |
|
601 |
width = aRectangle width ifFalse:[^ false]. |
|
602 |
height = aRectangle height ifFalse:[^ false]. |
|
603 |
^ true |
|
59 | 604 |
! |
605 |
||
606 |
hash |
|
607 |
"return an integer useful for hashing - |
|
608 |
redefined since = is redefined here" |
|
609 |
||
610 |
^ ((left hash bitShift:16) bitXor:(top hash bitShift:16)) |
|
611 |
+ ((width hash) bitXor:(height hash)) |
|
1 | 612 |
! ! |
613 |
||
356 | 614 |
!Rectangle methodsFor:'converting'! |
615 |
||
616 |
asFractionalLayout |
|
617 |
"return a layoutFrame in which fractions (top, left, bottom, right) |
|
618 |
are taken from corresponding edges of the receiver. |
|
619 |
You have to make certain that those are in 0..1." |
|
620 |
||
621 |
|l| |
|
622 |
||
623 |
l := LayoutFrame new. |
|
624 |
l |
|
625 |
leftFraction:(self left); |
|
626 |
rightFraction:(self right); |
|
627 |
topFraction:(self top); |
|
628 |
bottomFraction:(self bottom). |
|
629 |
^ l |
|
630 |
||
631 |
" |
|
632 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
633 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
634 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
635 |
" |
|
636 |
! |
|
637 |
||
638 |
asLayout |
|
639 |
"return a layoutFrame in which offsets (top, left, bottom, right) |
|
640 |
are taken from corresponding edges of the receiver. |
|
1151 | 641 |
If all values are between 0.0 .. 1.0, a fractionalLayout is created, |
356 | 642 |
otherwise, an offsetLayout" |
643 |
||
1454 | 644 |
|newLayout l r t b| |
356 | 645 |
|
1151 | 646 |
newLayout := LayoutFrame new. |
1454 | 647 |
l := left. |
648 |
r := (self right). |
|
649 |
t := top. |
|
650 |
b := (self bottom). |
|
651 |
((l between:0.0 and:1.0) |
|
652 |
and:[(r between:0.0 and:1.0) |
|
653 |
and:[(t between:0.0 and:1.0) |
|
654 |
and:[(b between:0.0 and:1.0)]]]) ifTrue:[ |
|
655 |
newLayout |
|
656 |
leftFraction:l; |
|
657 |
rightFraction:r; |
|
658 |
topFraction:t; |
|
659 |
bottomFraction:b. |
|
356 | 660 |
] ifFalse:[ |
1454 | 661 |
newLayout |
662 |
leftOffset:l; |
|
663 |
rightFraction:0 offset:r; |
|
664 |
topOffset:t; |
|
665 |
bottomFraction:0 offset:b. |
|
356 | 666 |
]. |
1151 | 667 |
^ newLayout |
356 | 668 |
|
669 |
" |
|
670 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
671 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
672 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
673 |
(0@0 corner:1@1) asLayout |
|
674 |
(0@0 corner:1@1) asFractionalLayout |
|
675 |
(0@0 corner:1@1) asOffsetLayout |
|
676 |
" |
|
1454 | 677 |
|
678 |
"Modified: 5.6.1996 / 00:45:46 / cg" |
|
356 | 679 |
! |
680 |
||
637 | 681 |
asOffsetLayout |
682 |
"return a layoutFrame in which offsets (top, left, bottom, right) |
|
683 |
are taken from corresponding edges of the receiver. |
|
684 |
You have to make certain that those are in 0..1." |
|
685 |
||
1151 | 686 |
|newLayout| |
637 | 687 |
|
1151 | 688 |
newLayout := LayoutFrame new. |
689 |
newLayout |
|
637 | 690 |
leftOffset:(self left); |
691 |
rightFraction:0 offset:(self right); |
|
692 |
topOffset:(self top); |
|
693 |
bottomFraction:0 offset:(self bottom). |
|
1151 | 694 |
^ newLayout |
637 | 695 |
|
696 |
" |
|
697 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
698 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
699 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
700 |
||
701 |
(10@10 corner:20@20) asFractionalLayout |
|
702 |
(10@10 corner:20@20) asOffsetLayout |
|
703 |
(10@10 corner:20@20) asLayout |
|
704 |
" |
|
705 |
||
706 |
! |
|
707 |
||
356 | 708 |
asPointArray |
709 |
"return an array containing my corners (clockwise) and |
|
710 |
the origin again as 5th element. Can be used to convert |
|
711 |
a rectangle into a polygon." |
|
712 |
||
713 |
|org| |
|
714 |
||
715 |
^ Array with:(org := self origin) |
|
716 |
with:self topRight |
|
717 |
with:self corner |
|
718 |
with:self bottomLeft |
|
719 |
with:org |
|
720 |
||
721 |
" |
|
722 |
(10@10 corner:100@100) asPointArray |
|
723 |
" |
|
724 |
! |
|
725 |
||
1354 | 726 |
asPolygon |
727 |
"return a polygon from the receiver" |
|
728 |
||
729 |
^ Polygon vertices:self asPointArray |
|
730 |
||
731 |
" |
|
732 |
(10@10 corner:100@100) asPolygon |
|
733 |
" |
|
734 |
||
735 |
"Modified: 8.5.1996 / 20:14:44 / cg" |
|
736 |
! |
|
737 |
||
637 | 738 |
fromLiteralArrayEncoding:encoding |
739 |
"read my values from an encoding. |
|
740 |
The encoding is supposed to be of the form: (Rectangle orgX orgY cornX cornY)" |
|
356 | 741 |
|
637 | 742 |
left := encoding at:2. |
743 |
top := encoding at:3. |
|
744 |
width := (encoding at:4) - left. |
|
745 |
height := (encoding at:5) - top |
|
746 |
||
356 | 747 |
|
748 |
" |
|
637 | 749 |
Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) |
356 | 750 |
" |
379 | 751 |
! |
752 |
||
421 | 753 |
literalArrayEncoding |
1245 | 754 |
"encode myself as an array, from which a copy of the receiver |
755 |
can be reconstructed with #decodeAsLiteralArray. |
|
421 | 756 |
The encoding is: (Rectangle orgX orgY cornX cornY)" |
757 |
||
758 |
^ Array |
|
1245 | 759 |
with:#Rectangle |
760 |
with:left |
|
761 |
with:top |
|
2426 | 762 |
with:(left + width) |
763 |
with:(top + height) |
|
421 | 764 |
|
765 |
||
766 |
" |
|
767 |
Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) |
|
768 |
(100@200 corner:300@500) literalArrayEncoding |
|
769 |
" |
|
770 |
||
771 |
"Modified: 1.9.1995 / 02:16:54 / claus" |
|
1245 | 772 |
"Modified: 22.4.1996 / 13:00:36 / cg" |
421 | 773 |
! |
774 |
||
3488
6e1feb9ead68
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
3269
diff
changeset
|
775 |
rectangleRelativeTo:aRectangle preferred:prefRectHolder |
637 | 776 |
"compute a displayRectangle, treating the receiver like a |
1454 | 777 |
layoutFrame. |
778 |
This allows rectangles to be used interchangable with Layouts." |
|
379 | 779 |
|
3488
6e1feb9ead68
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
3269
diff
changeset
|
780 |
^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRectHolder |
379 | 781 |
|
782 |
" |
|
637 | 783 |
(10@20 corner:20@30) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
784 |
||
785 |
(0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
|
379 | 786 |
" |
1454 | 787 |
|
3488
6e1feb9ead68
prefRect may now be a valueHolder or block
Claus Gittinger <cg@exept.de>
parents:
3269
diff
changeset
|
788 |
"Modified: / 27.5.1998 / 10:20:20 / cg" |
356 | 789 |
! ! |
790 |
||
186 | 791 |
!Rectangle methodsFor:'destructive rectangle operations'! |
792 |
||
356 | 793 |
expandBy:delta |
794 |
"destructively expanded the receiver in all directions |
|
795 |
by amount, a Point, Rectangle or Number. |
|
796 |
Warning: this is a destructive operation, modifying the receiver |
|
797 |
NOT returning a copy. You have to be certain to be the exclusive |
|
798 |
owner of the receiver to avoid side effects. See also: #expandedBy:" |
|
799 |
||
800 |
|amountPoint deltaLeft deltaTop deltaWidth deltaHeight| |
|
801 |
||
802 |
delta isNumber ifTrue:[ |
|
803 |
deltaLeft := deltaTop := delta. |
|
804 |
deltaWidth := deltaHeight := delta * 2. |
|
805 |
] ifFalse:[ |
|
806 |
delta isRectangle ifTrue:[ |
|
807 |
deltaLeft := delta left. |
|
808 |
deltaTop := delta top. |
|
809 |
deltaWidth := deltaLeft + delta right. |
|
810 |
deltaHeight := deltaTop + delta bottom |
|
811 |
] ifFalse:[ |
|
812 |
amountPoint := delta asPoint. |
|
813 |
deltaLeft := amountPoint x. |
|
814 |
deltaTop := amountPoint y. |
|
815 |
deltaWidth := deltaLeft * 2. |
|
816 |
deltaHeight := deltaTop * 2. |
|
817 |
] |
|
818 |
]. |
|
819 |
||
820 |
left := (left - deltaLeft). |
|
821 |
top := (top - deltaTop). |
|
822 |
width := (width + deltaWidth). |
|
823 |
height := (height + deltaHeight). |
|
824 |
||
825 |
" |
|
826 |
|r| |
|
827 |
r := Rectangle origin:10@10 corner:100@100. |
|
828 |
r expandBy:5. |
|
829 |
||
830 |
r := Rectangle origin:10@10 corner:100@100. |
|
831 |
r expandBy:(5 @ 0). |
|
832 |
||
833 |
r := Rectangle origin:10@10 corner:100@100. |
|
834 |
r expandBy:(10 @ 10). |
|
835 |
||
836 |
r := Rectangle origin:10@10 corner:100@100. |
|
837 |
r expandBy:( 10@10 corner:20@20 ) |
|
838 |
" |
|
637 | 839 |
! |
840 |
||
841 |
moveBy:aPoint |
|
842 |
"destructively translate the rectangle by some distance. |
|
843 |
sorry for the name inconsistency - but GNU-ST named it that way" |
|
844 |
||
845 |
left := left + aPoint x. |
|
846 |
top := top + aPoint y |
|
847 |
! |
|
848 |
||
849 |
moveTo:aPoint |
|
850 |
"destructively translate the rectangle to have its origin at aPoint." |
|
851 |
||
852 |
|diff| |
|
853 |
||
854 |
diff := aPoint - self origin. |
|
855 |
self origin:aPoint corner:self corner + diff |
|
856 |
! |
|
857 |
||
858 |
scaleBy:scale |
|
859 |
"scale the receiver rectangle by scale (a Number or Point). |
|
860 |
This is destructive (modifies the receiver, not a copy) and |
|
861 |
should only be used if you know, that you are the exclusive owner |
|
862 |
of the receiver. (use scaledBy if in doubt)" |
|
863 |
||
864 |
|scalePoint sx sy| |
|
865 |
||
866 |
(scale isMemberOf:Point) ifTrue:[ "type hint to stc" |
|
867 |
sx := scale x. |
|
868 |
sy := scale y |
|
869 |
] ifFalse:[ |
|
870 |
scalePoint := scale asPoint. |
|
871 |
sx := scalePoint x. |
|
872 |
sy := scalePoint y |
|
873 |
]. |
|
874 |
width := width * sx. |
|
875 |
height := height * sy. |
|
876 |
left := left * sx. |
|
877 |
top := top * sy |
|
878 |
||
879 |
" |
|
880 |
(Rectangle origin:10@10 corner:50@50) scaleBy:2 |
|
881 |
" |
|
882 |
||
883 |
"its destructive:" |
|
884 |
" |
|
885 |
|r1 r2| |
|
886 |
||
887 |
r1 := Rectangle origin:10@10 corner:50@50. |
|
888 |
r2 := r1 scaleBy:2. |
|
889 |
r1 |
|
890 |
" |
|
891 |
! |
|
892 |
||
893 |
translateBy:amount |
|
894 |
"translate (i.e. move) the receiver rectangle |
|
895 |
by amount, a Point or Number. |
|
896 |
This is destructive (modifies the receiver, not a copy) and |
|
897 |
should only be used if you know, that you are the exclusive owner |
|
898 |
of the receiver. (use translatedBy if in doubt)" |
|
899 |
||
900 |
|amountPoint| |
|
901 |
||
902 |
(amount isMemberOf:Point) ifTrue:[ "type hint to stc" |
|
903 |
left := left + amount x. |
|
904 |
top := top + amount y |
|
905 |
] ifFalse:[ |
|
906 |
amountPoint := amount asPoint. |
|
907 |
left := left + amountPoint x. |
|
908 |
top := top + amountPoint y |
|
909 |
] |
|
910 |
||
911 |
" |
|
912 |
(Rectangle origin:10@10 corner:50@50) translateBy:10 |
|
913 |
" |
|
914 |
||
915 |
"its destructive:" |
|
916 |
" |
|
917 |
|r1 r2| |
|
918 |
||
919 |
r1 := Rectangle origin:10@10 corner:50@50. |
|
920 |
r2 := r1 translateBy:10. |
|
921 |
r1 |
|
922 |
" |
|
923 |
! ! |
|
924 |
||
925 |
!Rectangle methodsFor:'displaying'! |
|
926 |
||
927 |
displayFilledOn:aGC |
|
1314 | 928 |
"display a filled rectangle as represented by the receiver in |
929 |
the graphicsContext, aGC" |
|
930 |
||
637 | 931 |
aGC fillRectangleX:left y:top width:width height:height |
932 |
||
933 |
" |
|
934 |
|v| |
|
935 |
||
1349
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
936 |
v := View new openAndWait. |
637 | 937 |
|
938 |
(Rectangle origin:10@10 corner:50@50) displayFilledOn:v |
|
939 |
" |
|
1314 | 940 |
|
1349
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
941 |
"Modified: 8.5.1996 / 14:40:42 / cg" |
637 | 942 |
! |
943 |
||
944 |
displayStrokedOn:aGC |
|
1314 | 945 |
"display an unfilled rectangle as represented by the receiver in |
946 |
the graphicsContext, aGC" |
|
947 |
||
637 | 948 |
aGC displayRectangleX:left y:top width:width height:height |
949 |
||
950 |
" |
|
951 |
|v| |
|
952 |
||
1349
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
953 |
v := View new openAndWait. |
637 | 954 |
|
955 |
(Rectangle origin:10@10 corner:50@50) displayStrokedOn:v |
|
956 |
" |
|
1314 | 957 |
|
1349
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
958 |
"Modified: 8.5.1996 / 14:40:53 / cg" |
637 | 959 |
! ! |
960 |
||
961 |
!Rectangle methodsFor:'printing & storing'! |
|
962 |
||
963 |
printOn:aStream |
|
964 |
"print the receiver on aStream" |
|
965 |
||
966 |
aStream nextPutAll:(self class name). |
|
967 |
aStream nextPutAll:' origin:'. |
|
968 |
(self origin) printOn:aStream. |
|
1443 | 969 |
aStream nextPutAll:' extent:'. |
970 |
(self extent) printOn:aStream |
|
971 |
||
972 |
"Modified: 29.5.1996 / 00:17:39 / cg" |
|
637 | 973 |
! |
974 |
||
975 |
storeOn:aStream |
|
976 |
"store the receiver on aStream; i.e. print an expression which will |
|
977 |
reconstruct the receiver" |
|
978 |
||
979 |
aStream nextPut:$(. |
|
980 |
aStream nextPutAll:(self class name). |
|
981 |
aStream nextPutAll:' origin:'. |
|
982 |
(self origin) storeOn:aStream. |
|
1443 | 983 |
aStream nextPutAll:' extent:'. |
984 |
(self extent) storeOn:aStream. |
|
637 | 985 |
aStream nextPut:$) |
1443 | 986 |
|
987 |
"Modified: 29.5.1996 / 00:17:42 / cg" |
|
637 | 988 |
! ! |
989 |
||
990 |
!Rectangle methodsFor:'queries'! |
|
991 |
||
1349
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
992 |
bounds |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
993 |
"return the smallest enclosing rectangle" |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
994 |
|
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
995 |
^ self |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
996 |
|
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
997 |
"Created: 8.5.1996 / 13:56:24 / cg" |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
998 |
"Modified: 8.5.1996 / 14:06:38 / cg" |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
999 |
! |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1000 |
|
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1001 |
canBeFilled |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1002 |
"return true, if the receiver can be drawn as a filled geometric. |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1003 |
Always true here." |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1004 |
|
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1005 |
^ true |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1006 |
|
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1007 |
"Created: 8.5.1996 / 08:16:47 / cg" |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1008 |
! |
275388fd5271
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
1314
diff
changeset
|
1009 |
|
2381
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1010 |
computeBounds |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1011 |
"return the smallest enclosing rectangle" |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1012 |
|
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1013 |
^ self |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1014 |
|
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1015 |
"Modified: 8.5.1996 / 14:06:38 / cg" |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1016 |
"Created: 12.2.1997 / 11:44:45 / cg" |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1017 |
! |
10af98758a49
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
2373
diff
changeset
|
1018 |
|
637 | 1019 |
isRectangle |
1020 |
"return true, if the receiver is some kind of rectangle" |
|
1021 |
||
1022 |
^ true |
|
186 | 1023 |
! ! |
1024 |
||
1 | 1025 |
!Rectangle methodsFor:'rectangle operations'! |
1026 |
||
1027 |
+ aPoint |
|
356 | 1028 |
"return a new rectangle with same extent as receiver but |
1 | 1029 |
origin translated by the argument, aPoint" |
1030 |
||
217 | 1031 |
|amountPoint| |
1032 |
||
2274 | 1033 |
(aPoint isMemberOf:SmallInteger) ifTrue:[ |
1034 |
"/ this is an stc optimization |
|
1035 |
^ Rectangle |
|
2373 | 1036 |
left:(left + aPoint) |
1037 |
top:(top + aPoint) |
|
2274 | 1038 |
width:width |
1039 |
height:height |
|
1040 |
]. |
|
1041 |
||
217 | 1042 |
amountPoint := aPoint asPoint. |
1043 |
^ Rectangle left:(left + amountPoint x) |
|
2274 | 1044 |
top:(top + amountPoint y) |
1045 |
width:width |
|
1046 |
height:height |
|
1047 |
||
1048 |
"Modified: 25.1.1997 / 17:29:53 / cg" |
|
1049 |
! |
|
1050 |
||
1051 |
- aPoint |
|
1052 |
"return a new rectangle with same extent as receiver but |
|
1053 |
origin translated by the argument, aPoint" |
|
1054 |
||
1055 |
|amountPoint| |
|
1056 |
||
1057 |
(aPoint isMemberOf:SmallInteger) ifTrue:[ |
|
1058 |
"/ this is an stc optimization |
|
1059 |
^ Rectangle |
|
2373 | 1060 |
left:(left - aPoint) |
1061 |
top:(top - aPoint) |
|
2274 | 1062 |
width:width |
1063 |
height:height |
|
1064 |
]. |
|
1065 |
||
1066 |
amountPoint := aPoint asPoint. |
|
1067 |
^ Rectangle left:(left - amountPoint x) |
|
1068 |
top:(top - amountPoint y) |
|
1069 |
width:width |
|
1070 |
height:height |
|
1071 |
||
1072 |
"Modified: 25.1.1997 / 17:29:53 / cg" |
|
1073 |
"Created: 25.1.1997 / 17:30:21 / cg" |
|
1 | 1074 |
! |
1075 |
||
326 | 1076 |
align:offset with:someCoordinate |
1077 |
"return a new rectangle which is translated (i.e. moved) |
|
1078 |
such that the point offset in mySelf is placed on someCoordinate." |
|
1079 |
||
1080 |
^ Rectangle origin:(someCoordinate - offset + self origin) |
|
1081 |
extent:(self extent) |
|
1082 |
" |
|
1083 |
|r| |
|
1084 |
||
1085 |
r := Rectangle origin:10@10 corner:50@50. |
|
1086 |
r align:(r center) with:100@100. |
|
1087 |
" |
|
1088 |
! |
|
1089 |
||
1 | 1090 |
amountToTranslateWithin: aRectangle |
1091 |
"for GNU-ST compatibility" |
|
1092 |
||
1093 |
^(aRectangle origin) - self origin |
|
1094 |
! |
|
1095 |
||
1096 |
areasOutside: aRectangle |
|
4863 | 1097 |
"Answer an Array of Rectangles comprising the parts of the receiver not |
1098 |
intersecting aRectangle." |
|
1099 |
||
1100 |
| areas yOrigin yCorner origin corner| |
|
1101 |
||
1102 |
origin := self origin. |
|
1103 |
corner := self corner. |
|
1 | 1104 |
|
4863 | 1105 |
"Make sure the intersection is non-empty" |
1106 |
(origin <= aRectangle corner and: [aRectangle origin <= corner]) |
|
1107 |
ifFalse: [^ Array with: self]. |
|
1108 |
areas := OrderedCollection new. |
|
1109 |
aRectangle origin y > origin y |
|
1110 |
ifTrue: [areas addLast: (origin corner: corner x @ (yOrigin := aRectangle origin y))] |
|
1111 |
ifFalse: [yOrigin := origin y]. |
|
1112 |
aRectangle corner y < corner y |
|
1113 |
ifTrue: [areas addLast: (origin x @ (yCorner := aRectangle corner y) corner: corner)] |
|
1114 |
ifFalse: [yCorner := corner y]. |
|
1115 |
aRectangle origin x > origin x |
|
1116 |
ifTrue: [areas addLast: (origin x @ yOrigin corner: aRectangle origin x @ yCorner)]. |
|
1117 |
aRectangle corner x < corner x |
|
1118 |
ifTrue: [areas addLast: (aRectangle corner x @ yOrigin corner: corner x @ yCorner)]. |
|
1119 |
^areas |
|
1120 |
||
1121 |
"/ cg: the old code below was wrong ... |
|
1124 | 1122 |
|
4863 | 1123 |
"/ "---------------------------------------------------------------- |
1124 |
"/ | added for GNU-ST compatibility |
|
1125 |
"/ | |
|
1126 |
"/ | author: Doug McCallum <uunet!!ico.isc.com!!dougm> |
|
1127 |
"/ | |
|
1128 |
"/ |areasOutside: aRectangle |
|
1129 |
"/ | most complicated of the Rectangle primitives |
|
1130 |
"/ | The basic methodology is to first determine that there is an |
|
1131 |
"/ | intersection by finding the overlapping rectangle. From the |
|
1132 |
"/ | overlapping rectangle, first determine if it runs along an edge. |
|
1133 |
"/ | If it doesn't, extend the rectangle up to the top edge and add |
|
1134 |
"/ | the new rectangle to the collection and start the rest of the |
|
1135 |
"/ | process. If the left edge does not touch the left edge of self, |
|
1136 |
"/ | extend it to the edge saving the new rectangle. Then do the |
|
1137 |
"/ | same to the right edge. Then check top and bottom edges. Most |
|
1138 |
"/ | of the time only 2 or 3 rectangles get formed, occasionally 4. |
|
1139 |
"/ | It should be possible to never get more than 3 but requires more |
|
1140 |
"/ | work. |
|
1141 |
"/ ----------------------------------------------------------------" |
|
1142 |
"/ |
|
1143 |
"/ | collect iRect tmp | |
|
1144 |
"/ |
|
1145 |
"/ iRect := self intersect: aRectangle. |
|
1146 |
"/ iRect isNil ifTrue: [^nil]. "case of no intersection" |
|
1147 |
"/ "the collect collection gathers Rectangles" |
|
1148 |
"/ collect := OrderedCollection new: 4. |
|
1149 |
"/ "is it floating or on the edge?" |
|
1150 |
"/ (((((iRect top) ~= self top) |
|
1151 |
"/ and: [ (iRect bottom) ~= self bottom ]) |
|
1152 |
"/ and: [ (iRect left) ~= self left ]) |
|
1153 |
"/ and: [ (iRect right) ~= self right ] ) |
|
1154 |
"/ ifTrue: "entirely in the center." |
|
1155 |
"/ [tmp := Rectangle origin: (Point x: iRect left y: self top) |
|
1156 |
"/ corner: iRect bottomRight. |
|
1157 |
"/ collect add: tmp. |
|
1158 |
"/ iRect := iRect merge: tmp]. |
|
1159 |
"/ ((iRect left) ~= self left) |
|
1160 |
"/ ifTrue: "doesn't touch left edge so make it touch" |
|
1161 |
"/ [tmp := Rectangle origin: (Point x: self left y: iRect top) |
|
1162 |
"/ corner: iRect bottomLeft. |
|
1163 |
"/ collect add: tmp. |
|
1164 |
"/ "merge new (tmp) with overlap to keep track" |
|
1165 |
"/ iRect := iRect merge: tmp]. |
|
1166 |
"/ ((iRect right) ~= self right) |
|
1167 |
"/ ifTrue: "doesn't touch right edge so extend it" |
|
1168 |
"/ [tmp := Rectangle origin: iRect topRight |
|
1169 |
"/ corner: (Point x: self right y: iRect bottom). |
|
1170 |
"/ collect add: tmp. |
|
1171 |
"/ iRect := iRect merge: tmp]. |
|
1172 |
"/ (((iRect left) ~= self left) or: [(iRect top) ~= self top]) |
|
1173 |
"/ ifTrue: "whole top part can be taken now" |
|
1174 |
"/ [tmp := Rectangle origin: self origin corner: iRect topRight. |
|
1175 |
"/ collect add: tmp]. |
|
1176 |
"/ (((iRect right) ~= self right) or: [(iRect bottom) ~= self bottom]) |
|
1177 |
"/ ifTrue: "whole bottom open and can be taken" |
|
1178 |
"/ [tmp := Rectangle origin: iRect bottomLeft corner: self corner. |
|
1179 |
"/ collect add: tmp]. |
|
1180 |
"/ ^collect |
|
77 | 1181 |
! |
1 | 1182 |
|
4864 | 1183 |
encompass:aPoint |
1184 |
"return a Rectangle that contains both the receiver and aPoint." |
|
1185 |
||
1186 |
^ Rectangle |
|
1187 |
origin: (self origin min: aPoint) |
|
1188 |
corner: (self corner max: aPoint) |
|
1189 |
||
1190 |
! |
|
1191 |
||
637 | 1192 |
expandedBy:delta |
1193 |
"return a new rectangle which is expanded in all directions |
|
1194 |
by amount, a Point, Rectangle or Number" |
|
1195 |
||
1196 |
^ self copy expandBy:delta |
|
1197 |
||
1198 |
" |
|
1199 |
|r| |
|
1200 |
r := Rectangle origin:10@10 corner:100@100. |
|
1201 |
r expandedBy:5. |
|
1202 |
r expandedBy:(5 @ 0). |
|
1203 |
r expandedBy:(10 @ 10). |
|
1204 |
r expandedBy:( 10@10 corner:20@20 ) |
|
1205 |
" |
|
1206 |
! |
|
1207 |
||
1208 |
insetBy: delta |
|
1209 |
"return a new rectangle which is inset in all directions |
|
1210 |
by delta, a Point, Rectangle or Number" |
|
1211 |
||
1212 |
|amountPoint deltaLeft deltaTop deltaWidth deltaHeight| |
|
1213 |
||
1214 |
delta isNumber ifTrue:[ |
|
1215 |
deltaLeft := deltaTop := delta. |
|
1216 |
deltaWidth := deltaHeight := delta * 2. |
|
1217 |
] ifFalse:[ |
|
1218 |
delta isRectangle ifTrue:[ |
|
1219 |
deltaLeft := delta left. |
|
1220 |
deltaTop := delta top. |
|
1221 |
deltaWidth := deltaLeft + delta right. |
|
1222 |
deltaHeight := deltaTop + delta bottom |
|
1223 |
] ifFalse:[ |
|
1224 |
amountPoint := delta asPoint. |
|
1225 |
deltaLeft := amountPoint x. |
|
1226 |
deltaTop := amountPoint y. |
|
1227 |
deltaWidth := deltaLeft * 2. |
|
1228 |
deltaHeight := deltaTop * 2. |
|
1229 |
] |
|
1230 |
]. |
|
1231 |
||
1232 |
^ Rectangle left:(left + deltaLeft) |
|
1233 |
top:(top + deltaTop) |
|
1234 |
width:(width - deltaWidth) |
|
1235 |
height:(height - deltaHeight) |
|
1236 |
" |
|
1237 |
|r| |
|
1238 |
r := Rectangle origin:10@10 corner:100@100. |
|
1239 |
r insetBy:5. |
|
1240 |
r insetBy:(5 @ 0). |
|
1241 |
r insetBy:(10 @ 10). |
|
1242 |
r insetBy:( 10@10 corner:20@20 ) |
|
1243 |
" |
|
1244 |
! |
|
1245 |
||
1246 |
insetOriginBy:originDelta cornerBy:cornerDelta |
|
1247 |
"return a new rectangle which is inset by originDelta |
|
1248 |
and cornerDelta; both may be instances of Point or Number" |
|
1249 |
||
1250 |
^ Rectangle |
|
1251 |
origin:(left @ top) + originDelta asPoint |
|
1252 |
corner:(self corner - cornerDelta asPoint) |
|
1253 |
" |
|
1254 |
|r| |
|
1255 |
r := Rectangle origin:10@10 corner:100@100. |
|
1256 |
r insetOriginBy:5 cornerBy:10. |
|
1257 |
r insetOriginBy:10@5 cornerBy:10. |
|
1258 |
r insetOriginBy:10 cornerBy:10@5. |
|
1259 |
r insetOriginBy:10@10 cornerBy:20@20. |
|
1260 |
" |
|
1261 |
! |
|
1262 |
||
1263 |
intersect:aRectangle |
|
1264 |
"return a new rectangle covering the intersection of the receiver |
|
1265 |
and the argument, aRectangle. |
|
1266 |
the rectangles must intersect for a valid return" |
|
1267 |
||
1268 |
^ Rectangle left:(left max:(aRectangle left)) |
|
1269 |
right:((left + width) min:(aRectangle right)) |
|
1270 |
top:(top max:(aRectangle top)) |
|
1271 |
bottom:((top + height) min:(aRectangle bottom)) |
|
1272 |
||
1273 |
" |
|
1274 |
|r1 r2| |
|
1275 |
||
1276 |
r1 := Rectangle origin:10@10 corner:100@100. |
|
1277 |
r2 := Rectangle origin:50@50 corner:150@75. |
|
1278 |
r1 intersect:r2 |
|
1279 |
" |
|
1280 |
! |
|
1281 |
||
1282 |
merge:aRectangle |
|
1283 |
"return a new rectangle covering both the receiver |
|
1284 |
and the argument, aRectangle" |
|
1285 |
||
1286 |
^ Rectangle left:(left min:(aRectangle left)) |
|
4859 | 1287 |
right:((left + width) max:(aRectangle right)) |
1288 |
top:(top min:(aRectangle top)) |
|
1289 |
bottom:((top + height) max:(aRectangle bottom)) |
|
1290 |
||
1291 |
" |
|
1292 |
(Rectangle origin:10@10 corner:100@100) |
|
1293 |
merge:(Rectangle origin:20@20 corner:110@110) |
|
1294 |
||
1295 |
(Rectangle origin:10@10 corner:100@100) |
|
1296 |
merge:(Rectangle origin:20@20 corner:100@100) |
|
1297 |
" |
|
637 | 1298 |
! |
1299 |
||
77 | 1300 |
nonIntersections:aRectangle |
1301 |
"this is the same as areasOutside: - for ST/V compatibility only" |
|
1302 |
||
1303 |
^ self areasOutside:aRectangle |
|
637 | 1304 |
! |
1305 |
||
4859 | 1306 |
quickMerge: aRectangle |
1307 |
"return the receiver if it encloses the given rectangle, |
|
1308 |
or the merge of the two rectangles if it doesn't. |
|
1309 |
This method is an optimization to reduce extra rectangle creations." |
|
1310 |
||
1311 |
| useRcvr rLeft rTop rRight rBottom Origin rCorner minX maxX minY maxY | |
|
1312 |
||
1313 |
useRcvr := true. |
|
1314 |
rLeft := aRectangle left. |
|
1315 |
rTop := aRectangle top. |
|
1316 |
rRight := aRectangle right. |
|
1317 |
rBottom := aRectangle bottom. |
|
1318 |
minX := rLeft < left ifTrue: [useRcvr := false. rLeft] ifFalse: [left]. |
|
1319 |
maxX := rRight > self right ifTrue: [useRcvr := false. rRight] ifFalse: [self right]. |
|
1320 |
minY := rTop < top ifTrue: [useRcvr := false. rTop] ifFalse: [top]. |
|
1321 |
maxY := rBottom > self bottom ifTrue: [useRcvr := false. rBottom] ifFalse: [self bottom]. |
|
1322 |
||
1323 |
useRcvr ifTrue: [^ self]. |
|
1324 |
^ Rectangle left:minX top:minY right:maxX bottom:maxY. |
|
1325 |
||
1326 |
" |
|
1327 |
(Rectangle origin:10@10 corner:100@100) |
|
1328 |
quickMerge:(Rectangle origin:20@20 corner:110@110) |
|
1329 |
||
1330 |
(Rectangle origin:10@10 corner:100@100) |
|
1331 |
quickMerge:(Rectangle origin:20@20 corner:100@100) |
|
1332 |
" |
|
1333 |
||
1334 |
! |
|
1335 |
||
637 | 1336 |
scaledBy:scale |
1337 |
"return a new rectangle which is the receiver |
|
1338 |
scaled by scale" |
|
1339 |
||
1340 |
|scalePoint sx sy| |
|
356 | 1341 |
|
637 | 1342 |
scalePoint := scale asPoint. |
1343 |
sx := scalePoint x. |
|
1344 |
sy := scalePoint y. |
|
1345 |
^ Rectangle left:left * sx |
|
1346 |
top:top * sy |
|
1347 |
width:(width * sx) |
|
1348 |
height:(height * sy) |
|
356 | 1349 |
" |
637 | 1350 |
(Rectangle origin:10@10 corner:50@50) scaledBy:2 |
1351 |
" |
|
356 | 1352 |
|
637 | 1353 |
"its NOT destructive:" |
1354 |
" |
|
1355 |
|r1 r2| |
|
356 | 1356 |
|
637 | 1357 |
r1 := Rectangle origin:10@10 corner:50@50. |
1358 |
r2 := r1 scaledBy:2. |
|
1359 |
r1 |
|
356 | 1360 |
" |
1361 |
! |
|
1362 |
||
637 | 1363 |
translatedBy:amount |
1364 |
"return a new rectangle which is translated (i.e. moved) |
|
1365 |
by amount, aPoint or Number" |
|
1366 |
||
1367 |
|amountPoint| |
|
356 | 1368 |
|
637 | 1369 |
amountPoint := amount asPoint. |
1370 |
^ Rectangle left:(left + amountPoint x) |
|
1371 |
top:(top + amountPoint y) |
|
1372 |
width:width |
|
1373 |
height:height |
|
356 | 1374 |
" |
637 | 1375 |
(Rectangle origin:10@10 corner:50@50) translatedBy:10 |
1376 |
" |
|
356 | 1377 |
|
637 | 1378 |
"its NOT destructive:" |
1379 |
" |
|
1380 |
|r1 r2| |
|
356 | 1381 |
|
637 | 1382 |
r1 := Rectangle origin:10@10 corner:50@50. |
1383 |
r2 := r1 translatedBy:10. |
|
1384 |
r1 |
|
356 | 1385 |
" |
1386 |
! ! |
|
1387 |
||
637 | 1388 |
!Rectangle methodsFor:'testing'! |
1 | 1389 |
|
637 | 1390 |
contains:aRectangle |
1391 |
"return true, if the argument, aRectangle is equal to or |
|
1392 |
is contained fully within the receiver" |
|
1 | 1393 |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1394 |
%{ /* NOCONTEXT */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1395 |
/* |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1396 |
* claus: this may be often called by objectView |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1397 |
* the primitive code below (although lookung ugly) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1398 |
* speeds that up by almost a factor of 2 ... |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1399 |
*/ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1400 |
OBJ slf = self; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1401 |
OBJ rct = aRectangle; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1402 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1403 |
if (__isNonNilObject(rct) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1404 |
&& __qClass(rct) == Rectangle) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1405 |
OBJ r_l, r_w, r_t, r_h, l, w, t, h; |
2770 | 1406 |
INT r_ir, r_il, r_ib, r_it; |
1407 |
INT il, it, ir, ib, iw, ih; |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1408 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1409 |
r_l = __OINST(rct, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1410 |
l = __OINST(slf, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1411 |
if (__bothSmallInteger(r_l, l)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1412 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
2770 | 1413 |
il = (INT)(l); |
1414 |
r_il = (INT)(r_l); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1415 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1416 |
il = __intVal(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1417 |
r_il = __intVal(r_l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1418 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1419 |
if (il > r_il) { RETURN (false); } /* left > aRectangle left */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1420 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1421 |
r_t = __OINST(rct, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1422 |
t = __OINST(slf, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1423 |
if (__bothSmallInteger(r_t, t)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1424 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
2770 | 1425 |
it = (INT)(t); |
1426 |
r_it = (INT)(r_t); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1427 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1428 |
it = __intVal(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1429 |
r_it = __intVal(r_t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1430 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1431 |
if (it > r_it) { RETURN (false); } /* top > aRectangle top */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1432 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1433 |
r_w = __OINST(rct, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1434 |
w = __OINST(slf, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1435 |
if (__bothSmallInteger(r_w, w)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1436 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
2770 | 1437 |
ir = il + (INT)(w); |
1438 |
r_ir = r_il + (INT)(r_w); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1439 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1440 |
ir = il + __intVal(w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1441 |
r_ir = r_il + __intVal(r_w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1442 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1443 |
if (ir < r_ir) { RETURN (false); } /* (left + width) < aRectangle right */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1444 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1445 |
r_h = __OINST(rct, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1446 |
h = __OINST(slf, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1447 |
if (__bothSmallInteger(r_h, h)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1448 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
2770 | 1449 |
ib = it + (INT)(h); |
1450 |
r_ib = r_it + (INT)(r_h); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1451 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1452 |
ib = it + __intVal(h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1453 |
r_ib = r_it + __intVal(r_h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1454 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1455 |
if (ib < r_ib) { RETURN (false); } /* (top + height) < aRectangle bottom */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1456 |
RETURN (true); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1457 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1458 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1459 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1460 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1461 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1462 |
%}. |
637 | 1463 |
(left <= aRectangle left) ifTrue:[ |
1464 |
((left + width) >= aRectangle right) ifTrue:[ |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1465 |
(top <= aRectangle top) ifTrue:[ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1466 |
((top + height) >= aRectangle bottom) ifTrue:[ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1467 |
^ true |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1468 |
] |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1469 |
] |
637 | 1470 |
] |
1471 |
]. |
|
1472 |
^ false |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1473 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1474 |
" |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1475 |
(0@0 corner:100@100) contains:(10@10 corner:90@90) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1476 |
(0@0 corner:100@100) contains:(10@10 corner:100@100) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1477 |
(0@0 corner:100@100) contains:(10@10 corner:110@100) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1478 |
(0@0 corner:100@100) contains:(10@10 corner:100@110) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1479 |
(10@10 corner:100@100) contains:(0@10 corner:100@100) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1480 |
" |
637 | 1481 |
! |
1482 |
||
1483 |
containsPoint:aPoint |
|
1484 |
"return true, if the argument, aPoint is contained in the receiver" |
|
1485 |
||
1486 |
|px py| |
|
1487 |
||
1488 |
px := aPoint x. |
|
1489 |
(px < left) ifTrue:[^ false]. |
|
1490 |
(px > (left + width)) ifTrue:[^ false]. |
|
1491 |
py := aPoint y. |
|
1492 |
(py < top) ifTrue:[^ false]. |
|
1493 |
(py > (top + height)) ifTrue:[^ false]. |
|
1494 |
^ true |
|
1 | 1495 |
! |
1496 |
||
637 | 1497 |
containsPointX:x y:y |
1498 |
"return true, if the point defined by x@y is contained in the receiver. |
|
1499 |
This is the same as containsPoint:, but can be used if the coordinates |
|
1500 |
are already available as separate numbers to avoid useless creation of a |
|
1501 |
temporary point." |
|
1502 |
||
1503 |
(x < left) ifTrue:[^ false]. |
|
1504 |
(x > (left + width)) ifTrue:[^ false]. |
|
1505 |
(y < top) ifTrue:[^ false]. |
|
1506 |
(y > (top + height)) ifTrue:[^ false]. |
|
1507 |
^ true |
|
1508 |
! |
|
1509 |
||
1510 |
intersects:aRectangle |
|
1511 |
"return true, if the intersection between the argument, aRectangle |
|
1512 |
and the receiver is not empty" |
|
1513 |
||
1514 |
|b r| |
|
1 | 1515 |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1516 |
%{ /* NOCONTEXT */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1517 |
/* |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1518 |
* claus: this is one of the mostly called methods in |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1519 |
* the objectView - the primitive code below (although lookung ugly) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1520 |
* speeds up drawing by almost a factor of 2 ... |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1521 |
*/ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1522 |
OBJ slf = self; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1523 |
OBJ rct = aRectangle; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1524 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1525 |
if (__isNonNilObject(rct) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1526 |
&& __qClass(rct) == Rectangle) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1527 |
OBJ r_l, r_w, r_t, r_h, l, w, t, h; |
2770 | 1528 |
INT r_ir, r_il, r_ib, r_it; |
1529 |
INT il, it, ir, ib, iw, ih; |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1530 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1531 |
r_l = __OINST(rct, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1532 |
r_w = __OINST(rct, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1533 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1534 |
if (__bothSmallInteger(r_l, r_w)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1535 |
r_t = __OINST(rct, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1536 |
r_h = __OINST(rct, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1537 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1538 |
l = __OINST(slf, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1539 |
w = __OINST(slf, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1540 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1541 |
if (__bothSmallInteger(l, w)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1542 |
t = __OINST(slf, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1543 |
h = __OINST(slf, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1544 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1545 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
2770 | 1546 |
r_il = (INT)(r_l); |
1547 |
r_ir = r_il + (INT)(r_w) - 1; |
|
1548 |
il = (INT)(l); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1549 |
if (r_ir < il) { RETURN (false); } |
2770 | 1550 |
ir = il + (INT)(w) - 1; |
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1551 |
if (r_il > ir) { RETURN (false); } |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1552 |
#else /* tag in hi-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1553 |
r_il = __intVal(r_l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1554 |
r_ir = r_il + __intVal(r_w); /* aRectangle right */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1555 |
il = __intVal(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1556 |
if (r_ir < il) { RETURN (false); } /* (aRectangle right) < left */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1557 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1558 |
ir = il + __intVal(w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1559 |
if (r_il > ir) { RETURN (false); } /* (aRectangle left) > r */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1560 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1561 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1562 |
if (__bothSmallInteger(r_t, r_h)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1563 |
if (__bothSmallInteger(t, h)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1564 |
#ifndef POSITIVE_ADDRESSES |
2770 | 1565 |
r_it = (INT)(r_t); |
1566 |
r_ib = r_it + (INT)(r_h) - 1; /* aRectangle bottom */ |
|
1567 |
it = (INT)(t); |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1568 |
if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1569 |
|
2770 | 1570 |
ib = it + (INT)(h) - 1; |
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1571 |
if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1572 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1573 |
r_it = __intVal(r_t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1574 |
r_ib = r_it + __intVal(r_h); /* aRectangle bottom */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1575 |
it = __intVal(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1576 |
if (r_ib < it) { RETURN (false); } /* (aRectangle bottom) < top */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1577 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1578 |
ib = it + __intVal(h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1579 |
if (r_it > ib) { RETURN (false); } /* (aRectangle top) > b */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1580 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1581 |
RETURN (true); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1582 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1583 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1584 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1585 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1586 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1587 |
%}. |
637 | 1588 |
(aRectangle right) < left ifTrue:[^ false]. |
1589 |
(aRectangle bottom) < top ifTrue:[^ false]. |
|
1590 |
r := left + width. |
|
1591 |
(aRectangle left) > r ifTrue:[^ false]. |
|
1592 |
b := top + height. |
|
1593 |
(aRectangle top) > b ifTrue:[^ false]. |
|
1594 |
^ true |
|
1595 |
! |
|
1596 |
||
1597 |
isContainedIn:aRectangle |
|
1598 |
"return true, if the receiver is fully contained within |
|
1599 |
the argument, aRectangle" |
|
1600 |
||
1601 |
(aRectangle left <= left) ifTrue:[ |
|
1602 |
(aRectangle right >= (left + width)) ifTrue:[ |
|
1603 |
(aRectangle top <= top) ifTrue:[ |
|
1604 |
(aRectangle bottom >= (top + height)) ifTrue:[ |
|
1605 |
^ true |
|
1606 |
] |
|
1607 |
] |
|
1608 |
] |
|
1609 |
]. |
|
1610 |
^ false |
|
1 | 1611 |
! ! |
637 | 1612 |
|
4861 | 1613 |
!Rectangle methodsFor:'truncation and rounding'! |
1614 |
||
1615 |
rounded |
|
1616 |
"return a copy of the receiver with rounded coordinates. |
|
1617 |
Return the receiver if its coordinates are already integral." |
|
1618 |
||
1619 |
(left isInteger |
|
1620 |
and:[top isInteger |
|
1621 |
and:[width isInteger |
|
1622 |
and:[height isInteger]]]) |
|
1623 |
ifTrue: [^ self]. |
|
1624 |
||
1625 |
^ Rectangle left:(left rounded) |
|
1626 |
top:(top rounded) |
|
1627 |
width:(width rounded) |
|
1628 |
height:(height rounded) |
|
1629 |
! |
|
1630 |
||
1631 |
truncated |
|
1632 |
"return a Rectangle whose origin and corner have any fractional parts removed. |
|
1633 |
Return the receiver if its coordinates are already integral." |
|
1634 |
||
1635 |
(left isInteger |
|
1636 |
and:[top isInteger |
|
1637 |
and:[width isInteger |
|
1638 |
and:[height isInteger]]]) |
|
1639 |
ifTrue: [^ self]. |
|
1640 |
||
1641 |
^ Rectangle |
|
1642 |
left:left truncated |
|
1643 |
top:top truncated |
|
1644 |
width:width truncated |
|
1645 |
height:height truncated. |
|
1646 |
! ! |
|
1647 |
||
637 | 1648 |
!Rectangle class methodsFor:'documentation'! |
1649 |
||
1650 |
version |
|
4864 | 1651 |
^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.63 1999-10-06 23:45:37 cg Exp $' |
637 | 1652 |
! ! |