/** * The `Matter.Vector` module contains methods for creating and manipulating vectors. * Vectors are the basis of all the geometry related operations in the engine. * A `Matter.Vector` object is of the form `{ x: 0, y: 0 }`. * * See the included usage [examples](https://github.com/liabru/matter-js/tree/master/examples). * * @class Vector */ export declare class Vector { x: number; y: number; constructor(x?: number, y?: number); static Null: Vector; /** * Returns a new vector with `x` and `y` copied from the given `vector`. * @method clone * @param {vector} vector * @return {vector} A new cloned vector */ static clone(vector: Vector): Vector; /** * Returns the magnitude (length) of a vector. * @method magnitude * @param {vector} vector * @return {number} The magnitude of the vector */ static magnitude(vector: Vector): number; /** * Returns the magnitude (length) of a vector (therefore saving a `sqrt` operation). * @method magnitudeSquared * @param {vector} vector * @return {number} The squared magnitude of the vector */ static magnitudeSquared(vector: Vector): number; /** * Rotates the vector about (0, 0) by specified angle. * @method rotate * @param {vector} vector * @param {number} angle * @param {vector} [output] * @return {vector} The vector rotated about (0, 0) */ static rotate(vector: Vector, angle: number, output?: Vector): Vector; /** * Rotates the vector about a specified point by specified angle. * @method rotateAbout * @param {vector} vector * @param {number} angle * @param {vector} point * @param {vector} [output] * @return {vector} A new vector rotated about the point */ static rotateAbout(vector: Vector, angle: number, point: Vector, output?: Vector): Vector; /** * Normalises a vector (such that its magnitude is `1`). * @method normalise * @param {vector} vector * @return {vector} A new vector normalised */ static normalise(vector: Vector): Vector; /** * Returns the dot-product of two vectors. * @method dot * @param {vector} vectorA * @param {vector} vectorB * @return {number} The dot product of the two vectors */ static dot(vectorA: Vector, vectorB: Vector): number; /** * Returns the cross-product of two vectors. * @method cross * @param {vector} vectorA * @param {vector} vectorB * @return {number} The cross product of the two vectors */ static cross(vectorA: Vector, vectorB: Vector): number; /** * Returns the cross-product of three vectors. * @method cross3 * @param {vector} vectorA * @param {vector} vectorB * @param {vector} vectorC * @return {number} The cross product of the three vectors */ static cross3(vectorA: Vector, vectorB: Vector, vectorC: Vector): number; /** * Adds the two vectors. * @method add * @param {vector} vectorA * @param {vector} vectorB * @param {vector} [output] * @return {vector} A new vector of vectorA and vectorB added */ static add(vectorA: Vector, vectorB: Vector, output?: Vector): Vector; /** * Subtracts the two vectors. * @method sub * @param {vector} vectorA * @param {vector} vectorB * @param {vector} [output] * @return {vector} A new vector of vectorA and vectorB subtracted */ static sub(vectorA: Vector, vectorB: Vector, output?: Vector): Vector; /** * Multiplies a vector and a scalar. * @method mult * @param {vector} vector * @param {number} scalar * @return {vector} A new vector multiplied by scalar */ static mult(vector: Vector, scalar: number): Vector; /** * Divides a vector and a scalar. * @method div * @param {vector} vector * @param {number} scalar * @return {vector} A new vector divided by scalar */ static div(vector: Vector, scalar: number): Vector; /** * Returns the perpendicular vector. Set `negate` to true for the perpendicular in the opposite direction. * @method perp * @param {vector} vector * @param {bool} [negate=false] * @return {vector} The perpendicular vector */ static perp(vector: Vector, negate?: boolean): Vector; /** * Negates both components of a vector such that it points in the opposite direction. * @method neg * @param {vector} vector * @return {vector} The negated vector */ static neg(vector: Vector): Vector; /** * Returns the angle between the vector `vectorB - vectorA` and the x-axis in radians. * @method angle * @param {vector} vectorA * @param {vector} vectorB * @return {number} The angle in radians */ static angle(vectorA: Vector, vectorB: Vector): number; /** * Temporary vector pool (not thread-safe). * @property _temp * @type {vector[]} * @private */ static _temp: Vector[]; toString(): string; dump(msg?: string): void; } export declare type Contact = { vertex: Vertex; normalImpulse: number; tangentImpulse: number; }; export declare class Vertex extends Vector { index: number; body: any; isInternal: boolean; contact: Contact; constructor(x: number, y: number, index: number, body: any); } export declare class Vertices { /** * Creates a new set of `Matter.Body` compatible vertices. * The `points` argument accepts an array of `Matter.Vector` points orientated around the origin `(0, 0)`, for example: * * [{ x: 0, y: 0 }, { x: 25, y: 50 }, { x: 50, y: 0 }] * * The `Vertices.create` method returns a new array of vertices, which are similar to Matter.Vector objects, * but with some additional references required for efficient collision detection routines. * * Vertices must be specified in clockwise order. * * Note that the `body` argument is not optional, a `Matter.Body` reference must be provided. * * @method create * @param {vector[]} points * @param {body} body */ static create(points: Vector[], body: any): Vertex[]; /** * Parses a string containing ordered x y pairs separated by spaces (and optionally commas), * into a `Matter.Vertices` object for the given `Matter.Body`. * For parsing SVG paths, see `Svg.pathToVertices`. * @method fromPath * @param {string} path * @param {body} body * @return {vertices} vertices */ static fromPath(path: number[], body?: any): Vertex[]; /** * Returns the centre (centroid) of the set of vertices. * @method centre * @param {vertices} vertices * @return {vector} The centre point */ static centre(vertices: Vertex[]): Vector; /** * Returns the average (mean) of the set of vertices. * @method mean * @param {vertices} vertices * @return {vector} The average point */ static mean(vertices: Vertex[]): Vector; /** * Returns the area of the set of vertices. * @method area * @param {vertices} vertices * @param {bool} signed * @return {number} The area */ static area(vertices: Vertex[], signed?: boolean): number; /** * Returns the moment of inertia (second moment of area) of the set of vertices given the total mass. * @method inertia * @param {vertices} vertices * @param {number} mass * @return {number} The polygon's moment of inertia */ static inertia(vertices: Vertex[], mass: number): number; /** * Translates the set of vertices in-place. * @method translate * @param {vertices} vertices * @param {vector} vector * @param {number} scalar */ static translate(vertices: Vertex[], vector: Vector, scalar?: number): Vertex[]; static translate2(vertices: Vertex[], x: number, y: number, scalar?: number): Vertex[]; /** * Rotates the set of vertices in-place. * @method rotate * @param {vertices} vertices * @param {number} angle * @param {vector} point */ static rotate(vertices: Vertex[], angle: number, point: Vector): Vertex[] | undefined; /** * Returns `true` if the `point` is inside the set of `vertices`. * @method contains * @param {vertices} vertices * @param {vector} point * @return {boolean} True if the vertices contains point, otherwise false */ static contains(vertices: Vertex[], point: Vector): boolean; /** * Scales the vertices from a point (default is centre) in-place. * @method scale * @param {vertices} vertices * @param {number} scaleX * @param {number} scaleY * @param {vector} point */ static scale(vertices: Vertex[], scaleX: number, scaleY: number, point: Vector): Vertex[]; /** * Chamfers a set of vertices by giving them rounded corners, returns a new set of vertices. * The radius parameter is a single number or an array to specify the radius for each vertex. * @method chamfer * @param {vertices} vertices * @param {number[]} radius * @param {number} quality * @param {number} qualityMin * @param {number} qualityMax */ static chamfer(vertices: Vertex[], radius0: any, quality?: number, qualityMin?: number, qualityMax?: number): Vector[]; /** * Sorts the input vertices into clockwise order in place. * @method clockwiseSort * @param {vertices} vertices * @return {vertices} vertices */ static clockwiseSort(vertices: Vertex[]): Vertex[]; /** * Returns true if the vertices form a convex shape (vertices must be in clockwise order). * @method isConvex * @param {vertices} vertices * @return {bool} `true` if the `vertices` are convex, `false` if not (or `null` if not computable). */ static isConvex(vertices: Vertex[]): boolean | null; /** * Returns the convex hull of the input vertices as a new array of points. * @method hull * @param {vertices} vertices * @return [vertex] vertices */ static hull(vertices: Vertex[]): Vertex[]; } export declare class Bounds { max: Vector; min: Vector; constructor(minX: number, minY: number, maxX: number, maxY: number); getWidth(): number; getHeight(): number; randomX(mergin?: number): number; randomY(mergin?: number): number; static Null: Bounds; /** * Creates a new axis-aligned bounding box (AABB) for the given vertices. * @method create * @param {vertices} vertices * @return {bounds} A new bounds object */ static create(vertices?: Vector[]): Bounds; static create2(x: number, y: number, width: number, height: number): Bounds; /** * Updates bounds using the given vertices and extends the bounds given a velocity. * @method update * @param {bounds} bounds * @param {vertices} vertices * @param {vector} velocity */ static update(bounds: Bounds, vertices: Vector[], velocity?: Vector): void; update2(x: number, y: number, width: number, height: number): void; /** * Returns true if the bounds contains the given point. * @method contains * @param {bounds} bounds * @param {vector} point * @return {boolean} True if the bounds contain the point, otherwise false */ static contains(bounds: Bounds, point: Vector): boolean; /** * Returns true if the two bounds intersect. * @method overlaps * @param {bounds} boundsA * @param {bounds} boundsB * @return {boolean} True if the bounds overlap, otherwise false */ static overlaps(boundsA: Bounds, boundsB: Bounds): boolean; /** * Translates the bounds by the given vector. * @method translate * @param {bounds} bounds * @param {vector} vector */ static translate(bounds: Bounds, vector: Vector): void; /** * Shifts the bounds to the given position. * @method shift * @param {bounds} bounds * @param {vector} position */ static shift(bounds: Bounds, position: Vector): void; dump(msg?: string): void; } /** * The `Matter.Axes` module contains methods for creating and manipulating sets of axes. * * @class Axes */ export declare class Axes { /** * Creates a new set of axes from the given vertices. * @method fromVertices * @param {vertices} vertices * @return {axes} A new axes from the given vertices */ static fromVertices(vertices: Vertex[]): Vector[]; /** * Rotates a set of axes by the given angle. * @method rotate * @param {axes} axes * @param {number} angle */ static rotate(axes: Vector[], angle: number): void; }