ridder
Version:
A straightforward game engine for simple data-driven games in JavaScript
71 lines (70 loc) • 3.02 kB
TypeScript
import { Vector } from "./vector.js";
export type Polygon = {
x: number;
y: number;
basePoints: Array<Vector>;
calcPoints: Array<Vector>;
};
/**
* Create a new polygon data structure.
* @param x - The x-coordinate.
* @param y - The y-coordinate.
* @param points - An array of {@link Vector} points to create the convex polygon.
*/
export declare function polygon(x?: number, y?: number, points?: Array<Vector>): Polygon;
/**
* Create a new polygon from a rectangle.
* @param rx - The x-coordinate of the rectangle.
* @param ry - The y-coordinate of the rectangle.
* @param rw - The width of the rectangle.
* @param rh - The height of the rectangle
*/
export declare function polygonFromRect(x: number, y: number, rx: number, ry: number, rw: number, rh: number): Polygon;
/**
* Create a new polygon from a circle.
* @param cx - The x-coordinate of the circle.
* @param cy - The y-coordinate of the circle.
* @param cr - The radius of the circle.
* @param segments - The number of segments to create the polygon, e.g. 3 creates a triangle.
*/
export declare function polygonFromCircle(x: number, y: number, cx: number, cy: number, cr: number, segments: number): Polygon;
/**
* Set the components of the polygon and returns the polygon.
*/
export declare function setPolygon(p: Polygon, x: number, y: number, points: Array<Vector>): Polygon;
/**
* Set the components of the polygon from a rectangle and returns the polygon.
* @param rx - The x-coordinate of the rectangle.
* @param ry - The y-coordinate of the rectangle.
* @param rw - The width of the rectangle.
* @param rh - The height of the rectangle
*/
export declare function setPolygonFromRect(p: Polygon, x: number, y: number, rx: number, ry: number, rw: number, rh: number): void;
/**
* Set the components of the polygon from a circle and returns the polygon.
* @param cx - The x-coordinate of the circle.
* @param cy - The y-coordinate of the circle.
* @param cr - The radius of the circle.
* @param segments - The number of segments to create the polygon, e.g. 3 creates a triangle.
*/
export declare function setPolygonFromCircle(p: Polygon, x: number, y: number, cx: number, cy: number, cr: number, segments: number): void;
/**
* Returns `true` when the polygon has 3 or more points.
*/
export declare function isPolygonValid(p: Polygon): boolean;
/**
* Rotate the polygon to the given angle in degrees.
*/
export declare function setPolygonAngle(p: Polygon, angle: number): void;
/**
* Returns `true` when the polygons {@link a} and {@link b} intersect (overlap).
*/
export declare function doPolygonsIntersect(a: Polygon, b: Polygon): boolean;
/**
* Returns `true` when {@link x} and {@link y} are inside the polygon {@link p}.
*/
export declare function doesPolygonContain(p: Polygon, x: number, y: number): boolean;
/**
* Copy the data components of polygon {@link b} into polygon {@link a} and returns polygon {@link a}.
*/
export declare function copyPolygon(a: Polygon, b: Polygon): Polygon;