author | Claus Gittinger <cg@exept.de> |
Thu, 25 Apr 1996 18:20:46 +0200 | |
changeset 1290 | 15ba3221b89b |
parent 1245 | c8afea3d5af0 |
child 1314 | 18fabbc0e0a6 |
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 |
||
77 | 61 |
" |
62 |
! ! |
|
63 |
||
1 | 64 |
!Rectangle class methodsFor:'instance creation'! |
65 |
||
637 | 66 |
fromUser |
67 |
"let user specify a rectangle on the screen, return it" |
|
68 |
||
69 |
^ Screen current rectangleFromUser |
|
70 |
||
71 |
" |
|
72 |
Rectangle fromUser |
|
73 |
" |
|
74 |
! |
|
75 |
||
76 |
left:left right:right top:top bottom:bottom |
|
77 |
"create and return a new Rectangle giving left, top, right and bottom coordinates" |
|
78 |
||
79 |
^ (self basicNew) left:left right:right top:top bottom:bottom |
|
80 |
! |
|
81 |
||
82 |
left:left top:top right:right bottom:bottom |
|
83 |
"create and return a new Rectangle giving left, top, right and bottom coordinates" |
|
84 |
||
85 |
^ (self basicNew) left:left top:top right:right bottom:bottom |
|
86 |
! |
|
87 |
||
88 |
left:left top:top width:w height:h |
|
89 |
"create and return a new Rectangle giving left and top coordinates |
|
90 |
and width, height" |
|
91 |
||
92 |
%{ /* NOCONTEXT */ |
|
93 |
REGISTER OBJ newRect; |
|
94 |
OBJ t; |
|
95 |
int spc; |
|
96 |
||
835 | 97 |
if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) { |
637 | 98 |
if (self == Rectangle) { |
835 | 99 |
/* |
100 |
* short cut - rectangles are created so often ... |
|
101 |
*/ |
|
102 |
__qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ)); |
|
637 | 103 |
|
1133 | 104 |
__InstPtr(newRect)->o_class = Rectangle; |
105 |
__InstPtr(newRect)->i_instvars[0] = left; |
|
106 |
__InstPtr(newRect)->i_instvars[1] = top; |
|
107 |
__InstPtr(newRect)->i_instvars[2] = w; |
|
108 |
__InstPtr(newRect)->i_instvars[3] = h; |
|
637 | 109 |
|
110 |
if (! (__bothSmallInteger(left, top) && |
|
111 |
__bothSmallInteger(w, h))) { |
|
112 |
spc = __qSpace(newRect); |
|
113 |
__STORE_SPC(newRect, left, spc); |
|
114 |
__STORE_SPC(newRect, top, spc); |
|
115 |
__STORE_SPC(newRect, w, spc); |
|
116 |
__STORE_SPC(newRect, h, spc); |
|
117 |
} |
|
118 |
||
119 |
RETURN ( newRect ); |
|
120 |
} |
|
121 |
} |
|
122 |
%} |
|
123 |
. |
|
124 |
^ (self basicNew) left:left top:top width:w height:h |
|
125 |
! |
|
126 |
||
1 | 127 |
origin:origin corner:corner |
128 |
"create and return a new Rectangle giving top-left and bottom-right points" |
|
129 |
||
130 |
^ (self basicNew) origin:origin corner:corner |
|
131 |
! |
|
132 |
||
133 |
origin:origin extent:extent |
|
134 |
"create and return a new Rectangle giving top-left point and extent point" |
|
135 |
||
136 |
%{ /* NOCONTEXT */ |
|
59 | 137 |
REGISTER OBJ newRect; |
293 | 138 |
OBJ t; |
139 |
int spc; |
|
1 | 140 |
|
835 | 141 |
if (__CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) { |
142 |
/* |
|
143 |
* short cut - rectangles are created so often ... |
|
144 |
*/ |
|
186 | 145 |
if (self == Rectangle) { |
146 |
if (__isPoint(origin) && __isPoint(extent)) { |
|
835 | 147 |
__qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ)); |
1133 | 148 |
__InstPtr(newRect)->o_class = Rectangle; |
325 | 149 |
spc = __qSpace(newRect); |
59 | 150 |
|
1133 | 151 |
t = __PointInstPtr(origin)->p_x; |
152 |
__InstPtr(newRect)->i_instvars[0] = t; |
|
293 | 153 |
__STORE_SPC(newRect, t, spc); |
154 |
||
1133 | 155 |
t = __PointInstPtr(origin)->p_y; |
156 |
__InstPtr(newRect)->i_instvars[1] = t; |
|
293 | 157 |
__STORE_SPC(newRect, t, spc); |
59 | 158 |
|
1133 | 159 |
t = __PointInstPtr(extent)->p_x; |
160 |
__InstPtr(newRect)->i_instvars[2] = t; |
|
293 | 161 |
__STORE_SPC(newRect, t, spc); |
162 |
||
1133 | 163 |
t = __PointInstPtr(extent)->p_y; |
164 |
__InstPtr(newRect)->i_instvars[3] = t; |
|
293 | 165 |
__STORE_SPC(newRect, t, spc); |
186 | 166 |
RETURN ( newRect ); |
167 |
} |
|
168 |
} |
|
1 | 169 |
} |
170 |
%} |
|
171 |
. |
|
172 |
^ (self basicNew) origin:origin extent:extent |
|
173 |
! ! |
|
174 |
||
175 |
!Rectangle methodsFor:'accessing'! |
|
176 |
||
637 | 177 |
area |
178 |
"return the area |
|
179 |
- for screen Rectangles this is the number of pixels" |
|
180 |
||
181 |
^ width * height |
|
182 |
! |
|
183 |
||
184 |
bottom |
|
185 |
"return the y coordinate of the bottom" |
|
186 |
||
187 |
^ (top + height) |
|
188 |
! |
|
189 |
||
190 |
bottom:aNumber |
|
191 |
"set the bottom edge" |
|
192 |
||
193 |
height := aNumber - top |
|
194 |
! |
|
195 |
||
196 |
bottomCenter |
|
197 |
"return the bottom center point" |
|
198 |
||
199 |
^ (left + (width // 2)) @ (top + height) |
|
200 |
! |
|
201 |
||
202 |
bottomLeft |
|
203 |
"return the bottom-left point" |
|
204 |
||
205 |
^ left @ (top + height) |
|
206 |
! |
|
207 |
||
208 |
bottomRight |
|
209 |
"return the bottom-right point" |
|
210 |
||
211 |
^ (left + width) @ (top + height) |
|
212 |
! |
|
213 |
||
214 |
center |
|
215 |
"return the point in the center of the receiver" |
|
216 |
||
217 |
^ (left + (width // 2)) @ (top + (height // 2)) |
|
218 |
! |
|
219 |
||
220 |
corner |
|
221 |
"return the corner" |
|
222 |
||
223 |
^ (left + width) @ (top + height) |
|
224 |
! |
|
225 |
||
226 |
corner:aPoint |
|
227 |
"set the bottom-right corner" |
|
228 |
||
229 |
width := aPoint x - left. |
|
230 |
height := aPoint y - top |
|
231 |
! |
|
232 |
||
233 |
extent |
|
234 |
"return the extent" |
|
235 |
||
236 |
^ width @ height |
|
237 |
! |
|
238 |
||
239 |
extent:aPoint |
|
240 |
"set the extent from the argument, aPoint with width taken from aPoint x |
|
241 |
and height taken from aPoint y" |
|
242 |
||
243 |
width := aPoint x. |
|
244 |
height := aPoint y |
|
245 |
! |
|
246 |
||
247 |
height |
|
248 |
"return the height of the rectangle" |
|
249 |
||
250 |
^ height |
|
251 |
! |
|
252 |
||
253 |
left |
|
254 |
"return the x-coordinate of the top-left origin" |
|
255 |
||
256 |
^ left |
|
257 |
! |
|
258 |
||
259 |
left:aNumber |
|
260 |
"set the left edge" |
|
261 |
||
262 |
width := width + (left - aNumber). |
|
263 |
left := aNumber |
|
264 |
! |
|
265 |
||
1 | 266 |
left:newLeft right:right top:newTop bottom:bottom |
77 | 267 |
"set the rectangle given left, top, right and bottom coordinates." |
1 | 268 |
|
269 |
left := newLeft. |
|
270 |
top := newTop. |
|
271 |
width := right - left. |
|
272 |
height := bottom - top |
|
273 |
! |
|
274 |
||
275 |
left:newLeft top:newTop right:right bottom:bottom |
|
276 |
"set the rectangle given left, top, right and bottom coordinates" |
|
277 |
||
278 |
left := newLeft. |
|
279 |
top := newTop. |
|
280 |
width := right - left. |
|
281 |
height := bottom - top |
|
282 |
! |
|
283 |
||
284 |
left:newLeft top:newTop width:newWidth height:newHeight |
|
285 |
"set the rectangle given left, top coordinates and width, height" |
|
286 |
||
287 |
left := newLeft. |
|
288 |
top := newTop. |
|
289 |
width := newWidth. |
|
290 |
height := newHeight |
|
291 |
! |
|
292 |
||
637 | 293 |
leftCenter |
294 |
"return the left center point" |
|
295 |
||
296 |
^ left @ (top + (height // 2)) |
|
297 |
! |
|
298 |
||
299 |
origin |
|
300 |
"return the origin" |
|
301 |
||
302 |
^ left @ top |
|
303 |
! |
|
304 |
||
1 | 305 |
origin:aPoint |
77 | 306 |
"set the top-left origin. The corner remains unchanged." |
307 |
||
308 |
|newTop newLeft| |
|
1 | 309 |
|
77 | 310 |
newTop := aPoint y. |
311 |
newLeft := aPoint x. |
|
312 |
height := height + (top - newTop). |
|
313 |
width := width + (left - newLeft). |
|
314 |
left := newLeft. |
|
315 |
top := newTop |
|
1 | 316 |
! |
317 |
||
637 | 318 |
origin:origin corner:corner |
319 |
"set both origin and corner" |
|
320 |
||
321 |
left := origin x. |
|
322 |
top := origin y. |
|
323 |
width := corner x - left. |
|
324 |
height := corner y - top |
|
325 |
! |
|
326 |
||
327 |
origin:origin extent:extent |
|
328 |
"set both origin and extent" |
|
329 |
||
330 |
left := origin x. |
|
331 |
top := origin y. |
|
332 |
width := extent x. |
|
333 |
height := extent y |
|
334 |
! |
|
1 | 335 |
|
637 | 336 |
right |
337 |
"return the x coordinate of the right" |
|
338 |
||
339 |
^ (left + width) |
|
340 |
! |
|
341 |
||
342 |
right:aNumber |
|
343 |
"set the right edge" |
|
344 |
||
345 |
width := aNumber - left |
|
346 |
! |
|
347 |
||
348 |
rightCenter |
|
349 |
"return the right center point" |
|
350 |
||
351 |
^ (left + width) @ (top + (height // 2)) |
|
352 |
! |
|
353 |
||
354 |
top |
|
355 |
"return the y-coordinate of the top-left" |
|
356 |
||
357 |
^ top |
|
1 | 358 |
! |
359 |
||
360 |
top:aNumber |
|
361 |
"set the top edge" |
|
362 |
||
363 |
height := height + (top - aNumber). |
|
364 |
top := aNumber |
|
365 |
! |
|
366 |
||
637 | 367 |
topCenter |
368 |
"return the top center point" |
|
1 | 369 |
|
637 | 370 |
^ (left + (width // 2)) @ top |
1 | 371 |
! |
372 |
||
637 | 373 |
topLeft |
374 |
"return the top-left point - the same as origin" |
|
77 | 375 |
|
637 | 376 |
^ left @ top |
77 | 377 |
! |
378 |
||
379 |
topLeft:aPoint |
|
380 |
"Set the top and left edges. |
|
381 |
The bottom right remains unchanged." |
|
382 |
||
383 |
|newTop| |
|
384 |
||
385 |
newTop := aPoint y. |
|
386 |
height := height + (top - newTop). |
|
387 |
top := newTop. |
|
388 |
width := aPoint x - left |
|
389 |
! |
|
390 |
||
637 | 391 |
topRight |
392 |
"return the top-right point" |
|
393 |
||
394 |
^ (left + width) @ top |
|
395 |
! |
|
396 |
||
77 | 397 |
topRight:aPoint |
398 |
"Set the top and right edges. |
|
399 |
The bottom left remains unchanged." |
|
400 |
||
401 |
|newTop| |
|
402 |
||
403 |
newTop := aPoint y. |
|
404 |
height := height + (top - newTop). |
|
405 |
top := newTop. |
|
406 |
width := aPoint x - left |
|
407 |
! |
|
408 |
||
409 |
width |
|
410 |
"return the width of the rectangle" |
|
411 |
||
412 |
^ width |
|
1 | 413 |
! ! |
414 |
||
415 |
!Rectangle methodsFor:'comparing'! |
|
416 |
||
417 |
= aRectangle |
|
418 |
"return true, if the argument aRectangle represents the same |
|
419 |
rectangle as the receiver" |
|
420 |
||
421 |
%{ /* NOCONTEXT */ |
|
59 | 422 |
/* |
1151 | 423 |
* because rectangles are often compared in the graphics code, |
59 | 424 |
* handle the common case quickly |
425 |
*/ |
|
329 | 426 |
if (__isNonNilObject(aRectangle) |
427 |
&& __qClass(aRectangle) == Rectangle) { |
|
1133 | 428 |
if ((__InstPtr(self)->i_instvars[0] == __InstPtr(aRectangle)->i_instvars[0]) |
429 |
&& (__InstPtr(self)->i_instvars[1] == __InstPtr(aRectangle)->i_instvars[1]) |
|
430 |
&& (__InstPtr(self)->i_instvars[2] == __InstPtr(aRectangle)->i_instvars[2]) |
|
431 |
&& (__InstPtr(self)->i_instvars[3] == __InstPtr(aRectangle)->i_instvars[3])) { |
|
186 | 432 |
RETURN ( true ); |
433 |
} |
|
1133 | 434 |
if (__bothSmallInteger(__InstPtr(self)->i_instvars[0], __InstPtr(aRectangle)->i_instvars[0]) |
435 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[1], __InstPtr(aRectangle)->i_instvars[1]) |
|
436 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[2], __InstPtr(aRectangle)->i_instvars[2]) |
|
437 |
&& __bothSmallInteger(__InstPtr(self)->i_instvars[3], __InstPtr(aRectangle)->i_instvars[3])) { |
|
325 | 438 |
RETURN ( false ); |
439 |
} |
|
1 | 440 |
} |
1151 | 441 |
%}. |
259 | 442 |
(aRectangle species ~~ self species) ifTrue:[^ false]. |
1 | 443 |
|
444 |
left = aRectangle left ifFalse:[^ false]. |
|
445 |
top = aRectangle top ifFalse:[^ false]. |
|
446 |
width = aRectangle width ifFalse:[^ false]. |
|
447 |
height = aRectangle height ifFalse:[^ false]. |
|
448 |
^ true |
|
59 | 449 |
! |
450 |
||
451 |
hash |
|
452 |
"return an integer useful for hashing - |
|
453 |
redefined since = is redefined here" |
|
454 |
||
455 |
^ ((left hash bitShift:16) bitXor:(top hash bitShift:16)) |
|
456 |
+ ((width hash) bitXor:(height hash)) |
|
1 | 457 |
! ! |
458 |
||
356 | 459 |
!Rectangle methodsFor:'converting'! |
460 |
||
461 |
asFractionalLayout |
|
462 |
"return a layoutFrame in which fractions (top, left, bottom, right) |
|
463 |
are taken from corresponding edges of the receiver. |
|
464 |
You have to make certain that those are in 0..1." |
|
465 |
||
466 |
|l| |
|
467 |
||
468 |
l := LayoutFrame new. |
|
469 |
l |
|
470 |
leftFraction:(self left); |
|
471 |
rightFraction:(self right); |
|
472 |
topFraction:(self top); |
|
473 |
bottomFraction:(self bottom). |
|
474 |
^ l |
|
475 |
||
476 |
" |
|
477 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
478 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
479 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
480 |
" |
|
481 |
! |
|
482 |
||
483 |
asLayout |
|
484 |
"return a layoutFrame in which offsets (top, left, bottom, right) |
|
485 |
are taken from corresponding edges of the receiver. |
|
1151 | 486 |
If all values are between 0.0 .. 1.0, a fractionalLayout is created, |
356 | 487 |
otherwise, an offsetLayout" |
488 |
||
1151 | 489 |
|newLayout left right top bot| |
356 | 490 |
|
1151 | 491 |
newLayout := LayoutFrame new. |
356 | 492 |
left := (self left). |
493 |
right := (self right). |
|
494 |
top := (self top). |
|
495 |
bot := (self bottom). |
|
1151 | 496 |
((left between:0.0 and:1.0) |
497 |
and:[(right between:0.0 and:1.0) |
|
498 |
and:[(top between:0.0 and:1.0) |
|
499 |
and:[(bot between:0.0 and:1.0)]]]) ifTrue:[ |
|
500 |
newLayout |
|
356 | 501 |
leftFraction:left; |
502 |
rightFraction:right; |
|
503 |
topFraction:top; |
|
504 |
bottomFraction:bot. |
|
505 |
] ifFalse:[ |
|
1151 | 506 |
newLayout |
356 | 507 |
leftOffset:left; |
508 |
rightFraction:0 offset:right; |
|
509 |
topOffset:top; |
|
510 |
bottomFraction:0 offset:bot. |
|
511 |
]. |
|
1151 | 512 |
^ newLayout |
356 | 513 |
|
514 |
" |
|
515 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
516 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
517 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
518 |
(0@0 corner:1@1) asLayout |
|
519 |
(0@0 corner:1@1) asFractionalLayout |
|
520 |
(0@0 corner:1@1) asOffsetLayout |
|
521 |
" |
|
522 |
! |
|
523 |
||
637 | 524 |
asOffsetLayout |
525 |
"return a layoutFrame in which offsets (top, left, bottom, right) |
|
526 |
are taken from corresponding edges of the receiver. |
|
527 |
You have to make certain that those are in 0..1." |
|
528 |
||
1151 | 529 |
|newLayout| |
637 | 530 |
|
1151 | 531 |
newLayout := LayoutFrame new. |
532 |
newLayout |
|
637 | 533 |
leftOffset:(self left); |
534 |
rightFraction:0 offset:(self right); |
|
535 |
topOffset:(self top); |
|
536 |
bottomFraction:0 offset:(self bottom). |
|
1151 | 537 |
^ newLayout |
637 | 538 |
|
539 |
" |
|
540 |
(0.5@0.5 corner:0.75@0.75) asFractionalLayout |
|
541 |
(0.5@0.5 corner:0.75@0.75) asOffsetLayout |
|
542 |
(0.5@0.5 corner:0.75@0.75) asLayout |
|
543 |
||
544 |
(10@10 corner:20@20) asFractionalLayout |
|
545 |
(10@10 corner:20@20) asOffsetLayout |
|
546 |
(10@10 corner:20@20) asLayout |
|
547 |
" |
|
548 |
||
549 |
! |
|
550 |
||
356 | 551 |
asPointArray |
552 |
"return an array containing my corners (clockwise) and |
|
553 |
the origin again as 5th element. Can be used to convert |
|
554 |
a rectangle into a polygon." |
|
555 |
||
556 |
|org| |
|
557 |
||
558 |
^ Array with:(org := self origin) |
|
559 |
with:self topRight |
|
560 |
with:self corner |
|
561 |
with:self bottomLeft |
|
562 |
with:org |
|
563 |
||
564 |
" |
|
565 |
(10@10 corner:100@100) asPointArray |
|
566 |
" |
|
567 |
! |
|
568 |
||
637 | 569 |
fromLiteralArrayEncoding:encoding |
570 |
"read my values from an encoding. |
|
571 |
The encoding is supposed to be of the form: (Rectangle orgX orgY cornX cornY)" |
|
356 | 572 |
|
637 | 573 |
left := encoding at:2. |
574 |
top := encoding at:3. |
|
575 |
width := (encoding at:4) - left. |
|
576 |
height := (encoding at:5) - top |
|
577 |
||
356 | 578 |
|
579 |
" |
|
637 | 580 |
Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) |
356 | 581 |
" |
379 | 582 |
! |
583 |
||
421 | 584 |
literalArrayEncoding |
1245 | 585 |
"encode myself as an array, from which a copy of the receiver |
586 |
can be reconstructed with #decodeAsLiteralArray. |
|
421 | 587 |
The encoding is: (Rectangle orgX orgY cornX cornY)" |
588 |
||
589 |
^ Array |
|
1245 | 590 |
with:#Rectangle |
591 |
with:left |
|
592 |
with:top |
|
593 |
with:width |
|
594 |
with:height |
|
421 | 595 |
|
596 |
||
597 |
" |
|
598 |
Rectangle new fromLiteralArrayEncoding:#(Rectangle 100 200 300 500) |
|
599 |
(100@200 corner:300@500) literalArrayEncoding |
|
600 |
" |
|
601 |
||
602 |
"Modified: 1.9.1995 / 02:16:54 / claus" |
|
1245 | 603 |
"Modified: 22.4.1996 / 13:00:36 / cg" |
421 | 604 |
! |
605 |
||
637 | 606 |
rectangleRelativeTo:aRectangle preferred:prefRect |
607 |
"compute a displayRectangle, treating the receiver like a |
|
608 |
layoutorigin. This allows point to be used interchangable with |
|
609 |
LayoutOrigins." |
|
379 | 610 |
|
637 | 611 |
^ (self asLayout) rectangleRelativeTo:aRectangle preferred:prefRect |
379 | 612 |
|
613 |
" |
|
637 | 614 |
(10@20 corner:20@30) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
615 |
||
616 |
(0.5@0.5) rectangleRelativeTo:(0@0 corner:100@100) preferred:(0@0 corner:50@50) |
|
379 | 617 |
" |
356 | 618 |
! ! |
619 |
||
186 | 620 |
!Rectangle methodsFor:'destructive rectangle operations'! |
621 |
||
356 | 622 |
expandBy:delta |
623 |
"destructively expanded the receiver in all directions |
|
624 |
by amount, a Point, Rectangle or Number. |
|
625 |
Warning: this is a destructive operation, modifying the receiver |
|
626 |
NOT returning a copy. You have to be certain to be the exclusive |
|
627 |
owner of the receiver to avoid side effects. See also: #expandedBy:" |
|
628 |
||
629 |
|amountPoint deltaLeft deltaTop deltaWidth deltaHeight| |
|
630 |
||
631 |
delta isNumber ifTrue:[ |
|
632 |
deltaLeft := deltaTop := delta. |
|
633 |
deltaWidth := deltaHeight := delta * 2. |
|
634 |
] ifFalse:[ |
|
635 |
delta isRectangle ifTrue:[ |
|
636 |
deltaLeft := delta left. |
|
637 |
deltaTop := delta top. |
|
638 |
deltaWidth := deltaLeft + delta right. |
|
639 |
deltaHeight := deltaTop + delta bottom |
|
640 |
] ifFalse:[ |
|
641 |
amountPoint := delta asPoint. |
|
642 |
deltaLeft := amountPoint x. |
|
643 |
deltaTop := amountPoint y. |
|
644 |
deltaWidth := deltaLeft * 2. |
|
645 |
deltaHeight := deltaTop * 2. |
|
646 |
] |
|
647 |
]. |
|
648 |
||
649 |
left := (left - deltaLeft). |
|
650 |
top := (top - deltaTop). |
|
651 |
width := (width + deltaWidth). |
|
652 |
height := (height + deltaHeight). |
|
653 |
||
654 |
" |
|
655 |
|r| |
|
656 |
r := Rectangle origin:10@10 corner:100@100. |
|
657 |
r expandBy:5. |
|
658 |
||
659 |
r := Rectangle origin:10@10 corner:100@100. |
|
660 |
r expandBy:(5 @ 0). |
|
661 |
||
662 |
r := Rectangle origin:10@10 corner:100@100. |
|
663 |
r expandBy:(10 @ 10). |
|
664 |
||
665 |
r := Rectangle origin:10@10 corner:100@100. |
|
666 |
r expandBy:( 10@10 corner:20@20 ) |
|
667 |
" |
|
637 | 668 |
! |
669 |
||
670 |
moveBy:aPoint |
|
671 |
"destructively translate the rectangle by some distance. |
|
672 |
sorry for the name inconsistency - but GNU-ST named it that way" |
|
673 |
||
674 |
left := left + aPoint x. |
|
675 |
top := top + aPoint y |
|
676 |
! |
|
677 |
||
678 |
moveTo:aPoint |
|
679 |
"destructively translate the rectangle to have its origin at aPoint." |
|
680 |
||
681 |
|diff| |
|
682 |
||
683 |
diff := aPoint - self origin. |
|
684 |
self origin:aPoint corner:self corner + diff |
|
685 |
! |
|
686 |
||
687 |
scaleBy:scale |
|
688 |
"scale the receiver rectangle by scale (a Number or Point). |
|
689 |
This is destructive (modifies the receiver, not a copy) and |
|
690 |
should only be used if you know, that you are the exclusive owner |
|
691 |
of the receiver. (use scaledBy if in doubt)" |
|
692 |
||
693 |
|scalePoint sx sy| |
|
694 |
||
695 |
(scale isMemberOf:Point) ifTrue:[ "type hint to stc" |
|
696 |
sx := scale x. |
|
697 |
sy := scale y |
|
698 |
] ifFalse:[ |
|
699 |
scalePoint := scale asPoint. |
|
700 |
sx := scalePoint x. |
|
701 |
sy := scalePoint y |
|
702 |
]. |
|
703 |
width := width * sx. |
|
704 |
height := height * sy. |
|
705 |
left := left * sx. |
|
706 |
top := top * sy |
|
707 |
||
708 |
" |
|
709 |
(Rectangle origin:10@10 corner:50@50) scaleBy:2 |
|
710 |
" |
|
711 |
||
712 |
"its destructive:" |
|
713 |
" |
|
714 |
|r1 r2| |
|
715 |
||
716 |
r1 := Rectangle origin:10@10 corner:50@50. |
|
717 |
r2 := r1 scaleBy:2. |
|
718 |
r1 |
|
719 |
" |
|
720 |
! |
|
721 |
||
722 |
translateBy:amount |
|
723 |
"translate (i.e. move) the receiver rectangle |
|
724 |
by amount, a Point or Number. |
|
725 |
This is destructive (modifies the receiver, not a copy) and |
|
726 |
should only be used if you know, that you are the exclusive owner |
|
727 |
of the receiver. (use translatedBy if in doubt)" |
|
728 |
||
729 |
|amountPoint| |
|
730 |
||
731 |
(amount isMemberOf:Point) ifTrue:[ "type hint to stc" |
|
732 |
left := left + amount x. |
|
733 |
top := top + amount y |
|
734 |
] ifFalse:[ |
|
735 |
amountPoint := amount asPoint. |
|
736 |
left := left + amountPoint x. |
|
737 |
top := top + amountPoint y |
|
738 |
] |
|
739 |
||
740 |
" |
|
741 |
(Rectangle origin:10@10 corner:50@50) translateBy:10 |
|
742 |
" |
|
743 |
||
744 |
"its destructive:" |
|
745 |
" |
|
746 |
|r1 r2| |
|
747 |
||
748 |
r1 := Rectangle origin:10@10 corner:50@50. |
|
749 |
r2 := r1 translateBy:10. |
|
750 |
r1 |
|
751 |
" |
|
752 |
! ! |
|
753 |
||
754 |
!Rectangle methodsFor:'displaying'! |
|
755 |
||
756 |
displayFilledOn:aGC |
|
757 |
aGC fillRectangleX:left y:top width:width height:height |
|
758 |
||
759 |
" |
|
760 |
|v| |
|
761 |
||
762 |
v := View new open. |
|
763 |
[v shown] whileFalse:[Processor yield]. |
|
764 |
||
765 |
(Rectangle origin:10@10 corner:50@50) displayFilledOn:v |
|
766 |
" |
|
767 |
! |
|
768 |
||
769 |
displayStrokedOn:aGC |
|
770 |
aGC displayRectangleX:left y:top width:width height:height |
|
771 |
||
772 |
" |
|
773 |
|v| |
|
774 |
||
775 |
v := View new open. |
|
776 |
[v shown] whileFalse:[Processor yield]. |
|
777 |
||
778 |
(Rectangle origin:10@10 corner:50@50) displayStrokedOn:v |
|
779 |
" |
|
780 |
! ! |
|
781 |
||
782 |
!Rectangle methodsFor:'printing & storing'! |
|
783 |
||
784 |
printOn:aStream |
|
785 |
"print the receiver on aStream" |
|
786 |
||
787 |
aStream nextPutAll:(self class name). |
|
788 |
aStream nextPutAll:' origin:'. |
|
789 |
(self origin) printOn:aStream. |
|
790 |
aStream nextPutAll:' corner:'. |
|
791 |
(self corner) printOn:aStream |
|
792 |
! |
|
793 |
||
794 |
storeOn:aStream |
|
795 |
"store the receiver on aStream; i.e. print an expression which will |
|
796 |
reconstruct the receiver" |
|
797 |
||
798 |
aStream nextPut:$(. |
|
799 |
aStream nextPutAll:(self class name). |
|
800 |
aStream nextPutAll:' origin:'. |
|
801 |
(self origin) storeOn:aStream. |
|
802 |
aStream nextPutAll:' corner:'. |
|
803 |
(self corner) storeOn:aStream. |
|
804 |
aStream nextPut:$) |
|
805 |
! ! |
|
806 |
||
807 |
!Rectangle methodsFor:'queries'! |
|
808 |
||
809 |
isRectangle |
|
810 |
"return true, if the receiver is some kind of rectangle" |
|
811 |
||
812 |
^ true |
|
186 | 813 |
! ! |
814 |
||
1 | 815 |
!Rectangle methodsFor:'rectangle operations'! |
816 |
||
817 |
+ aPoint |
|
356 | 818 |
"return a new rectangle with same extent as receiver but |
1 | 819 |
origin translated by the argument, aPoint" |
820 |
||
217 | 821 |
|amountPoint| |
822 |
||
823 |
amountPoint := aPoint asPoint. |
|
824 |
^ Rectangle left:(left + amountPoint x) |
|
825 |
top:(top + amountPoint y) |
|
826 |
width:width |
|
827 |
height:height |
|
1 | 828 |
! |
829 |
||
326 | 830 |
align:offset with:someCoordinate |
831 |
"return a new rectangle which is translated (i.e. moved) |
|
832 |
such that the point offset in mySelf is placed on someCoordinate." |
|
833 |
||
834 |
^ Rectangle origin:(someCoordinate - offset + self origin) |
|
835 |
extent:(self extent) |
|
836 |
" |
|
837 |
|r| |
|
838 |
||
839 |
r := Rectangle origin:10@10 corner:50@50. |
|
840 |
r align:(r center) with:100@100. |
|
841 |
" |
|
842 |
! |
|
843 |
||
1 | 844 |
amountToTranslateWithin: aRectangle |
845 |
"for GNU-ST compatibility" |
|
846 |
||
847 |
^(aRectangle origin) - self origin |
|
848 |
! |
|
849 |
||
850 |
areasOutside: aRectangle |
|
851 |
"---------------------------------------------------------------- |
|
852 |
| added for GNU-ST compatibility |
|
853 |
| |
|
854 |
| author: Doug McCallum <uunet!!ico.isc.com!!dougm> |
|
855 |
| |
|
856 |
|areasOutside: aRectangle |
|
857 |
| most complicated of the Rectangle primitives |
|
858 |
| The basic methodology is to first determine that there is an |
|
859 |
| intersection by finding the overlapping rectangle. From the |
|
860 |
| overlapping rectangle, first determine if it runs along an edge. |
|
861 |
| If it doesn't, extend the rectangle up to the top edge and add |
|
862 |
| the new rectangle to the collection and start the rest of the |
|
863 |
| process. If the left edge does not touch the left edge of self, |
|
864 |
| extend it to the edge saving the new rectangle. Then do the |
|
865 |
| same to the right edge. Then check top and bottom edges. Most |
|
866 |
| of the time only 2 or 3 rectangles get formed, occasionally 4. |
|
867 |
| It should be possible to never get more than 3 but requires more |
|
868 |
| work. |
|
869 |
----------------------------------------------------------------" |
|
870 |
||
871 |
| collect iRect tmp | |
|
1124 | 872 |
|
360 | 873 |
iRect := self intersect: aRectangle. |
1124 | 874 |
iRect isNil ifTrue: [^nil]. "case of no intersection" |
186 | 875 |
"the collect collection gathers Rectangles" |
360 | 876 |
collect := OrderedCollection new: 4. |
186 | 877 |
"is it floating or on the edge?" |
1 | 878 |
(((((iRect top) ~= self top) |
186 | 879 |
and: [ (iRect bottom) ~= self bottom ]) |
880 |
and: [ (iRect left) ~= self left ]) |
|
881 |
and: [ (iRect right) ~= self right ] ) |
|
882 |
ifTrue: "entirely in the center." |
|
360 | 883 |
[tmp := Rectangle origin: (Point x: iRect left y: self top) |
884 |
corner: iRect bottomRight. |
|
186 | 885 |
collect add: tmp. |
360 | 886 |
iRect := iRect merge: tmp]. |
1 | 887 |
((iRect left) ~= self left) |
186 | 888 |
ifTrue: "doesn't touch left edge so make it touch" |
360 | 889 |
[tmp := Rectangle origin: (Point x: self left y: iRect top) |
890 |
corner: iRect bottomLeft. |
|
186 | 891 |
collect add: tmp. |
892 |
"merge new (tmp) with overlap to keep track" |
|
360 | 893 |
iRect := iRect merge: tmp]. |
1 | 894 |
((iRect right) ~= self right) |
186 | 895 |
ifTrue: "doesn't touch right edge so extend it" |
360 | 896 |
[tmp := Rectangle origin: iRect topRight |
897 |
corner: (Point x: self right y: iRect bottom). |
|
186 | 898 |
collect add: tmp. |
360 | 899 |
iRect := iRect merge: tmp]. |
77 | 900 |
(((iRect left) ~= self left) or: [(iRect top) ~= self top]) |
186 | 901 |
ifTrue: "whole top part can be taken now" |
360 | 902 |
[tmp := Rectangle origin: self origin corner: iRect topRight. |
186 | 903 |
collect add: tmp]. |
77 | 904 |
(((iRect right) ~= self right) or: [(iRect bottom) ~= self bottom]) |
186 | 905 |
ifTrue: "whole bottom open and can be taken" |
360 | 906 |
[tmp := Rectangle origin: iRect bottomLeft corner: self corner. |
186 | 907 |
collect add: tmp]. |
1 | 908 |
^collect |
77 | 909 |
! |
1 | 910 |
|
637 | 911 |
expandedBy:delta |
912 |
"return a new rectangle which is expanded in all directions |
|
913 |
by amount, a Point, Rectangle or Number" |
|
914 |
||
915 |
^ self copy expandBy:delta |
|
916 |
||
917 |
" |
|
918 |
|r| |
|
919 |
r := Rectangle origin:10@10 corner:100@100. |
|
920 |
r expandedBy:5. |
|
921 |
r expandedBy:(5 @ 0). |
|
922 |
r expandedBy:(10 @ 10). |
|
923 |
r expandedBy:( 10@10 corner:20@20 ) |
|
924 |
" |
|
925 |
! |
|
926 |
||
927 |
insetBy: delta |
|
928 |
"return a new rectangle which is inset in all directions |
|
929 |
by delta, a Point, Rectangle or Number" |
|
930 |
||
931 |
|amountPoint deltaLeft deltaTop deltaWidth deltaHeight| |
|
932 |
||
933 |
delta isNumber ifTrue:[ |
|
934 |
deltaLeft := deltaTop := delta. |
|
935 |
deltaWidth := deltaHeight := delta * 2. |
|
936 |
] ifFalse:[ |
|
937 |
delta isRectangle ifTrue:[ |
|
938 |
deltaLeft := delta left. |
|
939 |
deltaTop := delta top. |
|
940 |
deltaWidth := deltaLeft + delta right. |
|
941 |
deltaHeight := deltaTop + delta bottom |
|
942 |
] ifFalse:[ |
|
943 |
amountPoint := delta asPoint. |
|
944 |
deltaLeft := amountPoint x. |
|
945 |
deltaTop := amountPoint y. |
|
946 |
deltaWidth := deltaLeft * 2. |
|
947 |
deltaHeight := deltaTop * 2. |
|
948 |
] |
|
949 |
]. |
|
950 |
||
951 |
^ Rectangle left:(left + deltaLeft) |
|
952 |
top:(top + deltaTop) |
|
953 |
width:(width - deltaWidth) |
|
954 |
height:(height - deltaHeight) |
|
955 |
" |
|
956 |
|r| |
|
957 |
r := Rectangle origin:10@10 corner:100@100. |
|
958 |
r insetBy:5. |
|
959 |
r insetBy:(5 @ 0). |
|
960 |
r insetBy:(10 @ 10). |
|
961 |
r insetBy:( 10@10 corner:20@20 ) |
|
962 |
" |
|
963 |
! |
|
964 |
||
965 |
insetOriginBy:originDelta cornerBy:cornerDelta |
|
966 |
"return a new rectangle which is inset by originDelta |
|
967 |
and cornerDelta; both may be instances of Point or Number" |
|
968 |
||
969 |
^ Rectangle |
|
970 |
origin:(left @ top) + originDelta asPoint |
|
971 |
corner:(self corner - cornerDelta asPoint) |
|
972 |
" |
|
973 |
|r| |
|
974 |
r := Rectangle origin:10@10 corner:100@100. |
|
975 |
r insetOriginBy:5 cornerBy:10. |
|
976 |
r insetOriginBy:10@5 cornerBy:10. |
|
977 |
r insetOriginBy:10 cornerBy:10@5. |
|
978 |
r insetOriginBy:10@10 cornerBy:20@20. |
|
979 |
" |
|
980 |
! |
|
981 |
||
982 |
intersect:aRectangle |
|
983 |
"return a new rectangle covering the intersection of the receiver |
|
984 |
and the argument, aRectangle. |
|
985 |
the rectangles must intersect for a valid return" |
|
986 |
||
987 |
^ Rectangle left:(left max:(aRectangle left)) |
|
988 |
right:((left + width) min:(aRectangle right)) |
|
989 |
top:(top max:(aRectangle top)) |
|
990 |
bottom:((top + height) min:(aRectangle bottom)) |
|
991 |
||
992 |
" |
|
993 |
|r1 r2| |
|
994 |
||
995 |
r1 := Rectangle origin:10@10 corner:100@100. |
|
996 |
r2 := Rectangle origin:50@50 corner:150@75. |
|
997 |
r1 intersect:r2 |
|
998 |
" |
|
999 |
! |
|
1000 |
||
1001 |
merge:aRectangle |
|
1002 |
"return a new rectangle covering both the receiver |
|
1003 |
and the argument, aRectangle" |
|
1004 |
||
1005 |
^ Rectangle left:(left min:(aRectangle left)) |
|
1006 |
right:((left + width) max:(aRectangle right)) |
|
1007 |
top:(top min:(aRectangle top)) |
|
1008 |
bottom:((top + height) max:(aRectangle bottom)) |
|
1009 |
! |
|
1010 |
||
77 | 1011 |
nonIntersections:aRectangle |
1012 |
"this is the same as areasOutside: - for ST/V compatibility only" |
|
1013 |
||
1014 |
^ self areasOutside:aRectangle |
|
637 | 1015 |
! |
1016 |
||
1017 |
rounded |
|
1018 |
"return a copy of the receiver with rounded coordinates" |
|
1 | 1019 |
|
637 | 1020 |
^ Rectangle left:(left rounded) |
1021 |
top:(top rounded) |
|
1022 |
width:(width rounded) |
|
1023 |
height:(height rounded) |
|
1024 |
! |
|
356 | 1025 |
|
637 | 1026 |
scaledBy:scale |
1027 |
"return a new rectangle which is the receiver |
|
1028 |
scaled by scale" |
|
1029 |
||
1030 |
|scalePoint sx sy| |
|
356 | 1031 |
|
637 | 1032 |
scalePoint := scale asPoint. |
1033 |
sx := scalePoint x. |
|
1034 |
sy := scalePoint y. |
|
1035 |
^ Rectangle left:left * sx |
|
1036 |
top:top * sy |
|
1037 |
width:(width * sx) |
|
1038 |
height:(height * sy) |
|
356 | 1039 |
" |
637 | 1040 |
(Rectangle origin:10@10 corner:50@50) scaledBy:2 |
1041 |
" |
|
356 | 1042 |
|
637 | 1043 |
"its NOT destructive:" |
1044 |
" |
|
1045 |
|r1 r2| |
|
356 | 1046 |
|
637 | 1047 |
r1 := Rectangle origin:10@10 corner:50@50. |
1048 |
r2 := r1 scaledBy:2. |
|
1049 |
r1 |
|
356 | 1050 |
" |
1051 |
! |
|
1052 |
||
637 | 1053 |
translatedBy:amount |
1054 |
"return a new rectangle which is translated (i.e. moved) |
|
1055 |
by amount, aPoint or Number" |
|
1056 |
||
1057 |
|amountPoint| |
|
356 | 1058 |
|
637 | 1059 |
amountPoint := amount asPoint. |
1060 |
^ Rectangle left:(left + amountPoint x) |
|
1061 |
top:(top + amountPoint y) |
|
1062 |
width:width |
|
1063 |
height:height |
|
356 | 1064 |
" |
637 | 1065 |
(Rectangle origin:10@10 corner:50@50) translatedBy:10 |
1066 |
" |
|
356 | 1067 |
|
637 | 1068 |
"its NOT destructive:" |
1069 |
" |
|
1070 |
|r1 r2| |
|
356 | 1071 |
|
637 | 1072 |
r1 := Rectangle origin:10@10 corner:50@50. |
1073 |
r2 := r1 translatedBy:10. |
|
1074 |
r1 |
|
356 | 1075 |
" |
1076 |
! ! |
|
1077 |
||
637 | 1078 |
!Rectangle methodsFor:'testing'! |
1 | 1079 |
|
637 | 1080 |
contains:aRectangle |
1081 |
"return true, if the argument, aRectangle is equal to or |
|
1082 |
is contained fully within the receiver" |
|
1 | 1083 |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1084 |
%{ /* NOCONTEXT */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1085 |
/* |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1086 |
* 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
|
1087 |
* 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
|
1088 |
* 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
|
1089 |
*/ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1090 |
OBJ slf = self; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1091 |
OBJ rct = aRectangle; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1092 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1093 |
if (__isNonNilObject(rct) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1094 |
&& __qClass(rct) == Rectangle) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1095 |
OBJ r_l, r_w, r_t, r_h, l, w, t, h; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1096 |
int r_ir, r_il, r_ib, r_it; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1097 |
int il, it, ir, ib, iw, ih; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1098 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1099 |
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
|
1100 |
l = __OINST(slf, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1101 |
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
|
1102 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1103 |
il = (int)(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1104 |
r_il = (int)(r_l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1105 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1106 |
il = __intVal(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1107 |
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
|
1108 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1109 |
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
|
1110 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1111 |
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
|
1112 |
t = __OINST(slf, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1113 |
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
|
1114 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1115 |
it = (int)(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1116 |
r_it = (int)(r_t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1117 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1118 |
it = __intVal(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1119 |
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
|
1120 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1121 |
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
|
1122 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1123 |
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
|
1124 |
w = __OINST(slf, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1125 |
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
|
1126 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1127 |
ir = il + (int)(w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1128 |
r_ir = r_il + (int)(r_w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1129 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1130 |
ir = il + __intVal(w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1131 |
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
|
1132 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1133 |
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
|
1134 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1135 |
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
|
1136 |
h = __OINST(slf, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1137 |
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
|
1138 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1139 |
ib = it + (int)(h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1140 |
r_ib = r_it + (int)(r_h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1141 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1142 |
ib = it + __intVal(h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1143 |
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
|
1144 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1145 |
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
|
1146 |
RETURN (true); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1147 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1148 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1149 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1150 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1151 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1152 |
%}. |
637 | 1153 |
(left <= aRectangle left) ifTrue:[ |
1154 |
((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
|
1155 |
(top <= aRectangle top) ifTrue:[ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1156 |
((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
|
1157 |
^ true |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1158 |
] |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1159 |
] |
637 | 1160 |
] |
1161 |
]. |
|
1162 |
^ false |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1163 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1164 |
" |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1165 |
(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
|
1166 |
(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
|
1167 |
(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
|
1168 |
(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
|
1169 |
(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
|
1170 |
" |
637 | 1171 |
! |
1172 |
||
1173 |
containsPoint:aPoint |
|
1174 |
"return true, if the argument, aPoint is contained in the receiver" |
|
1175 |
||
1176 |
|px py| |
|
1177 |
||
1178 |
px := aPoint x. |
|
1179 |
(px < left) ifTrue:[^ false]. |
|
1180 |
(px > (left + width)) ifTrue:[^ false]. |
|
1181 |
py := aPoint y. |
|
1182 |
(py < top) ifTrue:[^ false]. |
|
1183 |
(py > (top + height)) ifTrue:[^ false]. |
|
1184 |
^ true |
|
1 | 1185 |
! |
1186 |
||
637 | 1187 |
containsPointX:x y:y |
1188 |
"return true, if the point defined by x@y is contained in the receiver. |
|
1189 |
This is the same as containsPoint:, but can be used if the coordinates |
|
1190 |
are already available as separate numbers to avoid useless creation of a |
|
1191 |
temporary point." |
|
1192 |
||
1193 |
(x < left) ifTrue:[^ false]. |
|
1194 |
(x > (left + width)) ifTrue:[^ false]. |
|
1195 |
(y < top) ifTrue:[^ false]. |
|
1196 |
(y > (top + height)) ifTrue:[^ false]. |
|
1197 |
^ true |
|
1198 |
! |
|
1199 |
||
1200 |
intersects:aRectangle |
|
1201 |
"return true, if the intersection between the argument, aRectangle |
|
1202 |
and the receiver is not empty" |
|
1203 |
||
1204 |
|b r| |
|
1 | 1205 |
|
1149
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1206 |
%{ /* NOCONTEXT */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1207 |
/* |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1208 |
* 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
|
1209 |
* 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
|
1210 |
* 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
|
1211 |
*/ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1212 |
OBJ slf = self; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1213 |
OBJ rct = aRectangle; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1214 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1215 |
if (__isNonNilObject(rct) |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1216 |
&& __qClass(rct) == Rectangle) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1217 |
OBJ r_l, r_w, r_t, r_h, l, w, t, h; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1218 |
int r_ir, r_il, r_ib, r_it; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1219 |
int il, it, ir, ib, iw, ih; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1220 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1221 |
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
|
1222 |
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
|
1223 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1224 |
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
|
1225 |
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
|
1226 |
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
|
1227 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1228 |
l = __OINST(slf, left); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1229 |
w = __OINST(slf, width); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1230 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1231 |
if (__bothSmallInteger(l, w)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1232 |
t = __OINST(slf, top); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1233 |
h = __OINST(slf, height); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1234 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1235 |
#ifndef POSITIVE_ADDRESSES /* tag in low-bit */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1236 |
r_il = (int)(r_l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1237 |
r_ir = r_il + (int)(r_w) - 1; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1238 |
il = (int)(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1239 |
if (r_ir < il) { RETURN (false); } |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1240 |
ir = il + (int)(w) - 1; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1241 |
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
|
1242 |
#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
|
1243 |
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
|
1244 |
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
|
1245 |
il = __intVal(l); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1246 |
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
|
1247 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1248 |
ir = il + __intVal(w); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1249 |
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
|
1250 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1251 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1252 |
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
|
1253 |
if (__bothSmallInteger(t, h)) { |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1254 |
#ifndef POSITIVE_ADDRESSES |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1255 |
r_it = (int)(r_t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1256 |
r_ib = r_it + (int)(r_h) - 1; /* aRectangle bottom */ |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1257 |
it = (int)(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1258 |
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
|
1259 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1260 |
ib = it + (int)(h) - 1; |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1261 |
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
|
1262 |
#else |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1263 |
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
|
1264 |
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
|
1265 |
it = __intVal(t); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1266 |
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
|
1267 |
|
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1268 |
ib = it + __intVal(h); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1269 |
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
|
1270 |
#endif |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1271 |
RETURN (true); |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1272 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1273 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1274 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1275 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1276 |
} |
69b30e3494fa
added specially tuned code for #intersects: & #contains: (for objectView performance)
Claus Gittinger <cg@exept.de>
parents:
1133
diff
changeset
|
1277 |
%}. |
637 | 1278 |
(aRectangle right) < left ifTrue:[^ false]. |
1279 |
(aRectangle bottom) < top ifTrue:[^ false]. |
|
1280 |
r := left + width. |
|
1281 |
(aRectangle left) > r ifTrue:[^ false]. |
|
1282 |
b := top + height. |
|
1283 |
(aRectangle top) > b ifTrue:[^ false]. |
|
1284 |
^ true |
|
1285 |
! |
|
1286 |
||
1287 |
isContainedIn:aRectangle |
|
1288 |
"return true, if the receiver is fully contained within |
|
1289 |
the argument, aRectangle" |
|
1290 |
||
1291 |
(aRectangle left <= left) ifTrue:[ |
|
1292 |
(aRectangle right >= (left + width)) ifTrue:[ |
|
1293 |
(aRectangle top <= top) ifTrue:[ |
|
1294 |
(aRectangle bottom >= (top + height)) ifTrue:[ |
|
1295 |
^ true |
|
1296 |
] |
|
1297 |
] |
|
1298 |
] |
|
1299 |
]. |
|
1300 |
^ false |
|
1 | 1301 |
! ! |
637 | 1302 |
|
1303 |
!Rectangle class methodsFor:'documentation'! |
|
1304 |
||
1305 |
version |
|
1290 | 1306 |
^ '$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.37 1996-04-25 16:20:46 cg Exp $' |
637 | 1307 |
! ! |