switch from low/high to from/to

This commit is contained in:
Ansis Brammanis
2015-02-04 12:08:29 -08:00
parent 93b07c3675
commit 4ec0028856
6 changed files with 51 additions and 49 deletions

View File

@@ -21,26 +21,28 @@ T PiecewiseConstantFunction<T>::evaluate(float z, const ZoomHistory &zh) const {
float fraction = std::fmod(z, 1.0f);
float t = std::min((std::chrono::steady_clock::now() - zh.lastIntegerZoomTime) / duration, 1.0f);
float scale = 1.0f;
uint32_t low, high;
float fromScale = 1.0f;
float toScale = 1.0f;
uint32_t from, to;
if (z > zh.lastIntegerZoom) {
result.t = fraction + (1.0f - fraction) * t;
scale *= 2.0f;
low = getBiggestStopLessThan(values, z - 1.0f);
high = getBiggestStopLessThan(values, z);
from = getBiggestStopLessThan(values, z - 1.0f);
to = getBiggestStopLessThan(values, z);
fromScale *= 2.0f;
} else {
result.t = fraction - fraction * t;
low = getBiggestStopLessThan(values, z);
high = getBiggestStopLessThan(values, z + 1.0f);
result.t = 1 - (1 - t) * fraction;
to = getBiggestStopLessThan(values, z);
from = getBiggestStopLessThan(values, z + 1.0f);
fromScale /= 2.0f;
}
result.low = values[low].second.low;
result.high = values[high].second.low;
result.lowScale = scale;
result.highScale = scale / 2;
result.from = values[from].second.to;
result.to = values[to].second.to;
result.fromScale = fromScale;
result.toScale = toScale;
return result;
}

View File

@@ -261,7 +261,7 @@ template <>
Faded<std::vector<float>> StyleParser::parseFunctionArgument(JSVal value) {
Faded<std::vector<float>> parsed;
JSVal rvalue = replaceConstant(value);
parsed.low = std::get<1>(parseFloatArray(rvalue));
parsed.to = std::get<1>(parseFloatArray(rvalue));
return parsed;
}
@@ -270,7 +270,7 @@ Faded<std::string> StyleParser::parseFunctionArgument(JSVal value) {
JSVal rvalue = replaceConstant(value);
if (rvalue.IsString()) {
Faded<std::string> parsed;
parsed.low = { value.GetString(), value.GetStringLength() };
parsed.to = { value.GetString(), value.GetStringLength() };
return parsed;
} else {
Log::Warning(Event::ParseStyle, "function argument must be a string");
@@ -560,7 +560,7 @@ template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>
} else if (value.IsArray()) {
Faded<std::vector<float>> parsed;
std::tuple<bool, std::vector<float>> floatarray = parseFloatArray(value);
parsed.low = std::get<1>(floatarray);
parsed.to = std::get<1>(floatarray);
return std::tuple<bool, PiecewiseConstantFunction<Faded<std::vector<float>>>> { std::get<0>(floatarray), parsed };
} else {
Log::Warning(Event::ParseStyle, "value of '%s' must be an array of numbers, or a number array function", property_name);
@@ -573,7 +573,7 @@ template<> std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> Style
return parsePiecewiseConstantFunction<Faded<std::string>>(value);
} else if (value.IsString()) {
Faded<std::string> parsed;
parsed.low = { value.GetString(), value.GetStringLength() };
parsed.to = { value.GetString(), value.GetStringLength() };
return std::tuple<bool, PiecewiseConstantFunction<Faded<std::string>>> { true, parsed };
} else {
Log::Warning(Event::ParseStyle, "value of '%s' must be string or a string function", property_name);

View File

@@ -14,10 +14,10 @@ typedef std::array<float, 4> Color;
template <typename T>
struct Faded {
T low;
float lowScale;
T high;
float highScale;
T from;
float fromScale;
T to;
float toScale;
float t;
};