Package | starling.geom |
Class | public class Polygon |
Inheritance | Polygon Object |
The vertices of a polygon form a closed path (i.e. the last vertex will be connected to the first). It is recommended to provide the vertices in clockwise order. Self-intersecting paths are not supported and will give wrong results on triangulation, area calculation, etc.
Property | Defined By | ||
---|---|---|---|
area : Number [read-only] Calculates the total area of the polygon. | Polygon | ||
isConvex : Boolean [read-only] Indicates if the polygon is convex. | Polygon | ||
isSimple : Boolean [read-only] Indicates if the polygon's line segments are not self-intersecting. | Polygon | ||
numTriangles : int [read-only] Returns the number of triangles that will be required when triangulating the polygon. | Polygon | ||
numVertices : int Returns the total number of vertices spawning up the polygon. | Polygon |
Method | Defined By | ||
---|---|---|---|
Polygon(vertices:Array = null) Creates a Polygon with the given coordinates. | Polygon | ||
addVertices(... args):void Adds vertices to the polygon. | Polygon | ||
Creates a clone of this polygon. | Polygon | ||
contains(x:Number, y:Number):Boolean Figures out if the given coordinates lie within the polygon. | Polygon | ||
containsPoint(point:Point):Boolean Figures out if the given point lies within the polygon. | Polygon | ||
copyToVertexData(target:VertexData = null, targetVertexID:int = 0, attrName:String = position):void Copies all vertices to a 'VertexData' instance, beginning at a certain target index. | Polygon | ||
createCircle(x:Number, y:Number, radius:Number, numSides:int = -1):Polygon [static] Creates a circle with optimized implementations of triangulation, hitTest, etc. | Polygon | ||
createEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number, numSides:int = -1):Polygon [static] Creates an ellipse with optimized implementations of triangulation, hitTest, etc. | Polygon | ||
createRectangle(x:Number, y:Number, width:Number, height:Number):Polygon [static] Creates a rectangle with optimized implementations of triangulation, hitTest, etc. | Polygon | ||
getVertex(index:int, out:Point = null):Point Returns the coordinates of a certain vertex. | Polygon | ||
reverse():void Reverses the order of the vertices. | Polygon | ||
setVertex(index:int, x:Number, y:Number):void Moves a given vertex to a certain position or adds a new vertex at the end. | Polygon | ||
toString():String Creates a string that contains the values of all included points. | Polygon | ||
Calculates a possible representation of the polygon via triangles. | Polygon |
area | property |
area:Number
[read-only] Calculates the total area of the polygon.
public function get area():Number
isConvex | property |
isConvex:Boolean
[read-only] Indicates if the polygon is convex. In a convex polygon, the vector between any two points inside the polygon lies inside it, as well.
public function get isConvex():Boolean
isSimple | property |
isSimple:Boolean
[read-only] Indicates if the polygon's line segments are not self-intersecting.
Beware: this is a brute-force implementation with O(n^2)
.
public function get isSimple():Boolean
numTriangles | property |
numTriangles:int
[read-only] Returns the number of triangles that will be required when triangulating the polygon.
public function get numTriangles():int
numVertices | property |
numVertices:int
Returns the total number of vertices spawning up the polygon. Assigning a value that's smaller than the current number of vertices will crop the path; a bigger value will fill up the path with zeros.
public function get numVertices():int
public function set numVertices(value:int):void
Polygon | () | Constructor |
public function Polygon(vertices:Array = null)
Creates a Polygon with the given coordinates.
Parametersvertices:Array (default = null ) — an array that contains either 'Point' instances or
alternating 'x' and 'y' coordinates.
|
addVertices | () | method |
public function addVertices(... args):void
Adds vertices to the polygon. Pass either a list of 'Point' instances or alternating 'x' and 'y' coordinates.
Parameters
... args |
clone | () | method |
contains | () | method |
public function contains(x:Number, y:Number):Boolean
Figures out if the given coordinates lie within the polygon.
Parameters
x:Number | |
y:Number |
Boolean |
containsPoint | () | method |
public function containsPoint(point:Point):Boolean
Figures out if the given point lies within the polygon.
Parameters
point:Point |
Boolean |
copyToVertexData | () | method |
public function copyToVertexData(target:VertexData = null, targetVertexID:int = 0, attrName:String = position):void
Copies all vertices to a 'VertexData' instance, beginning at a certain target index.
Parameters
target:VertexData (default = null )
| |
targetVertexID:int (default = 0 )
| |
attrName:String (default = position )
|
createCircle | () | method |
public static function createCircle(x:Number, y:Number, radius:Number, numSides:int = -1):Polygon
Creates a circle with optimized implementations of triangulation, hitTest, etc.
Parameters
x:Number | |
y:Number | |
radius:Number | |
numSides:int (default = -1 )
|
Polygon |
createEllipse | () | method |
public static function createEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number, numSides:int = -1):Polygon
Creates an ellipse with optimized implementations of triangulation, hitTest, etc.
Parameters
x:Number | |
y:Number | |
radiusX:Number | |
radiusY:Number | |
numSides:int (default = -1 )
|
Polygon |
createRectangle | () | method |
public static function createRectangle(x:Number, y:Number, width:Number, height:Number):Polygon
Creates a rectangle with optimized implementations of triangulation, hitTest, etc.
Parameters
x:Number | |
y:Number | |
width:Number | |
height:Number |
Polygon |
getVertex | () | method |
public function getVertex(index:int, out:Point = null):Point
Returns the coordinates of a certain vertex.
Parameters
index:int | |
out:Point (default = null )
|
Point |
reverse | () | method |
public function reverse():void
Reverses the order of the vertices. Note that some methods of the Polygon class require the vertices in clockwise order.
setVertex | () | method |
public function setVertex(index:int, x:Number, y:Number):void
Moves a given vertex to a certain position or adds a new vertex at the end.
Parameters
index:int | |
x:Number | |
y:Number |
toString | () | method |
public function toString():String
Creates a string that contains the values of all included points.
ReturnsString |
triangulate | () | method |
public function triangulate(indexData:IndexData = null, offset:int = 0):IndexData
Calculates a possible representation of the polygon via triangles. The resulting IndexData instance will reference the polygon vertices as they are saved in this Polygon instance, optionally incremented by the given offset.
If you pass an indexData object, the new indices will be appended to it. Otherwise, a new instance will be created.
Parameters
indexData:IndexData (default = null )
| |
offset:int (default = 0 )
|
IndexData |