Package | starling.geom |
Class | public class Polygon |
Inheritance | Polygon ![]() |
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 | ||
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 | ||
copyToVector(target:Vector.<Number>, targetIndex:int = 0, stride:int = 0):void Copies all vertices to a 'Vector', beginning at a certain target index and skipping
'stride' coordinates between each 'x, y' pair. | Polygon | ||
copyToVertexData(target:VertexData, targetIndex:int = 0):void Copies all vertices to a 'VertexData' instance, beginning at a certain target index. | Polygon | ||
createCircle(x:Number, y:Number, radius:Number):Polygon [static] Creates a circle with optimized implementations of triangulation, hitTest, etc. | Polygon | ||
createEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number):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, result: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 | ||
triangulate(result:Vector.<uint> = null):Vector.<uint> 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
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 |
copyToVector | () | method |
public function copyToVector(target:Vector.<Number>, targetIndex:int = 0, stride:int = 0):void
Copies all vertices to a 'Vector', beginning at a certain target index and skipping 'stride' coordinates between each 'x, y' pair.
Parameters
target:Vector.<Number> | |
targetIndex:int (default = 0 )
| |
stride:int (default = 0 )
|
copyToVertexData | () | method |
public function copyToVertexData(target:VertexData, targetIndex:int = 0):void
Copies all vertices to a 'VertexData' instance, beginning at a certain target index.
Parameters
target:VertexData | |
targetIndex:int (default = 0 )
|
createCircle | () | method |
public static function createCircle(x:Number, y:Number, radius:Number):Polygon
Creates a circle with optimized implementations of triangulation, hitTest, etc.
Parameters
x:Number | |
y:Number | |
radius:Number |
Polygon |
createEllipse | () | method |
public static function createEllipse(x:Number, y:Number, radiusX:Number, radiusY:Number):Polygon
Creates an ellipse with optimized implementations of triangulation, hitTest, etc.
Parameters
x:Number | |
y:Number | |
radiusX:Number | |
radiusY:Number |
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, result:Point = null):Point
Returns the coordinates of a certain vertex.
Parameters
index:int | |
result: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(result:Vector.<uint> = null):Vector.<uint>
Calculates a possible representation of the polygon via triangles. The resulting vector contains a list of vertex indices, where every three indices describe a triangle referencing the vertices of the polygon.
Parameters
result:Vector.<uint> (default = null )
|
Vector.<uint> |