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