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