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