author | Claus Gittinger <cg@exept.de> |
Thu, 22 Jan 2009 00:22:24 +0100 | |
changeset 2091 | 24965fa2be83 |
parent 1430 | baf6bfed6d56 |
child 2158 | cc8120b2afc9 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1988 by Claus Gittinger |
68 | 3 |
All Rights Reserved |
0 | 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 |
||
78 | 14 |
Geometric subclass:#Polygon |
252 | 15 |
instanceVariableNames:'vertices' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
1303 | 18 |
category:'Graphics-Geometry-Objects' |
0 | 19 |
! |
20 |
||
135 | 21 |
!Polygon class methodsFor:'documentation'! |
31 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1988 by Claus Gittinger |
|
68 | 26 |
All Rights Reserved |
0 | 27 |
|
31 | 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 |
Polygon - an array of points |
|
78 | 40 |
|
31 | 41 |
Adds simple boundary checking methods to Array. |
42 |
(needs much more - such as inside check, area computation etc.) |
|
255 | 43 |
|
44 |
[author:] |
|
45 |
Claus Gittinger |
|
267 | 46 |
|
47 |
[see also:] |
|
331 | 48 |
Rectangle EllipticalArc Spline Circle Point LineSegment Curve |
49 |
Arrow ArroedSpline |
|
50 |
GraphicsContext StrokingWrapper FillingWrapper |
|
280 | 51 |
" |
52 |
! |
|
53 |
||
54 |
examples |
|
55 |
" |
|
56 |
simple polygon; filled & unfilled: |
|
57 |
[exBegin] |
|
58 |
|v p| |
|
59 |
||
60 |
v := (View extent:200@200) openAndWait. |
|
61 |
||
62 |
p := Polygon vertices: |
|
63 |
(Array with:(10@10) |
|
64 |
with:(90@90) |
|
65 |
with:(10@90)). |
|
66 |
||
67 |
v scale:2. |
|
68 |
v paint:Color blue. |
|
69 |
p displayFilledOn:v. |
|
70 |
||
71 |
v paint:Color red. |
|
72 |
p displayStrokedOn:v. |
|
73 |
||
74 |
v scale:1; translation:100@0. |
|
75 |
v paint:Color green. |
|
76 |
p displayFilledOn:v. |
|
77 |
||
78 |
v paint:Color black. |
|
79 |
p displayStrokedOn:v. |
|
80 |
[exEnd] |
|
81 |
||
82 |
arbitrary polygon; filled & unfilled: |
|
83 |
[exBegin] |
|
84 |
|v p| |
|
85 |
||
86 |
v := (View extent:200@200) openAndWait. |
|
87 |
v scale:2. |
|
88 |
||
89 |
p := Polygon vertices: |
|
90 |
(Array with:(10@10) |
|
91 |
with:(90@90) |
|
92 |
with:(50@90) |
|
93 |
with:(90@10) |
|
94 |
with:(10@90) |
|
95 |
). |
|
96 |
||
97 |
v paint:Color blue. |
|
98 |
p displayFilledOn:v. |
|
99 |
||
100 |
v paint:Color red. |
|
101 |
p displayStrokedOn:v. |
|
102 |
[exEnd] |
|
31 | 103 |
" |
104 |
! ! |
|
0 | 105 |
|
135 | 106 |
!Polygon class methodsFor:'instance creation'! |
107 |
||
108 |
fromRectangle:aRectangle |
|
280 | 109 |
"return a new polygon, taking the rectangles vertices" |
110 |
||
111 |
^ self new vertices:(aRectangle asPointArray) |
|
135 | 112 |
|
113 |
" |
|
114 |
Polygon fromRectangle:(50@50 corner:100@100) |
|
115 |
" |
|
280 | 116 |
|
117 |
"Modified: 8.5.1996 / 20:15:18 / cg" |
|
135 | 118 |
! |
78 | 119 |
|
120 |
vertices:anArrayOfPoints |
|
280 | 121 |
"return a new polygon, given a collection of vertices" |
122 |
||
78 | 123 |
^ self new vertices:anArrayOfPoints |
124 |
||
125 |
" |
|
126 |
Polygon vertices:(Array with:10@10 |
|
280 | 127 |
with:20@20 |
128 |
with:30@30) |
|
78 | 129 |
|
1430 | 130 |
Polygon vertices:(#(10 10 100 0 50 50) pairWiseCollect:[:x :y | x @ y]). |
131 |
" |
|
132 |
||
133 |
" |
|
134 |
|p v| |
|
135 |
||
136 |
v := View new openAndWait. |
|
137 |
p := Polygon |
|
138 |
vertices:(Array with:10@10 |
|
139 |
with:20@10 |
|
140 |
with:20@30). |
|
141 |
p displayOn:v |
|
78 | 142 |
" |
280 | 143 |
|
144 |
"Modified: 8.5.1996 / 20:11:31 / cg" |
|
135 | 145 |
! ! |
146 |
||
147 |
!Polygon methodsFor:'accessing'! |
|
148 |
||
149 |
vertices |
|
150 |
"return the array containing my points" |
|
78 | 151 |
|
135 | 152 |
^ vertices |
153 |
! |
|
78 | 154 |
|
135 | 155 |
vertices:anArrayOfPoints |
156 |
"set the array containing my points" |
|
157 |
||
158 |
vertices := anArrayOfPoints |
|
78 | 159 |
! ! |
160 |
||
283 | 161 |
!Polygon methodsFor:'converting'! |
162 |
||
163 |
asPointArray |
|
164 |
"return an array containing my vertex points. |
|
165 |
Notice, that no copy of my vertices is created - you should not |
|
166 |
modify the returned collections points (unless you want to affect |
|
167 |
the polygon ...)." |
|
168 |
||
169 |
^ vertices |
|
170 |
||
171 |
"Modified: 8.5.1996 / 20:43:39 / cg" |
|
172 |
! ! |
|
173 |
||
135 | 174 |
!Polygon methodsFor:'displaying'! |
78 | 175 |
|
135 | 176 |
displayFilledOn:aGC |
267 | 177 |
"display a filled polygin as represented by the receiver in |
178 |
the graphicsContext, aGC" |
|
179 |
||
135 | 180 |
aGC fillPolygon:vertices |
78 | 181 |
|
182 |
" |
|
135 | 183 |
|v| |
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
184 |
v := View new openAndWait. |
135 | 185 |
|
186 |
(Polygon vertices:( |
|
267 | 187 |
Array |
188 |
with:10@10 |
|
189 |
with:60@10 |
|
190 |
with:35@60)) displayFilledOn:v |
|
135 | 191 |
|
192 |
|v| |
|
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
193 |
v := View new openAndWait. |
78 | 194 |
|
135 | 195 |
(Polygon vertices:( |
267 | 196 |
Array |
197 |
with:10@10 |
|
198 |
with:60@10 |
|
199 |
with:35@60 |
|
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
200 |
with:10@10)) displayStrokedOn:v |
78 | 201 |
" |
267 | 202 |
|
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
203 |
"Modified: 8.5.1996 / 14:41:47 / cg" |
78 | 204 |
! |
205 |
||
135 | 206 |
displayStrokedOn:aGC |
267 | 207 |
"display an unfilled polygin as represented by the receiver in |
208 |
the graphicsContext, aGC" |
|
209 |
||
135 | 210 |
aGC displayPolygon:vertices |
211 |
||
212 |
" |
|
213 |
|v| |
|
214 |
||
215 |
v := View new open. |
|
216 |
[v shown] whileFalse:[Processor yield]. |
|
217 |
||
218 |
(Polygon vertices:( |
|
267 | 219 |
Array |
220 |
with:10@10 |
|
221 |
with:60@10 |
|
222 |
with:35@60)) displayStrokedOn:v |
|
135 | 223 |
|
224 |
|v| |
|
225 |
||
226 |
v := View new open. |
|
227 |
[v shown] whileFalse:[Processor yield]. |
|
228 |
||
229 |
(Polygon vertices:( |
|
267 | 230 |
Array |
231 |
with:10@10 |
|
232 |
with:60@10 |
|
233 |
with:35@60 |
|
234 |
with:10@10)) displayStrokedOn:v |
|
135 | 235 |
" |
236 |
||
267 | 237 |
"Modified: 27.4.1996 / 14:52:29 / cg" |
135 | 238 |
! ! |
239 |
||
240 |
!Polygon methodsFor:'enumerating'! |
|
241 |
||
78 | 242 |
edgesDo:aTwoArgBlock |
243 |
"evaluate aTwoArgBlock for each pair of vertices" |
|
244 |
||
245 |
1 to:vertices size-1 do:[:i | |
|
246 |
aTwoArgBlock value:(vertices at:i) value:(vertices at:i+1) |
|
247 |
]. |
|
248 |
||
249 |
" |
|
250 |
|v p| |
|
251 |
||
252 |
v := View new open. |
|
253 |
[v shown] whileFalse:[Processor yield]. |
|
254 |
||
255 |
p := Polygon vertices:(Array with:5@5 |
|
256 |
with:50@5 |
|
257 |
with:30@30 |
|
258 |
with:5@5). |
|
259 |
||
260 |
p displayOn:v. |
|
261 |
(Delay forSeconds:3) wait. |
|
262 |
||
263 |
p edgesDo:[:p1 :p2 | v lineWidth:3. v displayLineFrom:p1 to:p2] |
|
264 |
" |
|
265 |
! |
|
266 |
||
135 | 267 |
verticesDo:aBlock |
268 |
"evaluate aBlock for each point" |
|
269 |
||
270 |
vertices do:aBlock |
|
271 |
||
272 |
" |
|
273 |
|v p| |
|
274 |
||
275 |
v := View new open. |
|
276 |
[v shown] whileFalse:[Processor yield]. |
|
78 | 277 |
|
135 | 278 |
p := Polygon vertices:(Array with:5@5 |
279 |
with:50@5 |
|
280 |
with:30@30 |
|
281 |
with:5@5). |
|
282 |
||
283 |
p displayOn:v. |
|
284 |
(Delay forSeconds:3) wait. |
|
285 |
||
286 |
p verticesDo:[:p | v displayRectangleX:p x -3 y:p y -3 width:6 height:6] |
|
287 |
" |
|
78 | 288 |
! ! |
289 |
||
135 | 290 |
!Polygon methodsFor:'queries'! |
0 | 291 |
|
292 |
bottom |
|
14 | 293 |
"return the bottom boundary of the polygon, |
294 |
that is the maximum y coordinate of all its points" |
|
295 |
||
78 | 296 |
(vertices size == 0) ifTrue: [^ nil]. |
297 |
^ vertices inject:(vertices at:1) y into:[:maxSoFar :p | maxSoFar max:(p y)] |
|
0 | 298 |
|
78 | 299 |
" |
300 |
(Polygon vertices:( |
|
301 |
Array |
|
302 |
with:10@10 |
|
303 |
with:60@10 |
|
304 |
with:35@60)) bottom |
|
305 |
" |
|
0 | 306 |
! |
307 |
||
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
308 |
canBeFilled |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
309 |
"return true, if the receiver can be drawn as a filled geometric. |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
310 |
Always true here." |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
311 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
312 |
^ true |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
313 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
314 |
"Created: 8.5.1996 / 08:16:53 / cg" |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
315 |
! |
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
316 |
|
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
317 |
computeBounds |
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
318 |
"return the smallest enclosing rectangle" |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
319 |
|
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
320 |
|minX maxX minY maxY t n "{ Class: SmallInteger }" | |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
321 |
|
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
322 |
n := vertices size. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
323 |
n == 0 ifTrue:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
324 |
^ nil "/ mhmh - should we return an empty rectangle here ? |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
325 |
]. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
326 |
t := vertices at:1. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
327 |
minX := maxX := t x. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
328 |
minY := maxY := t y. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
329 |
2 to:n do:[:i | |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
330 |
|x y t| |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
331 |
|
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
332 |
t := vertices at:i. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
333 |
x := t x. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
334 |
y := t y. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
335 |
x < minX ifTrue:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
336 |
minX := x. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
337 |
] ifFalse:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
338 |
x > maxX ifTrue:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
339 |
maxX := x. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
340 |
] |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
341 |
]. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
342 |
y < minY ifTrue:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
343 |
minY := y. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
344 |
] ifFalse:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
345 |
y > maxY ifTrue:[ |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
346 |
maxY := y. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
347 |
] |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
348 |
]. |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
349 |
]. |
283 | 350 |
^ Rectangle left:minX top:minY right:maxX bottom:maxY. |
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
351 |
|
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
352 |
" |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
353 |
|p| |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
354 |
|
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
355 |
p := (Polygon vertices:( |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
356 |
Array |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
357 |
with:10@10 |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
358 |
with:60@10 |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
359 |
with:35@60)). |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
360 |
p bounds |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
361 |
" |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
362 |
|
283 | 363 |
"Modified: 8.5.1996 / 20:51:42 / cg" |
490
ef43c7a69346
added dummy Scale & InverseScale classVars.
Claus Gittinger <cg@exept.de>
parents:
331
diff
changeset
|
364 |
"Created: 12.2.1997 / 11:44:11 / cg" |
276
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
365 |
! |
e104a0359515
comments & more Geometric functionality
Claus Gittinger <cg@exept.de>
parents:
267
diff
changeset
|
366 |
|
2091 | 367 |
containsPoint:aPoint |
368 |
"return true, if the argument, aPoint is contained in the receiver" |
|
369 |
||
370 |
|angle pPrev p1 p2 angle2D| |
|
371 |
||
372 |
angle2D := [:p1 :p2 | |
|
373 |
"/ Return the angle between two vectors on a plane |
|
374 |
"/ The angle is from vector 1 to vector 2, positive anticlockwise |
|
375 |
"/ The result is between -pi -> pi |
|
376 |
|theta theta1 theta2| |
|
377 |
||
378 |
theta1 := p1 x arcTan2:p1 y. |
|
379 |
theta2 := p2 x arcTan2:p2 y. |
|
380 |
theta := theta2 - theta1. |
|
381 |
[theta > Float pi] whileTrue:[ |
|
382 |
theta := theta - (Float pi * 2) |
|
383 |
]. |
|
384 |
[ theta < (Float pi negated) ] whileTrue:[ |
|
385 |
theta := theta + (Float pi * 2) |
|
386 |
]. |
|
387 |
theta |
|
388 |
]. |
|
389 |
||
390 |
angle := 0. |
|
391 |
||
392 |
pPrev := vertices last. |
|
393 |
vertices do:[:pI | |
|
394 |
p1 := pPrev - aPoint. |
|
395 |
p2 := pI - aPoint. |
|
396 |
angle := angle + (angle2D value:p1 value:p2). |
|
397 |
pPrev := pI. |
|
398 |
]. |
|
399 |
||
400 |
^ angle abs >= Float pi |
|
401 |
||
402 |
" |
|
403 |
|p| |
|
404 |
||
405 |
p := Polygon vertices:(Array |
|
406 |
with:10@10 |
|
407 |
with:30@10 |
|
408 |
with:20@20). |
|
409 |
TestCase assert:(p containsPoint:14@11). |
|
410 |
TestCase assert:(p containsPoint:15@15). |
|
411 |
TestCase assert:(p containsPoint:5@15) not. |
|
412 |
TestCase assert:(p containsPoint:15@5) not. |
|
413 |
TestCase assert:(p containsPoint:30@15) not. |
|
414 |
TestCase assert:(p containsPoint:20@15). |
|
415 |
" |
|
416 |
! |
|
417 |
||
0 | 418 |
left |
14 | 419 |
"return the left boundary of the polygon, |
420 |
that is the minimum x coordinate of all its points" |
|
421 |
||
78 | 422 |
(vertices size == 0) ifTrue: [^ nil]. |
423 |
^ vertices inject:(vertices at:1) x into:[:minSoFar :p | minSoFar min:(p x)] |
|
0 | 424 |
|
78 | 425 |
" |
426 |
(Polygon vertices:( |
|
427 |
Array |
|
428 |
with:10@10 |
|
429 |
with:60@10 |
|
430 |
with:35@60)) left |
|
431 |
" |
|
432 |
||
0 | 433 |
! |
434 |
||
435 |
right |
|
14 | 436 |
"return the right boundary of the polygon, |
88 | 437 |
that is the maximum x coordinate of all its points" |
14 | 438 |
|
78 | 439 |
(vertices size == 0) ifTrue: [^ nil]. |
440 |
^ vertices inject:(vertices at:1) x into:[:maxSoFar :p | maxSoFar max:(p x)] |
|
441 |
||
442 |
" |
|
443 |
(Polygon vertices:( |
|
444 |
Array |
|
445 |
with:10@10 |
|
446 |
with:60@10 |
|
447 |
with:35@60)) right |
|
448 |
" |
|
449 |
||
135 | 450 |
! |
78 | 451 |
|
135 | 452 |
top |
453 |
"return the top boundary of the polygon, |
|
454 |
that is the minimum y coordinate of all its points" |
|
78 | 455 |
|
135 | 456 |
(vertices size == 0) ifTrue: [^ nil]. |
457 |
^ vertices inject:(vertices at:1) y into:[:minSoFar :p | minSoFar min:(p y)] |
|
78 | 458 |
|
459 |
" |
|
460 |
(Polygon vertices:( |
|
461 |
Array |
|
462 |
with:10@10 |
|
463 |
with:60@10 |
|
135 | 464 |
with:35@60)) top |
78 | 465 |
" |
466 |
||
135 | 467 |
! ! |
78 | 468 |
|
135 | 469 |
!Polygon class methodsFor:'documentation'! |
78 | 470 |
|
135 | 471 |
version |
2091 | 472 |
^ '$Header: /cvs/stx/stx/libbasic2/Polygon.st,v 1.27 2009-01-21 23:22:24 cg Exp $' |
0 | 473 |
! ! |