From 6f7097185aa4cfd2b33f266f27988da56334d454 Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 11:34:18 +1000 Subject: [PATCH 1/7] updated to version 0.10.0 --- matter-js/matter-js.d.ts | 46 ++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index eccd892df5..c926c197f3 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Matter.js - 0.9.1 +// Type definitions for Matter.js - 0.10.0 // Project: https://github.com/liabru/matter-js // Definitions by: Ivane Gegia , // David Asmuth @@ -1826,9 +1826,21 @@ declare namespace Matter { * @param {HTMLElement} element * @param {object} [options] * @return {engine} engine + * @deprecated */ static create(element?: HTMLElement | IEngineDefinition, options?: IEngineDefinition): Engine; + /** + * Creates a new engine. The options parameter is an object that specifies any properties you wish to override the defaults. + * All properties have default values, and many are pre-calculated automatically based on other properties. + * See the properties section below for detailed information on what you can pass via the `options` object. + * @method create + * @param {object} [options] + * @return {engine} engine + * @deprecated + */ + static create(options?: IEngineDefinition): Engine; + /** * Merges two engines by keeping the configuration of `engineA` but replacing the world with the one from `engineB`. * @method merge @@ -2164,12 +2176,20 @@ declare namespace Matter { * @type render */ controller?: any; + /** + * A reference to the `Matter.Engine` instance to be used. + * + * @property engine + * @type engine + */ + engine: Engine; /** * A reference to the element where the canvas is to be inserted (if `render.canvas` has not been specified) * * @property element * @type HTMLElement * @default null + * @deprecated */ element?: HTMLElement; /** @@ -2253,13 +2273,9 @@ declare namespace Matter { } /** - * The `Matter.Render` module is the default `render.controller` used by a `Matter.Engine`. - * This renderer is HTML5 canvas based and supports a number of drawing options including sprites and viewports. - * - * It is possible develop a custom renderer module based on `Matter.Render` and pass an instance of it to `Engine.create` via `options.render`. - * A minimal custom renderer object must define at least three functions: `create`, `clear` and `world` (see `Matter.Render`). - * - * See also `Matter.RenderPixi` for an alternate WebGL, scene-graph based renderer. + * The `Matter.Render` module is a simple HTML5 canvas based renderer for visualising instances of `Matter.Engine`. + * It is intended for development and debugging purposes, but may also be suitable for simple games. + * It includes a number of drawing options including wireframe, vector with support for sprites and viewports. * * @class Render */ @@ -2273,6 +2289,18 @@ declare namespace Matter { * @return {render} A new renderer */ static create(options: IRenderDefinition): Render; + /** + * Continuously updates the render canvas on the `requestAnimationFrame` event. + * @method run + * @param {render} render + */ + static run(render: Render): void; + /** + * Ends execution of `Render.run` on the given `render`, by canceling the animation frame request event loop. + * @method stop + * @param {render} render + */ + static stop(render: Render): void; /** * Sets the pixel ratio of the renderer and updates the canvas. * To automatically detect the correct ratio, pass the string `'auto'` for `pixelRatio`. @@ -2287,7 +2315,7 @@ declare namespace Matter { * @method world * @param {engine} engine */ - static world(engine: Engine): void; + static world(render: Render): void; /** * A back-reference to the `Matter.Render` module. From b186a847445cb4abe0ce8a7398c30f60dd6fbc9b Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 13:21:21 +1000 Subject: [PATCH 2/7] added Bounds definition --- matter-js/matter-js.d.ts | 47 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index c926c197f3..4d456067dc 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -1051,13 +1051,56 @@ declare namespace Matter { } /** - * Internal Class, not generally used outside of the engine's internals. * The `Matter.Bounds` module contains methods for creating and manipulating axis-aligned bounding boxes (AABB). * * @class Bounds */ export class 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: Vertices): 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: Vertices, velocity: Vector): 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; } export interface ICompositeDefinition { From 34adbd2c0101938f785f89f093c5c670a1df2713 Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 16:53:41 +1000 Subject: [PATCH 3/7] fixed World base class --- matter-js/matter-js.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index 4d456067dc..63ff207920 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -2898,7 +2898,7 @@ declare namespace Matter { * @class World * @extends Composite */ - export class World { + export class World extends Composite { /** * Add objects or arrays of objects of types: Body, Constraint, Composite * @param world From 1ae14917a3f3bf97bd98b4c962639053303cf15d Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 17:26:40 +1000 Subject: [PATCH 4/7] comment defaults --- matter-js/matter-js.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index 63ff207920..6976ffd144 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -1901,14 +1901,14 @@ declare namespace Matter { * Therefore the value is always `1` (no correction) when `delta` constant (or when no correction is desired, which is the default). * See the paper on Time Corrected Verlet for more information. * - * Triggers `beforeUpdate` and `afterUpdate` events. - * Triggers `collisionStart`, `collisionActive` and `collisionEnd` events. - * @method update - * @param {engine} engine - * @param {number} delta - * @param {number} [correction] - */ - static update(engine: Engine, delta: number, correction?: number): Engine; + * Triggers `beforeUpdate` and `afterUpdate` events. + * Triggers `collisionStart`, `collisionActive` and `collisionEnd` events. + * @method update + * @param {engine} engine + * @param {number} [delta=16.666] + * @param {number} [correction=1] + */ + static update(engine: Engine, delta?: number, correction?: number): Engine; /** * An alias for `Runner.run`, see `Matter.Runner` for more information. From 64d06b4b3d76ccb46fb20ff6a1ef57861ac031f0 Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 18:07:58 +1000 Subject: [PATCH 5/7] add Body.isSensor --- matter-js/matter-js.d.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index 6976ffd144..f3f23fa9f8 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -250,6 +250,14 @@ declare namespace Matter { * @type number */ inverseMass?: number; + /** + * A flag that indicates whether a body is a sensor. Sensor triggers collision events, but doesn't react with colliding body physically. + * + * @property isSensor + * @type boolean + * @default false + */ + isSensor: boolean; /** * A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken. * If you need to set a body as sleeping, you should use `Sleeping.set` as this requires more than just setting this flag. From c71265fe3490910999a0406cd94fe60d6f1c3ce1 Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 18:18:45 +1000 Subject: [PATCH 6/7] add chamfer to Bodies --- matter-js/matter-js.d.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index f3f23fa9f8..b0573e3bf6 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -31,6 +31,17 @@ declare namespace Matter { static rotate(axes: Array, angle: number): void; } + interface IChamfer { + radius?: number | Array; + quality?: number; + qualityMin?: number; + qualityMax?: number; + } + + interface IChamferableBodyDefinition extends IBodyDefinition { + chamfer?: IChamfer; + } + /** * The `Matter.Bodies` module contains factory methods for creating rigid body models * with commonly used body configurations (such as rectangles, circles and other polygons). @@ -66,7 +77,7 @@ declare namespace Matter { * @param {object} [options] * @return {body} A new regular polygon body */ - static polygon(x: number, y: number, sides: number, radius: number, options?: IBodyDefinition): Body; + static polygon(x: number, y: number, sides: number, radius: number, options?: IChamferableBodyDefinition): Body; /** * Creates a new rigid body model with a rectangle hull. @@ -80,7 +91,7 @@ declare namespace Matter { * @param {object} [options] * @return {body} A new rectangle body */ - static rectangle(x: number, y: number, width: number, height: number, options?: IBodyDefinition): Body; + static rectangle(x: number, y: number, width: number, height: number, options?: IChamferableBodyDefinition): Body; /** * Creates a new rigid body model with a trapezoid hull. @@ -95,7 +106,7 @@ declare namespace Matter { * @param {object} [options] * @return {body} A new trapezoid body */ - static trapezoid(x: number, y: number, width: number, height: number, slope: number, options?: IBodyDefinition): Body; + static trapezoid(x: number, y: number, width: number, height: number, slope: number, options?: IChamferableBodyDefinition): Body; /** * Creates a body using the supplied vertices (or an array containing multiple sets of vertices). * If the vertices are convex, they will pass through as supplied. @@ -2811,7 +2822,7 @@ declare namespace Matter { * @param {number} qualityMin * @param {number} qualityMax */ - static chamfer(vertices: Array, radius: Array, quality: number, qualityMin: number, qualityMax: number): void; + static chamfer(vertices: Array, radius: number | Array, quality: number, qualityMin: number, qualityMax: number): void; /** From f8da75758ee1233fcd790bb88ce8155af5f22e30 Mon Sep 17 00:00:00 2001 From: stafford Date: Tue, 30 Aug 2016 20:20:41 +1000 Subject: [PATCH 7/7] isSensor = optional --- matter-js/matter-js.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matter-js/matter-js.d.ts b/matter-js/matter-js.d.ts index b0573e3bf6..da2c2f3eec 100644 --- a/matter-js/matter-js.d.ts +++ b/matter-js/matter-js.d.ts @@ -268,7 +268,7 @@ declare namespace Matter { * @type boolean * @default false */ - isSensor: boolean; + isSensor?: boolean; /** * A flag that indicates whether the body is considered sleeping. A sleeping body acts similar to a static body, except it is only temporary and can be awoken. * If you need to set a body as sleeping, you should use `Sleeping.set` as this requires more than just setting this flag.