1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
Object subclass:#Rectangle
|
|
14 |
instanceVariableNames:'left top width height'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Graphics-Primitives'
|
|
18 |
!
|
|
19 |
|
|
20 |
Rectangle comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
Rectangles represent a rectangular area in 2D space.
|
|
26 |
|
|
27 |
notice, my implementation does not use origin/corner as instance objects
|
|
28 |
but left/top/width/height to save space and allocations. This means, that my
|
|
29 |
Rectangles cannot be used to represent Rectangles in a higher than 2D
|
|
30 |
space. (i.e. only valid if origin/corner are 2D Points)
|
|
31 |
|
|
32 |
(aside from that, you will not see any difference from the outside)
|
|
33 |
|
|
34 |
Instance variables:
|
|
35 |
|
|
36 |
left <Number> the left coordinate (i.e origin x)
|
|
37 |
top <Number> the top coordinate (i.e origin y)
|
|
38 |
width <Number> the width of the rectangle
|
|
39 |
height <Number> the height of the rectangle
|
|
40 |
|
13
|
41 |
$Header: /cvs/stx/stx/libbasic/Rectangle.st,v 1.5 1993-12-11 00:55:38 claus Exp $
|
1
|
42 |
|
|
43 |
written 89 by claus
|
|
44 |
'!
|
|
45 |
|
|
46 |
!Rectangle class methodsFor:'instance creation'!
|
|
47 |
|
|
48 |
origin:origin corner:corner
|
|
49 |
"create and return a new Rectangle giving top-left and bottom-right points"
|
|
50 |
|
|
51 |
^ (self basicNew) origin:origin corner:corner
|
|
52 |
!
|
|
53 |
|
|
54 |
origin:origin extent:extent
|
|
55 |
"create and return a new Rectangle giving top-left point and extent point"
|
|
56 |
|
|
57 |
%{ /* NOCONTEXT */
|
|
58 |
OBJ newRect;
|
|
59 |
extern char *newNextPtr, *newEndPtr;
|
|
60 |
extern OBJ Point;
|
|
61 |
|
|
62 |
/* short cut - rectangles are created so often ... */
|
|
63 |
if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
|
|
64 |
if ((self == Rectangle)
|
|
65 |
&& _isPoint(origin)
|
|
66 |
&& _isPoint(extent)) {
|
13
|
67 |
_qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
|
1
|
68 |
_InstPtr(newRect)->o_class = Rectangle;
|
|
69 |
_InstPtr(newRect)->i_instvars[0] = _PointInstPtr(origin)->p_x;
|
|
70 |
_InstPtr(newRect)->i_instvars[1] = _PointInstPtr(origin)->p_y;
|
|
71 |
_InstPtr(newRect)->i_instvars[2] = _PointInstPtr(extent)->p_x;
|
|
72 |
_InstPtr(newRect)->i_instvars[3] = _PointInstPtr(extent)->p_y;
|
3
|
73 |
__STORE(newRect, _PointInstPtr(origin)->p_x);
|
|
74 |
__STORE(newRect, _PointInstPtr(origin)->p_y);
|
|
75 |
__STORE(newRect, _PointInstPtr(extent)->p_x);
|
|
76 |
__STORE(newRect, _PointInstPtr(extent)->p_y);
|
1
|
77 |
RETURN ( newRect );
|
|
78 |
}
|
|
79 |
}
|
|
80 |
%}
|
|
81 |
.
|
|
82 |
^ (self basicNew) origin:origin extent:extent
|
|
83 |
!
|
|
84 |
|
|
85 |
left:left top:top width:w height:h
|
|
86 |
"create and return a new Rectangle giving left and top coordinates
|
|
87 |
and width, height"
|
|
88 |
|
|
89 |
%{ /* NOCONTEXT */
|
|
90 |
OBJ newRect;
|
|
91 |
extern char *newNextPtr, *newEndPtr;
|
|
92 |
|
|
93 |
if (_CanDoQuickNew(OHDR_SIZE + 4*sizeof(OBJ))) {
|
|
94 |
/* short cut - rectangles are created so often ... */
|
|
95 |
if (self == Rectangle) {
|
13
|
96 |
_qCheckedAlignedNew(newRect, OHDR_SIZE + 4*sizeof(OBJ));
|
1
|
97 |
_InstPtr(newRect)->o_class = Rectangle;
|
|
98 |
_InstPtr(newRect)->i_instvars[0] = left;
|
|
99 |
_InstPtr(newRect)->i_instvars[1] = top;
|
|
100 |
_InstPtr(newRect)->i_instvars[2] = w;
|
|
101 |
_InstPtr(newRect)->i_instvars[3] = h;
|
3
|
102 |
__STORE(newRect, left);
|
|
103 |
__STORE(newRect, top);
|
|
104 |
__STORE(newRect, w);
|
|
105 |
__STORE(newRect, h);
|
1
|
106 |
RETURN ( newRect );
|
|
107 |
}
|
|
108 |
}
|
|
109 |
%}
|
|
110 |
.
|
|
111 |
^ (self basicNew) left:left top:top width:w height:h
|
|
112 |
!
|
|
113 |
|
|
114 |
left:left right:right top:top bottom:bottom
|
|
115 |
"create and return a new Rectangle giving left, top, right and bottom coordinates"
|
|
116 |
|
|
117 |
^ (self basicNew) left:left right:right top:top bottom:bottom
|
|
118 |
!
|
|
119 |
|
|
120 |
left:left top:top right:right bottom:bottom
|
|
121 |
"create and return a new Rectangle giving left, top, right and bottom coordinates"
|
|
122 |
|
|
123 |
^ (self basicNew) left:left top:top right:right bottom:bottom
|
|
124 |
! !
|
|
125 |
|
|
126 |
!Rectangle methodsFor:'accessing'!
|
|
127 |
|
|
128 |
top
|
|
129 |
"return the y-coordinate of the top-left origin"
|
|
130 |
|
|
131 |
^ top
|
|
132 |
!
|
|
133 |
|
|
134 |
left
|
|
135 |
"return the x-coordinate of the top-left origin"
|
|
136 |
|
|
137 |
^ left
|
|
138 |
!
|
|
139 |
|
|
140 |
width
|
|
141 |
"return the width of the rectangle"
|
|
142 |
|
|
143 |
^ width
|
|
144 |
!
|
|
145 |
|
|
146 |
height
|
|
147 |
"return the height of the rectangle"
|
|
148 |
|
|
149 |
^ height
|
|
150 |
!
|
|
151 |
|
|
152 |
left:newLeft right:right top:newTop bottom:bottom
|
|
153 |
"set the rectangle given left, top, right and bottom coordinates"
|
|
154 |
|
|
155 |
left := newLeft.
|
|
156 |
top := newTop.
|
|
157 |
width := right - left.
|
|
158 |
height := bottom - top
|
|
159 |
!
|
|
160 |
|
|
161 |
left:newLeft top:newTop right:right bottom:bottom
|
|
162 |
"set the rectangle given left, top, right and bottom coordinates"
|
|
163 |
|
|
164 |
left := newLeft.
|
|
165 |
top := newTop.
|
|
166 |
width := right - left.
|
|
167 |
height := bottom - top
|
|
168 |
!
|
|
169 |
|
|
170 |
left:newLeft top:newTop width:newWidth height:newHeight
|
|
171 |
"set the rectangle given left, top coordinates and width, height"
|
|
172 |
|
|
173 |
left := newLeft.
|
|
174 |
top := newTop.
|
|
175 |
width := newWidth.
|
|
176 |
height := newHeight
|
|
177 |
!
|
|
178 |
|
|
179 |
origin:aPoint
|
|
180 |
"set the top-left origin"
|
|
181 |
|
|
182 |
left := aPoint x.
|
|
183 |
top := aPoint y
|
|
184 |
!
|
|
185 |
|
|
186 |
corner:aPoint
|
|
187 |
"set the bottom-right corner"
|
|
188 |
|
|
189 |
width := aPoint x - left.
|
|
190 |
height := aPoint y - top
|
|
191 |
!
|
|
192 |
|
|
193 |
top:aNumber
|
|
194 |
"set the top edge"
|
|
195 |
|
|
196 |
height := height + (top - aNumber).
|
|
197 |
top := aNumber
|
|
198 |
!
|
|
199 |
|
|
200 |
bottom:aNumber
|
|
201 |
"set the bottom edge"
|
|
202 |
|
|
203 |
height := aNumber - top
|
|
204 |
!
|
|
205 |
|
|
206 |
origin:origin corner:corner
|
|
207 |
"set both origin and corner"
|
|
208 |
|
|
209 |
left := origin x.
|
|
210 |
top := origin y.
|
|
211 |
width := corner x - left.
|
|
212 |
height := corner y - top
|
|
213 |
!
|
|
214 |
|
|
215 |
extent:aPoint
|
|
216 |
"set the extent from the argument, aPoint with width taken from aPoint x
|
|
217 |
and height taken from aPoint y"
|
|
218 |
|
|
219 |
width := aPoint x.
|
|
220 |
height := aPoint y
|
|
221 |
!
|
|
222 |
|
|
223 |
origin:origin extent:extent
|
|
224 |
"set both origin and extent"
|
|
225 |
|
|
226 |
left := origin x.
|
|
227 |
top := origin y.
|
|
228 |
width := extent x.
|
|
229 |
height := extent y
|
|
230 |
!
|
|
231 |
|
|
232 |
origin
|
|
233 |
"return the origin"
|
|
234 |
|
|
235 |
^ Point x:left y:top
|
|
236 |
!
|
|
237 |
|
|
238 |
left:aNumber
|
|
239 |
"set the left edge"
|
|
240 |
|
|
241 |
width := width + (left - aNumber).
|
|
242 |
left := aNumber
|
|
243 |
!
|
|
244 |
|
|
245 |
right:aNumber
|
|
246 |
"set the right edge"
|
|
247 |
|
|
248 |
width := aNumber - left
|
|
249 |
!
|
|
250 |
|
|
251 |
corner
|
|
252 |
"return the corner"
|
|
253 |
|
|
254 |
^ Point x:(left + width) y:(top + height)
|
|
255 |
!
|
|
256 |
|
|
257 |
extent
|
|
258 |
"return the extent"
|
|
259 |
|
|
260 |
^ Point x:width y:height
|
|
261 |
!
|
|
262 |
|
|
263 |
topLeft
|
|
264 |
"return the top-left point"
|
|
265 |
|
|
266 |
^ Point x:left y:top
|
|
267 |
!
|
|
268 |
|
|
269 |
topRight
|
|
270 |
"return the top-right point"
|
|
271 |
|
|
272 |
^ Point x:(left + width) y:top
|
|
273 |
!
|
|
274 |
|
|
275 |
bottomLeft
|
|
276 |
"return the bottom-left point"
|
|
277 |
|
|
278 |
^ Point x:left y:(top + height)
|
|
279 |
!
|
|
280 |
|
|
281 |
bottomRight
|
|
282 |
"return the bottom-right point"
|
|
283 |
|
|
284 |
^ Point x:(left + width) y:(top + height)
|
|
285 |
!
|
|
286 |
|
|
287 |
bottom
|
|
288 |
"return the y coordinate of the bottom"
|
|
289 |
|
|
290 |
^ (top + height)
|
|
291 |
!
|
|
292 |
|
|
293 |
right
|
|
294 |
"return the x coordinate of the right"
|
|
295 |
|
|
296 |
^ (left + width)
|
|
297 |
!
|
|
298 |
|
|
299 |
center
|
|
300 |
"return the point in the center of the receiver"
|
|
301 |
|
|
302 |
^ Point x:(left + (width // 2)) y:(top + (height // 2))
|
|
303 |
!
|
|
304 |
|
|
305 |
leftCenter
|
|
306 |
"return the left center point"
|
|
307 |
|
|
308 |
^ Point x:left y:(top + (height // 2))
|
|
309 |
!
|
|
310 |
|
|
311 |
rightCenter
|
|
312 |
"return the right center point"
|
|
313 |
|
|
314 |
^ Point x:(left + width) y:(top + (height // 2))
|
|
315 |
!
|
|
316 |
|
|
317 |
area
|
|
318 |
"return the area (- for screen Rectangles this is the number
|
|
319 |
of pixels)"
|
|
320 |
|
|
321 |
^ width * height
|
|
322 |
! !
|
|
323 |
|
|
324 |
!Rectangle methodsFor:'comparing'!
|
|
325 |
|
|
326 |
= aRectangle
|
|
327 |
"return true, if the argument aRectangle represents the same
|
|
328 |
rectangle as the receiver"
|
|
329 |
|
|
330 |
%{ /* NOCONTEXT */
|
|
331 |
static struct inlineCache eq = _ILC1;
|
|
332 |
|
|
333 |
if (_isNonNilObject(aRectangle) && _qClass(aRectangle) == Rectangle) {
|
|
334 |
if (( _InstPtr(self)->i_instvars[0] == _InstPtr(aRectangle)->i_instvars[0] )
|
|
335 |
&& ( _InstPtr(self)->i_instvars[1] == _InstPtr(aRectangle)->i_instvars[1] )
|
|
336 |
&& ( _InstPtr(self)->i_instvars[2] == _InstPtr(aRectangle)->i_instvars[2] )
|
|
337 |
&& ( _InstPtr(self)->i_instvars[3] == _InstPtr(aRectangle)->i_instvars[3] )) {
|
|
338 |
RETURN ( true );
|
|
339 |
}
|
|
340 |
}
|
|
341 |
%}
|
|
342 |
.
|
|
343 |
(aRectangle isKindOf:Rectangle) ifFalse:[^ false].
|
|
344 |
|
|
345 |
left = aRectangle left ifFalse:[^ false].
|
|
346 |
top = aRectangle top ifFalse:[^ false].
|
|
347 |
width = aRectangle width ifFalse:[^ false].
|
|
348 |
height = aRectangle height ifFalse:[^ false].
|
|
349 |
^ true
|
|
350 |
! !
|
|
351 |
|
|
352 |
!Rectangle methodsFor:'testing'!
|
|
353 |
|
|
354 |
containsPoint:aPoint
|
|
355 |
"return true, if the argument, aPoint is contained in the receiver"
|
|
356 |
|
|
357 |
|px py|
|
|
358 |
|
|
359 |
px := aPoint x.
|
|
360 |
(px < left) ifTrue:[^ false].
|
|
361 |
(px > (left + width)) ifTrue:[^ false].
|
|
362 |
py := aPoint y.
|
|
363 |
(py < top) ifTrue:[^ false].
|
|
364 |
(py > (top + height)) ifTrue:[^ false].
|
|
365 |
^ true
|
|
366 |
!
|
|
367 |
|
|
368 |
intersects:aRectangle
|
|
369 |
"return true, if the intersection between the argument, aRectangle
|
|
370 |
and the receiver is not empty"
|
|
371 |
|
|
372 |
|b r|
|
|
373 |
|
|
374 |
(aRectangle right) < left ifTrue:[^ false].
|
|
375 |
(aRectangle bottom) < top ifTrue:[^ false].
|
|
376 |
r := left + width.
|
|
377 |
(aRectangle left) > r ifTrue:[^ false].
|
|
378 |
b := top + height.
|
|
379 |
(aRectangle top) > b ifTrue:[^ false].
|
|
380 |
^ true
|
|
381 |
!
|
|
382 |
|
|
383 |
contains:aRectangle
|
|
384 |
"return true, if the argument, aRectangle is equal to or
|
|
385 |
is contained fully within the receiver"
|
|
386 |
|
|
387 |
(left <= aRectangle left) ifTrue:[
|
|
388 |
((left + width) >= aRectangle right) ifTrue:[
|
|
389 |
(top <= aRectangle top) ifTrue:[
|
|
390 |
((top + height) >= aRectangle bottom) ifTrue:[
|
|
391 |
^ true
|
|
392 |
]
|
|
393 |
]
|
|
394 |
]
|
|
395 |
].
|
|
396 |
^ false
|
|
397 |
!
|
|
398 |
|
|
399 |
isContainedIn:aRectangle
|
|
400 |
"return true, if the receiver is fully contained within
|
|
401 |
the argument, aRectangle"
|
|
402 |
|
|
403 |
(aRectangle left <= left) ifTrue:[
|
|
404 |
(aRectangle right >= (left + width)) ifTrue:[
|
|
405 |
(aRectangle top <= top) ifTrue:[
|
|
406 |
(aRectangle bottom >= (top + height)) ifTrue:[
|
|
407 |
^ true
|
|
408 |
]
|
|
409 |
]
|
|
410 |
]
|
|
411 |
].
|
|
412 |
^ false
|
|
413 |
! !
|
|
414 |
|
|
415 |
!Rectangle methodsFor:'rectangle operations'!
|
|
416 |
|
|
417 |
intersect:aRectangle
|
|
418 |
"return a new rectangle covering the intersection of the receiver
|
|
419 |
and the argument, aRectangle.
|
|
420 |
the rectangles must intersect for a valid return"
|
|
421 |
|
|
422 |
^ Rectangle left:(left max:(aRectangle left))
|
|
423 |
right:((left + width) min:(aRectangle right))
|
|
424 |
top:(top max:(aRectangle top))
|
|
425 |
bottom:((top + height) min:(aRectangle bottom))
|
|
426 |
!
|
|
427 |
|
|
428 |
merge:aRectangle
|
|
429 |
"return a new rectangle covering both the receiver
|
|
430 |
and the argument, aRectangle"
|
|
431 |
|
|
432 |
^ Rectangle left:(left min:(aRectangle left))
|
|
433 |
right:((left + width) max:(aRectangle right))
|
|
434 |
top:(top min:(aRectangle top))
|
|
435 |
bottom:((top + height) max:(aRectangle bottom))
|
|
436 |
!
|
|
437 |
|
|
438 |
+ aPoint
|
|
439 |
"return a Rectangle with same extent as receiver but
|
|
440 |
origin translated by the argument, aPoint"
|
|
441 |
|
|
442 |
^ Rectangle origin:(self origin + aPoint) extent:(self extent)
|
|
443 |
!
|
|
444 |
|
|
445 |
rounded
|
|
446 |
^ Rectangle left:(left rounded) top:(top rounded)
|
|
447 |
width:(width rounded) height:(height rounded)
|
|
448 |
!
|
|
449 |
|
|
450 |
expandBy:amount
|
|
451 |
"return a new rectangle which is expanded in all directions
|
|
452 |
by amount, aPoint or Number"
|
|
453 |
|
|
454 |
|amountPoint|
|
|
455 |
|
|
456 |
amountPoint := amount asPoint.
|
|
457 |
^ Rectangle left:(left - amountPoint x) top:(top - amountPoint y)
|
|
458 |
width:(width + (2 * amountPoint x))
|
|
459 |
height:(height + (2 * amountPoint y))
|
|
460 |
!
|
|
461 |
|
|
462 |
insetBy: delta
|
|
463 |
"return a new rectangle which is inset in all directions
|
|
464 |
by delta, aPoint or Rectangle"
|
|
465 |
|
|
466 |
| newrect |
|
|
467 |
|
|
468 |
newrect := delta asRectangle.
|
|
469 |
^Rectangle origin: (self origin + (newrect origin))
|
|
470 |
corner: (self corner - (newrect corner))
|
|
471 |
!
|
|
472 |
|
|
473 |
translateBy:amount
|
3
|
474 |
"destructively translate (i.e. move) the receiver rectangle
|
|
475 |
by amount, aPoint or Number"
|
|
476 |
|
|
477 |
|amountPoint|
|
|
478 |
|
|
479 |
amountPoint := amount asPoint.
|
|
480 |
left := left + amountPoint x.
|
|
481 |
top := top + amountPoint y
|
|
482 |
!
|
|
483 |
|
|
484 |
translatedBy:amount
|
1
|
485 |
"return a new rectangle which is translated (i.e. moved)
|
|
486 |
by amount, aPoint or Number"
|
|
487 |
|
|
488 |
|amountPoint|
|
|
489 |
|
|
490 |
amountPoint := amount asPoint.
|
|
491 |
^ Rectangle left:(left + amountPoint x) top:(top + amountPoint y)
|
|
492 |
width:(width)
|
|
493 |
height:(height)
|
|
494 |
!
|
|
495 |
|
|
496 |
moveTo: aPoint
|
|
497 |
"destructively translate the rectangle"
|
|
498 |
|
|
499 |
| diff |
|
|
500 |
|
|
501 |
diff := aPoint - self origin.
|
|
502 |
self origin:aPoint corner:self corner + diff
|
|
503 |
!
|
|
504 |
|
|
505 |
moveBy: aPoint
|
|
506 |
"destructively translate the rectangle
|
|
507 |
sorry for the name inconsistency - but GNU-ST named it that way"
|
|
508 |
|
|
509 |
left := left + aPoint x.
|
|
510 |
top := top + aPoint y
|
|
511 |
!
|
|
512 |
|
|
513 |
scaleBy:scale
|
|
514 |
"destructively scale the receiver rectangle by scale"
|
|
515 |
|
|
516 |
|scalePoint|
|
|
517 |
|
|
518 |
scalePoint := scale asPoint.
|
|
519 |
width := (width * scalePoint x).
|
|
520 |
height := (height * scalePoint y)
|
|
521 |
!
|
|
522 |
|
|
523 |
scaledBy:scale
|
|
524 |
"return a new rectangle which is the receiver
|
|
525 |
scaled by scale"
|
|
526 |
|
|
527 |
|scalePoint|
|
|
528 |
|
|
529 |
scalePoint := scale asPoint.
|
|
530 |
^ Rectangle left:left top:top
|
|
531 |
width:(width * scalePoint x)
|
|
532 |
height:(height * scalePoint y)
|
|
533 |
!
|
|
534 |
|
|
535 |
amountToTranslateWithin: aRectangle
|
|
536 |
"for GNU-ST compatibility"
|
|
537 |
|
|
538 |
^(aRectangle origin) - self origin
|
|
539 |
!
|
|
540 |
|
|
541 |
areasOutside: aRectangle
|
|
542 |
"----------------------------------------------------------------
|
|
543 |
| added for GNU-ST compatibility
|
|
544 |
|
|
|
545 |
| author: Doug McCallum <uunet!!ico.isc.com!!dougm>
|
|
546 |
|
|
|
547 |
|areasOutside: aRectangle
|
|
548 |
| most complicated of the Rectangle primitives
|
|
549 |
| The basic methodology is to first determine that there is an
|
|
550 |
| intersection by finding the overlapping rectangle. From the
|
|
551 |
| overlapping rectangle, first determine if it runs along an edge.
|
|
552 |
| If it doesn't, extend the rectangle up to the top edge and add
|
|
553 |
| the new rectangle to the collection and start the rest of the
|
|
554 |
| process. If the left edge does not touch the left edge of self,
|
|
555 |
| extend it to the edge saving the new rectangle. Then do the
|
|
556 |
| same to the right edge. Then check top and bottom edges. Most
|
|
557 |
| of the time only 2 or 3 rectangles get formed, occasionally 4.
|
|
558 |
| It should be possible to never get more than 3 but requires more
|
|
559 |
| work.
|
|
560 |
----------------------------------------------------------------"
|
|
561 |
|
|
562 |
| collect iRect tmp |
|
|
563 |
iRect _ self intersect: aRectangle.
|
|
564 |
(iRect = nil) ifTrue: [^nil]. "case of no intersection"
|
|
565 |
"the collect collection gathers Rectangles"
|
|
566 |
collect _ OrderedCollection new: 4.
|
|
567 |
"is it floating or on the edge?"
|
|
568 |
(((((iRect top) ~= self top)
|
|
569 |
and: [ (iRect bottom) ~= self bottom ])
|
|
570 |
and: [ (iRect left) ~= self left ])
|
|
571 |
and: [ (iRect right) ~= self right ] )
|
|
572 |
ifTrue: "entirely in the center."
|
|
573 |
[tmp _ Rectangle origin: (Point x: iRect left y: self top)
|
|
574 |
corner: iRect bottomRight.
|
|
575 |
collect add: tmp.
|
|
576 |
iRect _ iRect merge: tmp].
|
|
577 |
((iRect left) ~= self left)
|
|
578 |
ifTrue: "doesn't touch left edge so make it touch"
|
|
579 |
[tmp _ Rectangle origin: (Point x: self left y: iRect top)
|
|
580 |
corner: iRect bottomLeft.
|
|
581 |
collect add: tmp.
|
|
582 |
"merge new (tmp) with overlap to keep track"
|
|
583 |
iRect _ iRect merge: tmp].
|
|
584 |
((iRect right) ~= self right)
|
|
585 |
ifTrue: "doesn't touch right edge so extend it"
|
|
586 |
[tmp _ Rectangle origin: iRect topRight
|
|
587 |
corner: (Point x: self right y: iRect bottom).
|
|
588 |
collect add: tmp.
|
|
589 |
iRect _ iRect merge: tmp].
|
|
590 |
(((iRect left) ~= self left) || [(iRect top) ~= self top])
|
|
591 |
ifTrue: "whole top part can be taken now"
|
|
592 |
[tmp _ Rectangle origin: self origin corner: iRect topRight.
|
|
593 |
collect add: tmp].
|
|
594 |
(((iRect right) ~= self right) || [(iRect bottom) ~= self bottom])
|
|
595 |
ifTrue: "whole bottom open and can be taken"
|
|
596 |
[tmp _ Rectangle origin: iRect bottomLeft corner: self corner.
|
|
597 |
collect add: tmp].
|
|
598 |
^collect
|
|
599 |
|
|
600 |
! !
|
|
601 |
|
|
602 |
!Rectangle methodsFor:'printing'!
|
|
603 |
|
|
604 |
printString
|
|
605 |
"return a string for printing"
|
|
606 |
|
|
607 |
^ 'Rectangle origin:'
|
|
608 |
, self origin printString
|
|
609 |
, ' corner:'
|
|
610 |
, self corner printString
|
|
611 |
!
|
|
612 |
|
|
613 |
printOn:aStream
|
|
614 |
"print the receiver on aStream"
|
|
615 |
|
|
616 |
aStream nextPutAll:'Rectangle origin:'.
|
|
617 |
(self origin) printOn:aStream.
|
|
618 |
aStream nextPutAll:' corner:'.
|
|
619 |
(self corner) printOn:aStream
|
|
620 |
!
|
|
621 |
|
|
622 |
storeOn:aStream
|
|
623 |
"store the receiver on aStream; i.e. print an expression which will
|
|
624 |
reconstruct the receiver"
|
|
625 |
|
|
626 |
aStream nextPutAll:'('.
|
|
627 |
aStream nextPutAll:(self class name).
|
|
628 |
aStream nextPutAll:' new origin:'.
|
|
629 |
aStream nextPutAll:(self origin printString).
|
|
630 |
aStream nextPutAll:' corner:'.
|
|
631 |
aStream nextPutAll:(self corner printString).
|
|
632 |
aStream nextPutAll:'('
|
|
633 |
! !
|