-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexFunctionMeta.pde
53 lines (48 loc) · 1.47 KB
/
ComplexFunctionMeta.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
53
class ProductWrapper implements ComplexFunction{
ComplexFunction[] functions;
ProductWrapper(ComplexFunction f1,ComplexFunction f2){
functions = new ComplexFunction[2];
functions[0] = f1;
functions[1] = f2;
}
ProductWrapper(ComplexFunction[] funcs){functions = funcs;}
String name(){
String out = "";
for(ComplexFunction func : functions){
out += ("(" + func.name() + ")") + " * ";
}
return out.substring(0,out.length() - 3);
}
String menuName(){return name();}
Complex f(Complex z){
Complex out = new Complex(1,0);
for(ComplexFunction func : functions){
out = out.mult(func.f(z));
}
return out;
}
}
class QuotientWrapper implements ComplexFunction{
ComplexFunction N,D;
QuotientWrapper(ComplexFunction num,ComplexFunction den){
N = num;
D = den;
}
String name(){
return "(" + N.name() + ") / (" + D.name() + ")";
}
String menuName(){return name();}
Complex f(Complex z){
return N.f(z).divBy(D.f(z));
}
}
class ComposeWrapper implements ComplexFunction{
ComplexFunction outer,inner;
ComposeWrapper(ComplexFunction outerfunction, ComplexFunction innerfunction){
outer = outerfunction;
inner = innerfunction;
}
String name(){return outer.name().replaceAll("z",inner.name());}
String menuName(){return name();}
Complex f(Complex z){return outer.f(inner.f(z));}
}