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