-
Notifications
You must be signed in to change notification settings - Fork 0
/
Function.pde
52 lines (40 loc) · 1.01 KB
/
Function.pde
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
interface Function{
Complex get(float t);
}
class LinearSegmentF implements Function{
Complex p1, p2;
LinearSegmentF(Complex p1, Complex p2){
this.p1 = p1.copy();
this.p2 = p2.copy();
}
Complex get(float t){
return p1.mult(1-t).add(p2.mult(t));
}
}
class DiscontSegmentF implements Function{
Complex p1, p2;
DiscontSegmentF(Complex p1, Complex p2){
this.p1 = p1.copy();
this.p2 = p2.copy();
}
Complex get(float t){
return t<=0.5 ? p1.copy() : p2.copy();
}
}
class SegmentedF implements Function{
ArrayList<Function> functions;
SegmentedF(){
functions = new ArrayList<Function>();
}
void addFunc(Function f){
functions.add(f);
}
Complex get(float t){
if(functions.size() == 0){ return new Complex(0, 0); }
t -= floor(t);
int index = floor(t*functions.size());
Function f = functions.get(index);
float ft = t*functions.size() - floor(t*functions.size());
return f.get(ft);
}
}