author | Stefan Vogel <sv@exept.de> |
Fri, 03 Apr 2020 18:50:48 +0200 | |
changeset 5471 | 0bee7a5e40e8 |
parent 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 |
" |
|
1303 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
14 |
Geometric subclass:#Circle |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
15 |
instanceVariableNames:'center radius' |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
16 |
classVariableNames:'' |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
17 |
poolDictionaries:'' |
1303 | 18 |
category:'Graphics-Geometry-Objects' |
78 | 19 |
! |
20 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
21 |
!Circle class methodsFor:'documentation'! |
78 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
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 |
||
37 |
documentation |
|
38 |
" |
|
39 |
This class implements a circles which are defined by a radius and |
|
40 |
a centerpoint. |
|
281 | 41 |
|
42 |
[author:] |
|
43 |
Claus Gittinger |
|
44 |
||
45 |
[see also:] |
|
331 | 46 |
EllipticalArc Spline Curve Polygon Rectangle LineSegment |
47 |
Arrow ArrowedSpline |
|
281 | 48 |
GraphicsContext |
331 | 49 |
StrokingWrapper FillingWrapper |
78 | 50 |
" |
289 | 51 |
! |
52 |
||
53 |
examples |
|
54 |
" |
|
55 |
circle; filled and unfilled: |
|
56 |
[exBegin] |
|
57 |
|v c| |
|
58 |
||
59 |
v := (View extent:200@100) openAndWait. |
|
60 |
||
61 |
c := Circle boundingBox:(10@10 corner:90@90). |
|
62 |
||
63 |
v paint:Color blue. |
|
64 |
c displayFilledOn:v. |
|
65 |
||
66 |
c center:150@50. |
|
67 |
v paint:Color red. |
|
68 |
c displayStrokedOn:v. |
|
69 |
||
70 |
[exEnd] |
|
71 |
circle & rectangle; both filled: |
|
72 |
[exBegin] |
|
73 |
|v c| |
|
74 |
||
75 |
v := (View extent:100@100) openAndWait. |
|
76 |
||
77 |
c := Circle center:50@50 radius:40. |
|
78 |
||
79 |
v paint:Color red. |
|
80 |
c asRectangle displayFilledOn:v. |
|
81 |
||
82 |
v paint:Color blue. |
|
83 |
c displayFilledOn:v. |
|
84 |
||
85 |
[exEnd] |
|
86 |
circles; filled & unfilled: |
|
87 |
[exBegin] |
|
88 |
|v c| |
|
89 |
||
90 |
v := View new openAndWait. |
|
91 |
||
92 |
c := Circle center:50@50 radius:40. |
|
93 |
||
94 |
v paint:Color red. |
|
95 |
c displayFilledOn:v. |
|
96 |
50 to:1 by:-1 do:[:r | |
|
97 |
c radius:r. |
|
98 |
v paint:(Color grey:(r * 2)). |
|
99 |
c displayStrokedOn:v. |
|
100 |
]. |
|
101 |
1 to:50 do:[:r | |
|
102 |
c radius:r. |
|
103 |
v paint:(Color grey:100-(r * 2)). |
|
104 |
c displayStrokedOn:v. |
|
105 |
] |
|
106 |
||
107 |
[exEnd] |
|
108 |
more arcs; filled: |
|
109 |
[exBegin] |
|
110 |
|v ell| |
|
111 |
||
112 |
v := View new openAndWait. |
|
113 |
||
114 |
ell := EllipticalArc |
|
115 |
boundingBox:(10@10 corner:90@90) |
|
116 |
startAngle:0 |
|
117 |
sweepAngle:0. |
|
118 |
||
119 |
#(45 90 135 180 225 270 315 360) |
|
120 |
keysAndValuesReverseDo:[:index :angle | |
|
121 |
index odd ifTrue:[ |
|
122 |
v paint:Color white |
|
123 |
] ifFalse:[ |
|
124 |
v paint:Color black |
|
125 |
]. |
|
126 |
ell sweepAngle:angle. |
|
127 |
ell displayFilledOn:v. |
|
128 |
Delay waitForSeconds:0.1. |
|
129 |
]. |
|
130 |
||
131 |
[exEnd] |
|
132 |
more arcs; filled: |
|
133 |
[exBegin] |
|
134 |
|v ell| |
|
135 |
||
136 |
v := View new openAndWait. |
|
137 |
||
138 |
ell := EllipticalArc |
|
139 |
boundingBox:(10@10 corner:90@90) |
|
140 |
startAngle:0 |
|
141 |
sweepAngle:45. |
|
142 |
||
143 |
#(45 90 135 180 225 270 315 360) |
|
144 |
with:#( 0.125 0.25 0.375 0.5 0.625 0.75 0.875 1) |
|
145 |
do:[:angle :grey | |
|
146 |
ell startAngle:angle-45. |
|
147 |
v paint:(ColorValue red:grey green:0 blue:0). |
|
148 |
ell displayFilledOn:v. |
|
149 |
]. |
|
150 |
||
151 |
[exEnd] |
|
152 |
" |
|
78 | 153 |
! ! |
154 |
||
155 |
!Circle class methodsFor:'instance creation'! |
|
156 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
157 |
boundingBox:aRectangle |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
158 |
"Return a new Circle centered in aRectangle." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
159 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
160 |
^ self |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
161 |
center:(aRectangle center) |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
162 |
radius:(aRectangle width min:aRectangle height) / 2 |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
163 |
! |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
164 |
|
78 | 165 |
center:centerPoint radius:radius |
166 |
"Return a new Circle." |
|
167 |
||
283 | 168 |
^ self new center:centerPoint radius:radius |
78 | 169 |
|
283 | 170 |
"Modified: 8.5.1996 / 20:39:30 / cg" |
78 | 171 |
! ! |
172 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
173 |
!Circle methodsFor:'accessing'! |
78 | 174 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
175 |
center |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
176 |
"return the center." |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
177 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
178 |
^ center |
78 | 179 |
! |
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 |
"set the center point." |
78 | 183 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
184 |
center := aPoint |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
185 |
! |
78 | 186 |
|
187 |
center:centerPoint radius:radiusNumber |
|
188 |
"set the center and radius" |
|
189 |
||
190 |
center := centerPoint. |
|
191 |
radius := radiusNumber |
|
192 |
! |
|
193 |
||
194 |
radius |
|
195 |
"return the radius." |
|
196 |
||
197 |
^ radius |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
198 |
! |
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 |
"set the radius." |
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 |
radius := aNumber |
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 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
206 |
!Circle methodsFor:'converting'! |
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 |
asEllipticalArc |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
209 |
"convert the receiver into an ellipticalArc" |
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 |
^ EllipticalArc center:center radius:radius |
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 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
214 |
!Circle methodsFor:'displaying'! |
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 |
displayFilledOn:aGC |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
217 |
"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
|
218 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
219 |
aGC fillCircle:center radius:radius |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
220 |
! |
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 |
displayStrokedOn:aGC |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
223 |
"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
|
224 |
|
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
225 |
aGC displayCircle:center radius:radius |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
226 |
|
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 |
!Circle methodsFor:'queries'! |
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 |
area |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
232 |
"return the area of the receiver." |
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 |
^ radius * radius * (Float pi) |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
235 |
! |
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 |
bounds |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
238 |
"return the smallest enclosing rectangle" |
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 |
^ Rectangle origin:(center - radius) corner:(center + radius) |
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 |
(Circle center:100@100 radius:50) bounds |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
244 |
" |
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 |
diameter |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
248 |
"return the diameter of the receiver." |
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 |
^ radius * 2 |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
251 |
! |
78 | 252 |
|
253 |
startAngle |
|
254 |
"return the startAngle. |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
255 |
Provided for protocol compatibility with arcs and ellipese; |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
256 |
for circles, this is an arbitrary angle." |
78 | 257 |
|
258 |
^ 0 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
259 |
! |
78 | 260 |
|
261 |
sweepAngle |
|
262 |
"return the sweepAngle. |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
263 |
Provided for protocol compatibility with arcs and ellipese; |
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
264 |
for circles, this is always 360 degrees." |
78 | 265 |
|
266 |
^ 360 |
|
267 |
! ! |
|
268 |
||
2155 | 269 |
!Circle methodsFor:'testing'! |
270 |
||
271 |
canBeFilled |
|
272 |
"return true, if the receiver can be drawn filled; always true here" |
|
273 |
||
274 |
^ true |
|
275 |
! ! |
|
276 |
||
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
277 |
!Circle class methodsFor:'documentation'! |
78 | 278 |
|
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
279 |
version |
2155 | 280 |
^ '$Header: /cvs/stx/stx/libbasic2/Circle.st,v 1.13 2009-06-06 10:12:18 cg Exp $' |
275
4a9fed506144
doku, comments & more functionality
Claus Gittinger <cg@exept.de>
parents:
112
diff
changeset
|
281 |
! ! |