mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Merge pull request #4204 from ivanegegia/master
Type definitions for Victor.js 0.8.0 and Matter-js.js 0.2.0
This commit is contained in:
commit
529c7d6970
1
.gitignore
vendored
1
.gitignore
vendored
@ -33,3 +33,4 @@ _infrastructure/tests/build
|
||||
node_modules
|
||||
|
||||
.sublimets
|
||||
.settings/launch.json
|
||||
|
||||
57
matter-js/matter-js-tests.ts
Normal file
57
matter-js/matter-js-tests.ts
Normal file
@ -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:number, y:number, column:number, row:number) {
|
||||
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)
|
||||
1532
matter-js/matter-js.d.ts
vendored
Normal file
1532
matter-js/matter-js.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
52
victor/victor-tests.ts
Normal file
52
victor/victor-tests.ts
Normal file
@ -0,0 +1,52 @@
|
||||
///<reference path="victor.d.ts"/>
|
||||
|
||||
var vector1 = new Victor(10,10)
|
||||
var vector2 = new Victor(20,20)
|
||||
|
||||
vector1.add(vector2).addX(vector2).addY(vector2)
|
||||
|
||||
vector1.clone().copy(vector2).toString()
|
||||
|
||||
vector1.toArray()
|
||||
vector1.toObject()
|
||||
|
||||
vector1.subtract(vector2).subtractX(vector2).subtractY(vector2)
|
||||
.multiply(vector2).multiplyX(vector2).multiplyY(vector2)
|
||||
.divide(vector2).divideX(vector2).divideY(vector2)
|
||||
.invert().invertX().invertY()
|
||||
.mix(vector2, 0.5).mixX(vector2,0.5).mixY(vector2,0.5)
|
||||
.normalize().norm()
|
||||
.limit(100,5)
|
||||
.unfloat()
|
||||
.rotate(10)
|
||||
.rotateDeg(10)
|
||||
.rotateBy(10)
|
||||
.rotateByDeg(10)
|
||||
.randomize(new Victor(10,10), new Victor(100,100)).randomizeY(new Victor(10,10), new Victor(100,100)).randomizeX(new Victor(10,10), new Victor(100,100)).randomizeAny(new Victor(10,10), new Victor(100,100))
|
||||
|
||||
vector2.dot(vector1)
|
||||
vector2.cross(vector1)
|
||||
|
||||
vector1.length()
|
||||
vector1.lengthSq()
|
||||
|
||||
vector1.distance(vector2)
|
||||
vector1.distanceSq(vector2)
|
||||
|
||||
vector1.distanceX(vector2)
|
||||
vector1.distanceY(vector2)
|
||||
|
||||
vector1.horizontalAngle()
|
||||
vector1.horizontalAngleDeg()
|
||||
vector1.angle()
|
||||
vector1.angleDeg()
|
||||
vector1.verticalAngle()
|
||||
vector1.verticalAngleDeg()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
355
victor/victor.d.ts
vendored
Normal file
355
victor/victor.d.ts
vendored
Normal file
@ -0,0 +1,355 @@
|
||||
// Type definitions for Victor.js 0.2.5
|
||||
// Project: http://victorjs.org/
|
||||
// Definitions by: Ivane Gegia <https://twitter.com/ivanegegia>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
interface VictorCoordinates
|
||||
{
|
||||
x:number
|
||||
y:number
|
||||
}
|
||||
|
||||
declare class Victor
|
||||
{
|
||||
x:number;
|
||||
y:number;
|
||||
|
||||
/**
|
||||
* Can be used without the new keyword.
|
||||
* @param x The X component
|
||||
* @param y The Y component
|
||||
*/
|
||||
constructor(x:number,y:number);
|
||||
|
||||
/**
|
||||
* Creates vector from array.
|
||||
* @param arr array An array that contains the X component in the first element and the Y component in the second
|
||||
*/
|
||||
static fromArray(arr:Array<number>):Victor;
|
||||
|
||||
/**
|
||||
* Creates vector from object.
|
||||
* @param obj An object containing the X component in the x property and the Y component in the y property
|
||||
*/
|
||||
static fromObject(obj:VictorCoordinates):Victor;
|
||||
|
||||
/**
|
||||
* Creates a new Victor with the same X and Y components.
|
||||
*/
|
||||
clone():Victor;
|
||||
|
||||
/**
|
||||
* Copies the X component of another vector in to itself.
|
||||
* @param vector
|
||||
*/
|
||||
copyX(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Copies the Y component of another vector in to itself.
|
||||
* @param vector
|
||||
*/
|
||||
copyY(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Copies the X and Y components of another vector in to itself.
|
||||
* @param vector
|
||||
*/
|
||||
copy(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Returns a string representation of the X and Y components.
|
||||
*/
|
||||
toString():string;
|
||||
|
||||
/**
|
||||
* Returns an array representation of the X and Y components.
|
||||
*/
|
||||
toArray():Array<number>;
|
||||
|
||||
/**
|
||||
* Returns an object representation of tha X and Y components.
|
||||
*/
|
||||
toObject():VictorCoordinates;
|
||||
|
||||
/**
|
||||
* Adds another vector's X component to itself.
|
||||
* @param vector
|
||||
*/
|
||||
addX(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Adds another vector's Y component to itself.
|
||||
* @param vector
|
||||
*/
|
||||
addY(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Adds another vector to itself.
|
||||
* @param vector
|
||||
*/
|
||||
add(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Subtracts another vector's X component from itself.
|
||||
* @param vector
|
||||
*/
|
||||
subtractX(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Subtracts another vector's Y component from itself.
|
||||
* @param vector
|
||||
*/
|
||||
subtractY(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Subtracts another vector from itself.
|
||||
* @param vector
|
||||
*/
|
||||
subtract(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Multiplies the X component with the X component of another vector.
|
||||
* @param vector
|
||||
*/
|
||||
multiplyX(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Multiplies the Y component with the Y component of another vector.
|
||||
* @param vector
|
||||
*/
|
||||
multiplyY(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Multiplies both components with another vector.
|
||||
* @param vector
|
||||
*/
|
||||
multiply(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Divides the X component by the X component of another vector.
|
||||
* @param vector
|
||||
*/
|
||||
divideX(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Divides the Y component by the Y component of another vector.
|
||||
* @param vector
|
||||
*/
|
||||
divideY(vector:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Divides both components by another vector.
|
||||
* @param scalar
|
||||
*/
|
||||
divide(scalar:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Inverts the X component.
|
||||
*/
|
||||
invertX():Victor;
|
||||
|
||||
/**
|
||||
* Inverts the Y component.
|
||||
*/
|
||||
invertY():Victor;
|
||||
|
||||
/**
|
||||
* Inverts both components.
|
||||
*/
|
||||
invert():Victor;
|
||||
|
||||
/**
|
||||
* Performs a linear blend / interpolation of the X component towards another vector.
|
||||
* @param vector Number amount Value between 0 and 1. Default: 0.5
|
||||
* @param ammount
|
||||
*/
|
||||
mixX(vector:Victor, ammount:number):Victor;
|
||||
|
||||
/**
|
||||
* Performs a linear blend / interpolation of the Y component towards another vector.
|
||||
* @param vector
|
||||
* @param ammount
|
||||
*/
|
||||
mixY(vector:Victor, ammount:number):Victor;
|
||||
|
||||
/**
|
||||
* Performs a linear blend / interpolation towards another vector.
|
||||
* @param vector
|
||||
* @param ammount
|
||||
*/
|
||||
mix(vector:Victor, ammount:number):Victor;
|
||||
|
||||
/**
|
||||
* Normalizes the vector by scaling it down to a length of 1 while keeping its direction.
|
||||
*/
|
||||
normalize():Victor;
|
||||
|
||||
/**
|
||||
* Alias of normalize.
|
||||
*/
|
||||
norm():Victor;
|
||||
|
||||
/**
|
||||
* If either component is greater than max, multiplies the component by multiplier.
|
||||
* @param max
|
||||
* @param multiplier
|
||||
*/
|
||||
limit(max:number, multiplier:number):Victor;
|
||||
|
||||
/**
|
||||
* Rounds the components to integer numbers.
|
||||
*/
|
||||
unfloat():Victor;
|
||||
|
||||
/**
|
||||
* Rotates the vector to a certain angle, in radians CCW from +X axis.
|
||||
* @param angle
|
||||
*/
|
||||
rotate(angle:number):Victor;
|
||||
|
||||
/**
|
||||
* Same as rotate but uses degrees
|
||||
* @param angle
|
||||
*/
|
||||
rotateDeg(angle:number):Victor;
|
||||
|
||||
/**
|
||||
* Rotates the vector by a rotation angle, given in radians CCW from +X axis.
|
||||
* @param rotation
|
||||
*/
|
||||
rotateBy(rotation:number):Victor;
|
||||
|
||||
/**
|
||||
* Same as rotateBy but uses degrees
|
||||
* @param rotation
|
||||
*/
|
||||
rotateByDeg(rotation:number):Victor;
|
||||
|
||||
/**
|
||||
* Randomizes the X component with a value between topLeft and bottomRight.
|
||||
* @param topLeft
|
||||
* @param bottomRight
|
||||
*/
|
||||
randomizeX(topLeft:Victor, bottomRight:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Randomizes the Y component with a value between topLeft and bottomRight.
|
||||
* @param topLeft
|
||||
* @param bottomRight
|
||||
*/
|
||||
randomizeY(topLeft:Victor, bottomRight:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Randomizes the components with a value between topLeft and bottomRight.
|
||||
* @param topLeft
|
||||
* @param bottomRight
|
||||
*/
|
||||
randomize(topLeft:Victor, bottomRight:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Randomly randomizes either the X component or the Y component with a value between topLeft and bottomRight.
|
||||
* @param topLeft
|
||||
* @param bottomRight
|
||||
*/
|
||||
randomizeAny(topLeft:Victor, bottomRight:Victor):Victor;
|
||||
|
||||
/**
|
||||
* Returns the dot product of two vectors.
|
||||
* @param vector
|
||||
*/
|
||||
dot(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the cross product of two vectors.
|
||||
* @param vector
|
||||
*/
|
||||
cross(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the length / magnitude.
|
||||
*/
|
||||
length():number;
|
||||
|
||||
/**
|
||||
* Alias for length.
|
||||
*/
|
||||
magnitude():number;
|
||||
|
||||
/**
|
||||
* Returns the squared length / magnitude. If the length is only needed for comparison, this function is faster than length.
|
||||
*/
|
||||
lengthSq():number;
|
||||
|
||||
/**
|
||||
* Returns the distance of the X component from another vector.
|
||||
* @param vector
|
||||
*/
|
||||
distanceX(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Same as distanceX but always returns an absolute value.
|
||||
* @param vector
|
||||
*/
|
||||
absDistanceX(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the distance of the Y component from another vector.
|
||||
* @param vector
|
||||
*/
|
||||
distanceY(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Same as distanceY but always returns an absolute value.
|
||||
* @param vector
|
||||
*/
|
||||
absDistanceY(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the euclidean distance between two vectors.
|
||||
* @param vector
|
||||
*/
|
||||
distance(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the squared euclidean distance between two vectors. If the distance is only needed for comparison, this function is faster than distance.
|
||||
* @param vector
|
||||
*/
|
||||
distanceSq(vector:Victor):number;
|
||||
|
||||
/**
|
||||
* Returns the angle towards X in radians.
|
||||
*/
|
||||
horizontalAngle():number;
|
||||
|
||||
/**
|
||||
* Alias for horizontalAngle.
|
||||
*/
|
||||
angle():number;
|
||||
|
||||
/**
|
||||
* Alias for horizontalAngle.
|
||||
*/
|
||||
direction():number;
|
||||
|
||||
/**
|
||||
* Same as horizontalAngle but returns degrees.
|
||||
*/
|
||||
horizontalAngleDeg():number;
|
||||
|
||||
/**
|
||||
* Alias for horizontalAngleDeg.
|
||||
*/
|
||||
angleDeg():number;
|
||||
|
||||
/**
|
||||
* Returns the angle towards Y in radians.
|
||||
*/
|
||||
verticalAngle():number;
|
||||
|
||||
/**
|
||||
* Same as verticalAngle but returns degrees.
|
||||
*/
|
||||
verticalAngleDeg():number;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user