This repository has been archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
/
rebound.d.ts
215 lines (157 loc) · 5.59 KB
/
rebound.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
* Copyright (c) 2013, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
*/
export class SpringSystem {
listeners: Array<Listener>|null;
looper: Looper;
constructor(looper?: Looper);
setLooper(looper: Looper): void;
createSpring(tension?: number, friction?: number): Spring;
createSpringWithBouncinessAndSpeed(bounciness?: number, speed?: number):
Spring;
createSpringWithConfig(kwargs: SpringConfigDict): Spring;
getIsIdle(): boolean;
getSpringById(id: number): Spring;
getAllSprings(): Array<Spring>;
registerSpring(value: Spring): void;
deregisterSpring(value: Spring): void;
advance(time: number, deltaTime: number): void;
loop(currentTimeMillis: number): void;
activateSpring(springId: number): void;
addListener(listener: Listener): void;
removeListener(listener: Listener): void;
removeAllListeners(): void;
}
export class Spring {
static MAX_DELTA_TIME_SEC: number;
static SOLVER_TIMESTEP_SEC: number;
listeners: Array<Listener>|null;
constructor(system: SpringSystem);
destroy(): void;
getId(): number;
getSpringConfig(): SpringConfigDict;
setSpringConfig(value: SpringConfigDict): Spring;
getCurrentValue(): number;
setCurrentValue(currentValue: number, skipSetAtRest?: boolean): Spring;
getStartValue(): number;
getCurrentDisplacementDistance(): number;
getCurrentDisplacementDistanceForState(state: PhysicsState): number;
getEndValue(): number;
setEndValue(value: number): Spring;
getVelocity(): number;
setVelocity(value: number): Spring;
getRestSpeedThreshold(): number;
setRestSpeedThreshold(value: number): Spring;
getRestDisplacementThreshold(): number;
isOvershootClampingEnabled(): boolean;
setOvershootClampingEnabled(value: boolean): Spring;
isOvershooting(): boolean;
advance(time: number, realDeltaTime: number): void;
systemShouldAdvance(): boolean;
notifyPositionUpdated(notifyActivate?: boolean, notifyAtRest?: boolean): void;
wasAtRest(): boolean;
isAtRest(): boolean;
setAtRest(): Spring;
interpolate(value: number): void;
getListeners(): Array<Listener>;
addListener(value: Listener): Spring;
removeListener(value: Listener): Spring;
removeAllListeners(): Spring;
currentValueIsApproximately(value: number): boolean;
}
export interface CompleteListener {
onSpringEndStateChange(spring: Spring): void;
onBeforeIntegrate(spring: Spring): void;
onAfterIntegrate(spring: Spring): void;
onSpringActivate(spring: Spring): void;
onSpringUpdate(spring: Spring): void;
onSpringAtRest(spring: Spring): void;
}
export type Listener = Partial<CompleteListener>;
export type PhysicsState = {
position: number,
friction: number,
};
// We can't just export the type alias, because the library provides a factory
// called SpringConfig, so we export the factory as SpringConfig and call the
// type alias SpringConfigDict.
export type SpringConfigDict = {
tension: number,
friction: number,
};
export class SpringConfig {
static DEFAULT_ORIGAMI_SPRING_CONFIG: SpringConfig;
static fromOrigamiTensionAndFriction(tension: number, friction: number):
SpringConfig;
static fromBouncinessAndSpeed(bounciness: number, speed: number):
SpringConfig;
static coastingConfigWithOrigamiFriction(friction: number): SpringConfig;
tension: number;
friction: number;
constructor(tension: number, friction: number);
}
export interface Looper {
springSystem: SpringSystem;
run(): void;
}
export class AnimationLooper implements Looper {
springSystem: SpringSystem;
constructor();
run(): void;
}
export class SimulationLooper implements Looper {
springSystem: SpringSystem;
constructor(timestep?: number);
run(): void;
}
export class SteppingSimulationLooper extends SimulationLooper {
step(timestep: number): void;
}
export namespace OrigamiValueConverter {
function tensionFromOrigamiValue(value: number): number;
function origamiValueFromTension(value: number): number;
function frictionFromOrigamiValue(value: number): number;
function origamiFromFriction(value: number): number;
}
export class BouncyConversion {
bounciness: number;
speed: number;
constructor(bounciness: number, speed: number);
normalize(value: number, startValue: number, endValue: number): void;
projectNormal(n: number, start: number, end: number): void;
linearInterpolation(t: number, start: number, end: number): void;
quadraticOutInterpolation(t: number, start: number, end: number): void;
b3Friction1(x: number): void;
b3Friction2(x: number): void;
b3Friction3(x: number): void;
b3Nobounce(tension: number): void;
}
export type RGB = {
r: number,
g: number,
b: number,
};
export type RequestAnimationFrame = typeof requestAnimationFrame;
export namespace util {
function extend<T, U>(target: T, source: U): T&U;
function hexToRGB(color: string): RGB;
function rgbToHex(r: number, g: number, b: number): string;
const onFrame: RequestAnimationFrame;
// These are technically aliased to MathUtil, but it's not worth breaking them
// out
function mapValueInRange(
value: number, fromLow: number, fromHigh: number, toLow: number,
toHigh: number): number;
function interpolateColor(
val: number, startColor: string, endColor: string, fromLow?: number,
fromHigh?: number, asRGB?: boolean): string;
function degreesToRadians(value: number): number;
function radiansToDegrees(value: number): number;
}