eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Polygon':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Polygon


Inheritance:

   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

Description:


Polygon - an array of points

Adds simple boundary checking methods to Array.
(needs much more - such as inside check, area computation etc.)


Related information:

    Rectangle
    EllipticalArc
    Spline
    Circle
    Point
    LineSegment
    Curve
    Arrow
    ArroedSpline
    GraphicsContext
    StrokingWrapper
    FillingWrapper

Class protocol:

instance creation
o  fromRectangle: aRectangle
return a new polygon, taking the rectangles vertices

usage example(s):

     Polygon fromRectangle:(50@50 corner:100@100)

o  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]).


Instance protocol:

accessing
o  add: aPoint

o  vertices
return the array containing my points

o  vertices: anArrayOfPoints
set the array containing my points

converting
o  asChaikinCurve
return a new polygon, which is generated by applying
the chaikin corner cutting algorithm once
(see the example on the class side)

o  asChaikinCurve: level
return a new polygon, which is generated by applying
the corner cutting algorithm n-times.
(see the example on the class side)

o  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
o  displayFilledOn: aGC
display a filled polygin as represented by the receiver in
the graphicsContext, aGC

o  displayStrokedOn: aGC
display an unfilled polygin as represented by the receiver in
the graphicsContext, aGC

enumerating
o  edgesDo: aTwoArgBlock
evaluate aTwoArgBlock for each pair of vertices

o  verticesDo: aBlock
evaluate aBlock for each point

queries
o  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 

o  computeBounds
return the smallest enclosing rectangle

o  containsPoint: aPoint
return true, if the argument, aPoint is contained in the receiver

o  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  

o  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  

o  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
o  canBeFilled
return true, if the receiver can be drawn as a filled geometric.
Always true here.


Examples:


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.


ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 19 Apr 2024 12:43:09 GMT