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