|
Class: Polygon
Object
|
+--Geometric
|
+--Polygon
|
+--Polyline
- Package:
- stx:libbasic2
- Category:
- Graphics-Geometry-Objects
- Version:
- rev:
1.32
date: 2019/03/06 21:45:49
- user: cg
- file: Polygon.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
Polygon - an array of points
Adds simple boundary checking methods to Array.
(needs much more - such as inside check, area computation etc.)
Rectangle
EllipticalArc
Spline
Circle
Point
LineSegment
Curve
Arrow
ArroedSpline
GraphicsContext
StrokingWrapper
FillingWrapper
instance creation
-
fromRectangle: aRectangle
-
return a new polygon, taking the rectangles vertices
usage example(s):
Polygon fromRectangle:(50@50 corner:100@100)
|
-
vertices: anArrayOfPoints
-
return a new polygon, given a collection of vertices
usage example(s):
Polygon vertices:(Array with:10@10
with:20@20
with:30@30)
Polygon vertices:(#(10 10 100 0 50 50) pairWiseCollect:[:x :y | x @ y]).
|
accessing
-
add: aPoint
-
-
vertices
-
return the array containing my points
-
vertices: anArrayOfPoints
-
set the array containing my points
converting
-
asChaikinCurve
-
return a new polygon, which is generated by applying
the chaikin corner cutting algorithm once
(see the example on the class side)
-
asChaikinCurve: level
-
return a new polygon, which is generated by applying
the corner cutting algorithm n-times.
(see the example on the class side)
-
asPointArray
-
return an array containing my vertex points.
Notice, that no copy of my vertices is created - you should not
modify the returned collections points (unless you want to affect
the polygon ...).
displaying
-
displayFilledOn: aGC
-
display a filled polygin as represented by the receiver in
the graphicsContext, aGC
-
displayStrokedOn: aGC
-
display an unfilled polygin as represented by the receiver in
the graphicsContext, aGC
enumerating
-
edgesDo: aTwoArgBlock
-
evaluate aTwoArgBlock for each pair of vertices
-
verticesDo: aBlock
-
evaluate aBlock for each point
queries
-
bottom
-
return the bottom boundary of the polygon,
that is the maximum y coordinate of all its points
usage example(s):
(Polygon vertices:(
Array
with:10@10
with:60@10
with:35@60)) bottom
|
-
computeBounds
-
return the smallest enclosing rectangle
-
containsPoint: aPoint
-
return true, if the argument, aPoint is contained in the receiver
-
left
-
return the left boundary of the polygon,
that is the minimum x coordinate of all its points
usage example(s):
(Polygon vertices:(
Array
with:10@10
with:60@10
with:35@60)) left
|
-
right
-
return the right boundary of the polygon,
that is the maximum x coordinate of all its points
usage example(s):
(Polygon vertices:(
Array
with:10@10
with:60@10
with:35@60)) right
|
-
top
-
return the top boundary of the polygon,
that is the minimum y coordinate of all its points
usage example(s):
(Polygon vertices:(
Array
with:10@10
with:60@10
with:35@60)) top
|
testing
-
canBeFilled
-
return true, if the receiver can be drawn as a filled geometric.
Always true here.
simple polygon; filled & unfilled:
|v p|
v := (View extent:200@200) openAndWait.
p := Polygon vertices:
(Array with:(10@10)
with:(90@90)
with:(10@90)).
v scale:2.
v paint:Color blue.
p displayFilledOn:v.
v paint:Color red.
p displayStrokedOn:v.
v scale:1; translation:100@0.
v paint:Color green.
p displayFilledOn:v.
v paint:Color black.
p displayStrokedOn:v.
|
arbitrary polygon; filled & unfilled:
|v p|
v := (View extent:200@200) openAndWait.
v scale:2.
p := Polygon vertices:
(Array with:(10@10)
with:(90@90)
with:(50@90)
with:(90@10)
with:(10@90)
).
v paint:Color blue.
p displayFilledOn:v.
v paint:Color red.
p displayStrokedOn:v.
| chaikin curve fitting:
|p p2 v|
p := Polygon
vertices:{
0 @ 0 .
0 @ 100 .
100 @ 100 .
110 @ -10 .
200 @ 150
}.
v := (View extent:300@300) openAndWait.
v translateBy:50@250.
v scale:(1 @ -1).
v paint:Color blue.
p displayStrokedOn:v.
p2 := p asChaikinCurve:10.
v paint:Color red.
p2 displayStrokedOn:v.
|
|