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