import { Matrix2d } from "../math/matrix2d.ts"; import { Vector2d } from "../math/vector2d.ts"; import { Bounds } from "../physics/bounds.ts"; import { XYPoint } from "../utils/types.ts"; export type PolygonVertices = [XYPoint, XYPoint, XYPoint, ...XYPoint[]] | [Vector2d, Vector2d, Vector2d, ...Vector2d[]] | [number, number, number, number, number, number, ...number[]]; export type LineVertices = [XYPoint, XYPoint] | [Vector2d, Vector2d] | [number, number, number, number]; /** * a polygon Object.
* Please do note that melonJS implements a simple Axis-Aligned Boxes collision algorithm, which requires all polygons used for collision to be convex with all vertices defined with clockwise winding. * A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon * (which means that all angles are less than 180 degrees), as described here below :
*

* A polygon's `winding` is clockwise if its vertices (points) are declared turning to the right. The image above shows COUNTERCLOCKWISE winding. * @category Geometry */ export declare class Polygon { /** * origin point of the Polygon */ pos: Vector2d; /** * Array of points defining the Polygon
* Note: If you manually change `points`, you **must** call `recalc`afterwards so that the changes get applied correctly. */ points: Vector2d[]; /** * The edges here are the direction of the `n`th edge of the polygon, relative to * the `n`th point. If you want to draw a given edge from the edge value, you must * first translate to the position of the starting point. */ edges: Vector2d[]; /** * a list of indices for all vertices composing this polygon */ indices: number[]; /** * The normals here are the direction of the normal for the `n`th edge of the polygon, relative * to the position of the `n`th point. If you want to draw an edge normal, you must first * translate to the position of the starting point. * @ignore */ normals: Vector2d[]; /** * The bounding rectangle for this shape * @ignore */ private _bounds; /** * the shape type (used internally) */ type: string; /** * @param [x=0] - origin point of the Polygon * @param [y=0] - origin point of the Polygon * @param vertices - array of vector defining the Polygon */ constructor(x: number | undefined, y: number | undefined, vertices: PolygonVertices | LineVertices); /** * set new value to the Polygon * @param x - position of the Polygon * @param y - position of the Polygon * @param points - array of vector or vertices defining the Polygon * @returns this instance for object chaining */ setShape(x: number, y: number, points: PolygonVertices | LineVertices): this; /** * set the vertices defining this Polygon * @param vertices - array of vector or vertices defining the Polygon * @returns this instance for object chaining */ setVertices(vertices: PolygonVertices | LineVertices): this; /** * apply the given transformation matrix to this Polygon * @param m - the transformation matrix * @returns Reference to this object for method chaining */ transform(m: Matrix2d): this; /** * apply an isometric projection to this shape * @returns Reference to this object for method chaining */ toIso(): this; /** * apply a 2d projection to this shape * @returns Reference to this object for method chaining */ to2d(): this; /** * Rotate this Polygon (counter-clockwise) by the specified angle (in radians). * @param angle - The angle to rotate (in radians) * @param [v] - an optional point to rotate around * @returns Reference to this object for method chaining */ rotate(angle: number, v?: Vector2d | XYPoint): this; /** * Scales the polygon by the given factors along the x and y axes. * @param x - The factor by which to scale the polygon along the x-axis. * @param [y=x] - The factor by which to scale the polygon along the y-axis. Defaults to the value of x. * @returns Reference to this object for method chaining */ scale(x: number, y?: number): this; /** * Scales the polygon by the given vector. * @param v - A vector containing the scaling factors for the x and y axes. * @returns Reference to this object for method chaining */ scaleV(v: Vector2d): this; /** * Computes the calculated collision polygon. * This **must** be called if the `points` array, `angle`, or `offset` is modified manually. * @returns Reference to this object for method chaining */ recalc(): this; /** * returns a list of indices for all triangles defined in this polygon * @returns an array of vertex indices for all triangles forming this polygon. */ getIndices(): number[]; /** * Returns true if the vertices composing this polygon form a convex shape (vertices must be in clockwise order). * @returns true if the vertices are convex, false if not, null if not computable */ isConvex(): boolean | null; /** * Translates the Polygon by the specified offset. * @param x - The x offset or a vector point to translate by. * @param [y] - The y offset. This parameter is required if the first parameter is a number. * @returns Reference to this object for method chaining * @example * polygon.translate(10, 10); * // or * polygon.translate(myVector2d); */ translate(x: number, y: number): Polygon; translate(vector: Vector2d): Polygon; /** * Shifts the Polygon to the given position vector. * @param x - The x coordinate or a vector point to shift to. * @param [y] - The y coordinate. This parameter is required if the first parameter is a number. * @example * polygon.shift(10, 10); * // or * polygon.shift(myVector2d); */ shift(x: number, y: number): void; shift(vector: Vector2d): void; /** * Returns true if the polygon contains the given point.
* (Note: it is highly recommended to first do a hit test on the corresponding
* bounding rect, as the function can be highly consuming with complex shapes) * @param x - x coordinate or a vector point to check * @param [y] - y coordinate * @param args * @returns True if the polygon contain the point, otherwise false * @example * if (polygon.contains(10, 10)) { * // do something * } * // or * if (polygon.contains(myVector2d)) { * // do something * } */ contains(x: number, y: number): boolean; contains(vector: Vector2d): boolean; /** * returns the bounding box for this shape, the smallest Rectangle object completely containing this shape. * @returns this shape bounding box Rectangle object */ getBounds(): Bounds; /** * update the bounding box for this shape. * @returns this shape bounding box Rectangle object */ updateBounds(): Bounds; /** * clone this Polygon * @returns new Polygon */ clone(): Polygon; } export declare const polygonPool: import("../system/pool.ts").Pool; //# sourceMappingURL=polygon.d.ts.map