exponential functions

This commit is contained in:
Konstantin Käfer
2014-03-24 14:45:33 +01:00
parent 5c613b5455
commit c00ec64205
3 changed files with 25 additions and 0 deletions

View File

@@ -45,6 +45,9 @@ bool stops(float z, const std::vector<bool>& values);
float linear(float z, const std::vector<float>& values);
bool linear(float z, const std::vector<bool>& values);
float exponential(float z, const std::vector<float>& values);
bool exponential(float z, const std::vector<bool>& values);
}

View File

@@ -89,3 +89,23 @@ bool functions::linear(float z, const std::vector<bool>&) {
// TODO
return false;
}
float functions::exponential(float z, const std::vector<float>& values) {
if (values.size() != 5) {
return 0;
}
const float z_base = values[0];
const float val = values[1];
const float slope = values[2];
const float min = values[3];
const float max = values[4];
return fmin(fmax(min, val + pow(1.75, (z - z_base)) * slope), max);
// return fmin(fmax(min, val + (z - z_base) * slope), max);
}
bool functions::exponential(float z, const std::vector<bool>&) {
// TODO
return false;
}

View File

@@ -310,6 +310,8 @@ typename FunctionProperty<T>::fn StyleParser::parseFunctionType(JSVal type) {
return &functions::linear;
} else if (t == "stops") {
return &functions::stops;
} else if (t == "exponential") {
return &functions::exponential;
} else {
throw Style::exception("unknown function type");
}