author | Stefan Vogel <sv@exept.de> |
Fri, 18 Jan 2008 20:40:51 +0100 | |
changeset 1922 | be14f1a04953 |
parent 1303 | 6ca5f36cdc63 |
child 2155 | 15a41c701d00 |
permissions | -rw-r--r-- |
86 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
112
3e18f2cfe430
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
3 |
All Rights Reserved |
86 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
1303 | 13 |
"{ Package: 'stx:libbasic2' }" |
14 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
15 |
Geometric subclass:#Circle |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
16 |
instanceVariableNames:'center radius' |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
17 |
classVariableNames:'' |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
18 |
poolDictionaries:'' |
1303 | 19 |
category:'Graphics-Geometry-Objects' |
78 | 20 |
! |
21 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
22 |
!Circle class methodsFor:'documentation'! |
78 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
This class implements a circles which are defined by a radius and |
|
41 |
a centerpoint. |
|
281 | 42 |
|
43 |
[author:] |
|
44 |
Claus Gittinger |
|
45 |
||
46 |
[see also:] |
|
331 | 47 |
EllipticalArc Spline Curve Polygon Rectangle LineSegment |
48 |
Arrow ArrowedSpline |
|
281 | 49 |
GraphicsContext |
331 | 50 |
StrokingWrapper FillingWrapper |
78 | 51 |
" |
289 | 52 |
! |
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
circle; filled and unfilled: |
|
57 |
[exBegin] |
|
58 |
|v c| |
|
59 |
||
60 |
v := (View extent:200@100) openAndWait. |
|
61 |
||
62 |
c := Circle boundingBox:(10@10 corner:90@90). |
|
63 |
||
64 |
v paint:Color blue. |
|
65 |
c displayFilledOn:v. |
|
66 |
||
67 |
c center:150@50. |
|
68 |
v paint:Color red. |
|
69 |
c displayStrokedOn:v. |
|
70 |
||
71 |
[exEnd] |
|
72 |
circle & rectangle; both filled: |
|
73 |
[exBegin] |
|
74 |
|v c| |
|
75 |
||
76 |
v := (View extent:100@100) openAndWait. |
|
77 |
||
78 |
c := Circle center:50@50 radius:40. |
|
79 |
||
80 |
v paint:Color red. |
|
81 |
c asRectangle displayFilledOn:v. |
|
82 |
||
83 |
v paint:Color blue. |
|
84 |
c displayFilledOn:v. |
|
85 |
||
86 |
[exEnd] |
|
87 |
circles; filled & unfilled: |
|
88 |
[exBegin] |
|
89 |
|v c| |
|
90 |
||
91 |
v := View new openAndWait. |
|
92 |
||
93 |
c := Circle center:50@50 radius:40. |
|
94 |
||
95 |
v paint:Color red. |
|
96 |
c displayFilledOn:v. |
|
97 |
50 to:1 by:-1 do:[:r | |
|
98 |
c radius:r. |
|
99 |
v paint:(Color grey:(r * 2)). |
|
100 |
c displayStrokedOn:v. |
|
101 |
]. |
|
102 |
1 to:50 do:[:r | |
|
103 |
c radius:r. |
|
104 |
v paint:(Color grey:100-(r * 2)). |
|
105 |
c displayStrokedOn:v. |
|
106 |
] |
|
107 |
||
108 |
[exEnd] |
|
109 |
more arcs; filled: |
|
110 |
[exBegin] |
|
111 |
|v ell| |
|
112 |
||
113 |
v := View new openAndWait. |
|
114 |
||
115 |
ell := EllipticalArc |
|
116 |
boundingBox:(10@10 corner:90@90) |
|
117 |
startAngle:0 |
|
118 |
sweepAngle:0. |
|
119 |
||
120 |
#(45 90 135 180 225 270 315 360) |
|
121 |
keysAndValuesReverseDo:[:index :angle | |
|
122 |
index odd ifTrue:[ |
|
123 |
v paint:Color white |
|
124 |
] ifFalse:[ |
|
125 |
v paint:Color black |
|
126 |
]. |
|
127 |
ell sweepAngle:angle. |
|
128 |
ell displayFilledOn:v. |
|
129 |
Delay waitForSeconds:0.1. |
|
130 |
]. |
|
131 |
||
132 |
[exEnd] |
|
133 |
more arcs; filled: |
|
134 |
[exBegin] |
|
135 |
|v ell| |
|
136 |
||
137 |
v := View new openAndWait. |
|
138 |
||
139 |
ell := EllipticalArc |
|
140 |
boundingBox:(10@10 corner:90@90) |
|
141 |
startAngle:0 |
|
142 |
sweepAngle:45. |
|
143 |
||
144 |
#(45 90 135 180 225 270 315 360) |
|
145 |
with:#( 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1) |
|
146 |
do:[:angle :grey | |
|
147 |
ell startAngle:angle-45. |
|
148 |
v paint:(ColorValue red:grey green:0 blue:0). |
|
149 |
ell displayFilledOn:v. |
|
150 |
]. |
|
151 |
||
152 |
[exEnd] |
|
153 |
" |
|
78 | 154 |
! ! |
155 |
||
156 |
!Circle class methodsFor:'instance creation'! |
|
157 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
158 |
boundingBox:aRectangle |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
159 |
"Return a new Circle centered in aRectangle." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
160 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
161 |
^ self |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
162 |
center:(aRectangle center) |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
163 |
radius:(aRectangle width min:aRectangle height) / 2 |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
164 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
165 |
|
78 | 166 |
center:centerPoint radius:radius |
167 |
"Return a new Circle." |
|
168 |
||
283 | 169 |
^ self new center:centerPoint radius:radius |
78 | 170 |
|
283 | 171 |
"Modified: 8.5.1996 / 20:39:30 / cg" |
78 | 172 |
! ! |
173 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
174 |
!Circle methodsFor:'accessing'! |
78 | 175 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
176 |
center |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
177 |
"return the center." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
178 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
179 |
^ center |
78 | 180 |
! |
181 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
182 |
center:aPoint |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
183 |
"set the center point." |
78 | 184 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
185 |
center := aPoint |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
186 |
! |
78 | 187 |
|
188 |
center:centerPoint radius:radiusNumber |
|
189 |
"set the center and radius" |
|
190 |
||
191 |
center := centerPoint. |
|
192 |
radius := radiusNumber |
|
193 |
! |
|
194 |
||
195 |
radius |
|
196 |
"return the radius." |
|
197 |
||
198 |
^ radius |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
199 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
200 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
201 |
radius:aNumber |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
202 |
"set the radius." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
203 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
204 |
radius := aNumber |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
205 |
! ! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
206 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
207 |
!Circle methodsFor:'converting'! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
208 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
209 |
asEllipticalArc |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
210 |
"convert the receiver into an ellipticalArc" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
211 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
212 |
^ EllipticalArc center:center radius:radius |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
213 |
! ! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
214 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
215 |
!Circle methodsFor:'displaying'! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
216 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
217 |
displayFilledOn:aGC |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
218 |
"draw the receiver as a filled circle in a graphicsContext, aGC" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
219 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
220 |
aGC fillCircle:center radius:radius |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
221 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
222 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
223 |
displayStrokedOn:aGC |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
224 |
"draw the receiver as a unfilled circle in a graphicsContext, aGC" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
225 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
226 |
aGC displayCircle:center radius:radius |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
227 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
228 |
! ! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
229 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
230 |
!Circle methodsFor:'queries'! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
231 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
232 |
area |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
233 |
"return the area of the receiver." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
234 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
235 |
^ radius * radius * (Float pi) |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
236 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
237 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
238 |
bounds |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
239 |
"return the smallest enclosing rectangle" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
240 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
241 |
^ Rectangle origin:(center - radius) corner:(center + radius) |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
242 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
243 |
" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
244 |
(Circle center:100@100 radius:50) bounds |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
245 |
" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
246 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
247 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
248 |
canBeFilled |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
249 |
"return true, if the receiver can be drawn filled; always true here" |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
250 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
251 |
^ true |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
252 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
253 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
254 |
diameter |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
255 |
"return the diameter of the receiver." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
256 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
257 |
^ radius * 2 |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
258 |
! |
78 | 259 |
|
260 |
startAngle |
|
261 |
"return the startAngle. |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
262 |
Provided for protocol compatibility with arcs and ellipese; |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
263 |
for circles, this is an arbitrary angle." |
78 | 264 |
|
265 |
^ 0 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
266 |
! |
78 | 267 |
|
268 |
sweepAngle |
|
269 |
"return the sweepAngle. |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
270 |
Provided for protocol compatibility with arcs and ellipese; |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
271 |
for circles, this is always 360 degrees." |
78 | 272 |
|
273 |
^ 360 |
|
274 |
! ! |
|
275 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
276 |
!Circle class methodsFor:'documentation'! |
78 | 277 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
278 |
version |
1303 | 279 |
^ '$Header: /cvs/stx/stx/libbasic2/Circle.st,v 1.12 2003-08-29 17:32:06 cg Exp $' |
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
280 |
! ! |