diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 14:49:11 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-01-29 14:49:11 +0100 |
commit | 29f0214eea44042193340a04be3444edf86a384b (patch) | |
tree | be12fbd1233a9c1f5cd77592f137923b87f7e356 /src/style/properties.cpp | |
parent | 72d7ca0776f06029206df899e41fdf3f3a1cab46 (diff) | |
download | qtlocation-mapboxgl-29f0214eea44042193340a04be3444edf86a384b.tar.gz |
linear fades
Diffstat (limited to 'src/style/properties.cpp')
-rw-r--r-- | src/style/properties.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/style/properties.cpp b/src/style/properties.cpp index 499f0c7276..a0f2a659df 100644 --- a/src/style/properties.cpp +++ b/src/style/properties.cpp @@ -46,10 +46,12 @@ float functions::stops(float z, const std::vector<float>& stops) { } if (smaller && larger) { + if (larger_z == smaller_z || larger_val == smaller_val) return smaller_val; + float factor = (z - smaller_z) / (larger_z - smaller_z); + // Linear interpolation if base is 0 + if (smaller_val == 0) return factor * larger_val; // Exponential interpolation between the values - if (larger_z == smaller_z) return smaller_val; - float val = smaller_val * pow(larger_val / smaller_val, (z - smaller_z) / (larger_z - smaller_z)); - return val; + return smaller_val * pow(larger_val / smaller_val, factor); } else if (larger || smaller) { // Do not draw a line. return -std::numeric_limits<float>::infinity(); @@ -68,3 +70,21 @@ bool functions::stops(float z, const std::vector<bool>& values) { return false; } +float functions::linear(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 + (z - z_base) * slope), max); +} + +bool functions::linear(float z, const std::vector<bool>&) { + // TODO + return false; +} |