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