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.30 date: 2016/09/09 11:23:00
user: stefan
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  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.


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 17 Nov 2018 09:19:01 GMT