forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sat.d.ts
142 lines (128 loc) · 5.08 KB
/
sat.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Type definitions for sat.js
// Project: https://github.com/jriecken/sat-js
// Definitions by: Hou Chunlei <https://github.com/omni360>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace SAT {
/**
* This is a simple 2D vector/point class,Vector has two parameters {x},{y}.
*/
export class Vector {
/**
* @class Vector has two properties
* @param {number} x The x-coordinate of the Vector.
* @param {number} y The y-coordinate of the Vector.
*/
constructor(x: number, y: number);
x: number;
y: number;
copy(other: Vector): Vector;
clone(): Vector;
perp(): Vector;
rotate(angle: number): Vector;
reverse(): Vector;
normalize(): Vector;
add(other: Vector): Vector;
sub(other: Vector): Vector;
scale(x: number, y: number): Vector;
project(other: Vector): Vector;
projectN(other: Vector): Vector;
reflect(axis: Vector): Vector;
reflectN(axis: Vector): Vector;
dot(other: Vector): number;
len2(): number;
len(): number;
}
/**
* This is simple circle with a center {pos} position and radius {r}.
*/
export class Circle {
constructor(pos: Vector, r: number);
pos: Vector;
r: number;
}
export class Polygon {
constructor(pos: Vector, points: Vector[]);
pos: Vector;
points: Vector[];
angle: number;
offset: Vector;
calcPoints: Vector[];
edges: Vector[];
normals: Vector[];
setPoints(points: Vector[]): Polygon;
setAngle(angle: number): Polygon;
setOffset(offset: Vector): Polygon;
recalc(): Polygon;
rotate(angle: number): Polygon;
translate(x: number, y: number): Polygon;
getAABB(): Polygon;
}
export class Box {
constructor(pos: Vector, width: number, height: number);
pos: Vector;
w: number;
h: number;
toPolygon(): Polygon;
}
export class Response {
constructor();
a: any;
b: any;
overlap: number;
overlapN: Vector;
overlapV: Vector;
aInB: boolean;
bInA: boolean;
clear(): Response;
}
/**
* @function {pointInCircle} checks whether a given point {p} is inside the specified circle {c}.
* @param {Vector} p given a point to checks.
* @param {Circle} c check with a specified circle
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function pointInCircle(p: Vector, c: Circle): boolean;
/**
* @function {pointInPolygon} checks whether a given point [p] is inside a specified convex polygon.
* @param {Vector} p given a point to check.
* @param {Polygon} poly check with a spcified convex polygon.
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function pointInPolygon(p: Vector, poly: Polygon): boolean;
/**
* @function {testCicleCircle} tests a collision between two {Circle}s, {a} and {b}.
* if a {response} is to be calculated in the event of a collision, pass in a cleared {Response} object.
* @param {Circle} a specified circle a to tests.
* @param {Circle} b spacified circle b to tests.
* @param {Response} response specified the result of a collision between two circle.
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function testCircleCircle(a: Circle, b: Circle, response?: Response): boolean;
/**
* @function {testPolygonCicle} tests a collision between a {Polygon} and a {Circle}. if a response is to
* be calculated in the event of a collision, pass in a cleared {Response} object.
* @param {Polygon} polygon specified a Polygon to tests a collision.
* @param {Circle} circle specified a Circle to tests a collision.
* @param {Response} response specified the result of a collision between a {Polygon} and a {Circle}.
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function testPolygonCircle(polygon: Polygon, circle: Circle, response?: Response): boolean;
/**
* @function {testCirclePolygon} tests a collision between a {Circle} and a {Polygon}. if a response is to
* be calculated in the event of a collision, pass in a cleared {Response} object.
* @param {Circle} circle specified a {Circle} to tests a collision.
* @param {Polygon} polygon specified a {Polygon} to tests a collision.
* @param {Response} response specified the result of a collision between a {Circle} and a {Polygon}.
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function testCirclePolygon(circle: Circle, polygon: Polygon, response?: Response): boolean;
/**
* @function {testPolygonPolygon} tests whether two polygons {a} and {b} collide.
* if a response is to be calculated in the event of a collision, pass in a cleared {Response} object.
* @param {Polygon} a specified a {Polygon} {a} to test a collision.
* @param {Polygon} b specified a {Polygon} {b} to test a collision.
* @param {Response} response specified the result of a collision between two {Polygon}s.
* @return {boolean} return {true} if there is a collision. {false} otherwise.
*/
export function testPolygonPolygon(a: Polygon, b: Polygon, response?: Response): boolean;
}