starling-framework
Version:
A fast, productive library for 2D cross-platform development.
109 lines • 4.16 kB
TypeScript
import VertexData from "../rendering/VertexData";
import IndexData from "../rendering/IndexData";
import Point from "openfl/geom/Point";
declare namespace starling.geom {
/**
* A polygon describes a closed two-dimensional shape bounded by a number of straight
* * line segments.
* *
* * <p>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.</p>
*
*/
export class Polygon {
/**
* Creates a Polygon with the given coordinates.
* * @param vertices an array that contains either 'Point' instances or
* * alternating 'x' and 'y' coordinates.
*
*/
constructor(vertices?: Array<any>);
/**
* Creates an ellipse with optimized implementations of triangulation, hitTest, etc.
*/
static createEllipse(x: number, y: number, radiusX: number, radiusY: number, numSides?: number): Polygon;
/**
* Creates a circle with optimized implementations of triangulation, hitTest, etc.
*/
static createCircle(x: number, y: number, radius: number, numSides?: number): Polygon;
/**
* Creates a rectangle with optimized implementations of triangulation, hitTest, etc.
*/
static createRectangle(x: number, y: number, width: number, height: number): Polygon;
/**
* Creates a clone of this polygon.
*/
clone(): Polygon;
/**
* Reverses the order of the vertices. Note that some methods of the Polygon class
* * require the vertices in clockwise order.
*/
reverse(): void;
/**
* Adds vertices to the polygon. Pass either a list of 'Point' instances or alternating
* * 'x' and 'y' coordinates.
*/
addVertices(args: Array<any>): void;
/**
* Moves a given vertex to a certain position or adds a new vertex at the end.
*/
setVertex(index: number, x: number, y: number): void;
/**
* Returns the coordinates of a certain vertex.
*/
getVertex(index: number, out?: Point): Point;
/**
* Figures out if the given coordinates lie within the polygon.
*/
contains(x: number, y: number): boolean;
/**
* Figures out if the given point lies within the polygon.
*/
containsPoint(point: Point): boolean;
/**
* 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.
* *
* * <p>If you pass an indexData object, the new indices will be appended to it.
* * Otherwise, a new instance will be created.</p>
*/
triangulate(indexData?: IndexData, offset?: number): IndexData;
/**
* Copies all vertices to a 'VertexData' instance, beginning at a certain target index.
*/
copyToVertexData(target: VertexData, targetVertexID?: number, attrName?: string): void;
/**
* Creates a string that contains the values of all included points.
*/
toString(): string;
/**
* Indicates if the polygon's line segments are not self-intersecting.
* * Beware: this is a brute-force implementation with <code>O(n^2)</code>.
*/
get isSimple(): boolean;
/**
* Indicates if the polygon is convex. In a convex polygon, the vector between any two
* * points inside the polygon lies inside it, as well.
*/
get isConvex(): boolean;
/**
* Calculates the total area of the polygon.
*/
get area(): number;
/**
* 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.
*/
get numVertices(): number;
set numVertices(value: number)
/**
* Returns the number of triangles that will be required when triangulating the polygon.
*/
get numTriangles(): number;
}
}
export default starling.geom.Polygon;