-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.h
241 lines (218 loc) · 5.4 KB
/
function.h
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#ifndef FUNCTION_H
#define FUNCTION_H
#include <string>
#include <cmath>
#include <vector>
/**
* @brief The Function class
*
* All the functions used in to generate a fractal have to inherit that class.
*/
class Function
{
public:
explicit Function();
/**
* @brief apply
*
* Calculate the function on x and y
* @param x
* @param y
*/
virtual void apply(double& x, double& y)= 0;
/**
* @brief getName
* @return The name of the function
* @example Horsehoe
*/
std::string getName() const;
/**
* @brief getExpr
* @return An textual expression of the function
*/
std::string getExpr() const;
/**
* @brief getLatex
* @return A Latex expression of the function
*/
std::string getLatex() const;
/**
* @brief ~Function
*/
virtual ~Function(){};
protected:
/*
* Should insert manually , to delimitate the couple, but the functions get*
* automatically add "f(x,y) = ( <put the necessary> )"
*/
std::string m_name;
std::string m_expr;
std::string m_latex;
};
/**
* @brief The Identity class
*
* The identity function.
*
* @todo Identity is an affinity.
*/
class Identity : public Function
{
public:
explicit Identity();
virtual void apply(double& x, double& y);
};
/**
* @brief The Affinity class
*
* The affine functions : f(x,y) = (a1 * x + b1* y + c1, a2 * x + b2 * y + c2 )
*
* @attention We want contractive functions or contractove functions in average at least, so
* choose a and b strictly lesser than 1
*/
class Affinity : public Function
{
public:
/**
* @brief Affinity
*
* f(x,y) = (a1 * x + b1* y + c1, a2 * x + b2 * y + c2 )
*
* @param a1
* @param a2
* @param b1
* @param b2
* @param c1
* @param c2
*/
explicit Affinity(double a1=0, double a2=0, double b1=0, double b2=0, double c1=0, double c2=0);
/**
* @brief getFX
* @return an array with a1, b1, c1
*/
const double *getFX() const;//Mhummmmm... returning a pointer to a private attribute ?
/**
* @brief getFY
* @return an array with a2, b2, c2
*/
const double *getFY() const;
/**
* @brief setCoeff
* @param a1
* @param a2
* @param b1
* @param b2
* @param c1
* @param c2
* @see Affinity
*/
void setCoeff(double a1=0, double a2=0, double b1=0, double b2=0, double c1=0, double c2=0);
virtual void apply(double& x, double& y);
private:
// Why not having these attributes public ?
double m_fX[3];
double m_fY[3];
};
/**
* @brief The Sinusoidal class
*
* f(x, y) = (sin(x), sin(y))
*/
class Sinusoidal : public Function
{
public:
explicit Sinusoidal();
virtual void apply(double& x, double& y);
};
/**
* @brief The Spherical class
*
* f(x,y) = 1/r^2 * (x,y)
*/
class Spherical : public Function
{
public:
explicit Spherical();
virtual void apply(double& x, double& y);
};
class GenFunction : public Function
{
public:
explicit GenFunction(unsigned int nbFun);
virtual void apply(double &x, double &y);
/**
* @brief getColom_variations@return the color of the function in ARGB
*/
int getColor() const;
/**
* @brief setColor
* @param color ARGB color
*/
void setColor(int color);
/**
* @brief setAffinity
* @param affinity : the affinity which is composed in the functions
* default : the affine identity
*/
void setAffinity(Affinity affinity);
/**
* @brief setPostTransform
* @param affinity : the post transform affinity in which the previous resulting function is applied.
* Default : the affine identity.
*/
void setPostTransform(Affinity affinity);
/**
* @brief setFunction
* @param num : from 0 to the number of functions - 1. If num >= number of functions,
* does nothing.
* @param function : the function to set
*/
void setFunction(unsigned int num, Function *function);
~GenFunction();
//Maybe creating a class to manipulate colors ? But too specialized ?
/**
* @brief toAlpha
* @param color
* @return the alphe component of the ARGB color
*/
static char toAlpha(int color);
/**
* @brief toRed
* @param color
* @return the red component of the ARGB color
*/
static char toRed(int color);
/**
* @brief toGreen
* @param color
* @return the green component of the ARGB color
*/
static char toGreen(int color);
/**
* @brief toBlue
* @param color
* @return the blue component of the ARGB color
*/
static char toBlue(int color);
/**
* @brief toColor
* @param alpha
* @param red
* @param green
* @param blue
* @return the ARGB color from (alpha, red, green, blue)
*/
static int toColor(char alpha, char red, char green, char blue);
private:
//The weight of the generating functions, their sum will be normalized
std::vector<unsigned int> m_variations;
//The associated functions (a priori, max 49)
std::vector<Function *> m_functions;
//The affinity which is composed in each functions
Affinity *m_affinity;
//The affine post transform, in which are applied the previous resulting function
Affinity *m_postTransform;
// Color associated to the generating function, in ARGB
int m_color;
};
#endif // FUNCTION_H