forked from Alchemist0823/three.quarks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ValueGenerator.ts
31 lines (28 loc) · 932 Bytes
/
ValueGenerator.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
import {FunctionJSON} from "./FunctionJSON";
import { ConstantValue } from "./ConstantValue";
import { IntervalValue } from "./IntervalValue";
import { PiecewiseBezier } from "./PiecewiseBezier";
export interface ValueGenerator {
type: 'value';
genValue(): number;
toJSON(): FunctionJSON;
clone(): ValueGenerator;
}
export interface FunctionValueGenerator {
type: 'function';
genValue(t: number): number;
toJSON(): FunctionJSON;
clone(): FunctionValueGenerator;
}
export function ValueGeneratorFromJSON(json: FunctionJSON): FunctionValueGenerator | ValueGenerator {
switch(json.type) {
case 'ConstantValue':
return ConstantValue.fromJSON(json);
case 'IntervalValue':
return IntervalValue.fromJSON(json);
case 'PiecewiseBezier':
return PiecewiseBezier.fromJSON(json);
default:
return new ConstantValue(0);
}
}