mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-30 11:14:27 +08:00
matter-js, matter-js-tests
Added Query declaration to matter-js Added tests for matter-js
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
///<reference path="matter-js.d.ts"/>
|
||||
|
||||
var Engine = Matter.Engine,
|
||||
World = Matter.World,
|
||||
Body = Matter.Body,
|
||||
Bodies = Matter.Bodies,
|
||||
Composites = Matter.Composites,
|
||||
Constraint = Matter.Constraint,
|
||||
Events = Matter.Events,
|
||||
Query = Matter.Query
|
||||
|
||||
|
||||
var engine = Engine.create(document.body)
|
||||
|
||||
//Bodies
|
||||
var box1 = Bodies.rectangle(400,200,80,80)
|
||||
var box2 = Bodies.rectangle(400,610,810,60, {
|
||||
angle: 10,
|
||||
angularSpeed: 11,
|
||||
angularVelocity: 1,
|
||||
density: 4,
|
||||
isStatic: true
|
||||
})
|
||||
|
||||
var circle1 = Bodies.circle(100,100,50)
|
||||
|
||||
World.addBody(engine.world, box1)
|
||||
World.add(engine.world, [box2, circle1])
|
||||
|
||||
|
||||
//Composites
|
||||
var stack = Composites.stack(0, 100, 5, 1, 20, 0, function(x, y, column, row) {
|
||||
return Bodies.circle(x, y, 75, { restitution: 0.9 });
|
||||
});
|
||||
|
||||
World.add(engine.world, stack);
|
||||
|
||||
//Constraints
|
||||
var constraint1 = Constraint.create({
|
||||
bodyA: box1,
|
||||
bodyB: box2,
|
||||
stiffness: 0.02
|
||||
})
|
||||
|
||||
//Query
|
||||
var collisions = Query.ray([box1, box2, circle1], {x:1, y:2}, {x:3, y:4});
|
||||
|
||||
World.addConstraint(engine.world, constraint1)
|
||||
|
||||
|
||||
//events
|
||||
Events.on(engine, "beforeTick", (e:any)=>{
|
||||
|
||||
})
|
||||
|
||||
|
||||
Engine.run(engine)
|
||||
Vendored
+25
-1
@@ -44,7 +44,7 @@ declare module Matter
|
||||
{
|
||||
/**
|
||||
* Clears the engine including the world, pairs and broadphase.
|
||||
* @param engine
|
||||
* @param engine
|
||||
*/
|
||||
static clear(engine:Engine):void;
|
||||
|
||||
@@ -844,6 +844,30 @@ declare module Matter
|
||||
*/
|
||||
type?:string;
|
||||
}
|
||||
|
||||
export class Query
|
||||
{
|
||||
/**
|
||||
* Casts a ray segment against a set of bodies and returns all collisions, ray width is optional. Intersection points are not provided.
|
||||
*
|
||||
* @param bodies
|
||||
* @param startPoint
|
||||
* @param endPoint
|
||||
* @param [rayWidth]
|
||||
*
|
||||
* @returns Object[] Collisions
|
||||
*/
|
||||
static ray( bodies:Array<Body>, startPoint:Vector, endPoint:Vector, rayWidth?:number ):Array<any>;
|
||||
|
||||
/**
|
||||
* Returns all bodies whose bounds are inside (or outside if set) the given set of bounds, from the given set of bodies.
|
||||
*
|
||||
* @param bodies
|
||||
* @param bounds
|
||||
* @returns Body[] The bodies matching the query
|
||||
*/
|
||||
static region( bodies:Array<Body>, bounds:Bounds, outside?:boolean ):Array<Body>;
|
||||
}
|
||||
|
||||
export class Mouse
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user