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