[core, ios, macos] Refactor composite stop types and conversions

This commit is contained in:
John Firebaugh
2017-02-07 12:35:27 -08:00
parent 9df24addfb
commit f35ca0d9df
13 changed files with 268 additions and 149 deletions

View File

@@ -282,6 +282,72 @@ struct Converter<CompositeValue<S>> {
}
};
template <class T>
struct Converter<CompositeExponentialStops<T>> {
static constexpr const char * type = "exponential";
template <class V>
Result<CompositeExponentialStops<T>> operator()(const V& value) const {
auto stops = convertStops<CompositeValue<float>, T>(value);
if (!stops) {
return stops.error();
}
auto base = 1.0f;
auto baseValue = objectMember(value, "base");
if (baseValue && toNumber(*baseValue)) {
base = *toNumber(*baseValue);
}
std::map<float, std::map<float, T>> convertedStops;
for (const auto& stop : *stops) {
convertedStops[stop.first.first].emplace(stop.first.second, stop.second);
}
return CompositeExponentialStops<T>(convertedStops, base);
}
};
template <class T>
struct Converter<CompositeIntervalStops<T>> {
static constexpr const char * type = "interval";
template <class V>
Result<CompositeIntervalStops<T>> operator()(const V& value) const {
auto stops = convertStops<CompositeValue<float>, T>(value);
if (!stops) {
return stops.error();
}
std::map<float, std::map<float, T>> convertedStops;
for (const auto& stop : *stops) {
convertedStops[stop.first.first].emplace(stop.first.second, stop.second);
}
return CompositeIntervalStops<T>(convertedStops);
}
};
template <class T>
struct Converter<CompositeCategoricalStops<T>> {
static constexpr const char * type = "categorical";
template <class V>
Result<CompositeCategoricalStops<T>> operator()(const V& value) const {
auto stops = convertStops<CompositeValue<CategoricalValue>, T>(value);
if (!stops) {
return stops.error();
}
std::map<float, std::map<CategoricalValue, T>> convertedStops;
for (const auto& stop : *stops) {
convertedStops[stop.first.first].emplace(stop.first.second, stop.second);
}
return CompositeCategoricalStops<T>(convertedStops);
}
};
template <class T>
struct Converter<CompositeFunction<T>> {
template <class V>
@@ -300,66 +366,17 @@ struct Converter<CompositeFunction<T>> {
return Error { "function property must be a string" };
}
auto stops = StopsConverter<T, typename CompositeFunction<T>::Stops>()(value);
if (!stops) {
return stops.error();
}
auto defaultValue = convertDefaultValue<T>(value);
if (!defaultValue) {
return defaultValue.error();
}
std::string type = "exponential";
auto typeValue = objectMember(value, "type");
if (typeValue && toString(*typeValue)) {
type = *toString(*typeValue);
}
if (type == "exponential") {
auto stops = convertStops<CompositeValue<float>, T>(value);
if (!stops) {
return stops.error();
}
auto base = 1.0f;
auto baseValue = objectMember(value, "base");
if (baseValue && toNumber(*baseValue)) {
base = *toNumber(*baseValue);
}
std::map<float, ExponentialStops<T>> convertedStops;
for (const auto& stop : *stops) {
auto& inner = convertedStops[stop.first.first];
inner.base = base;
inner.stops.emplace(stop.first.second, stop.second);
}
return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue);
} else if (type == "interval") {
auto stops = convertStops<CompositeValue<float>, T>(value);
if (!stops) {
return stops.error();
}
std::map<float, IntervalStops<T>> convertedStops;
for (const auto& stop : *stops) {
auto& inner = convertedStops[stop.first.first];
inner.stops.emplace(stop.first.second, stop.second);
}
return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue);
} else if (type == "categorical") {
auto stops = convertStops<CompositeValue<CategoricalValue>, T>(value);
if (!stops) {
return stops.error();
}
std::map<float, CategoricalStops<T>> convertedStops;
for (const auto& stop : *stops) {
auto& inner = convertedStops[stop.first.first];
inner.stops.emplace(stop.first.second, stop.second);
}
return CompositeFunction<T>(*propertyString, convertedStops, *defaultValue);
} else {
return Error { "unsupported function type" };
}
return CompositeFunction<T>(*propertyString, *stops, *defaultValue);
}
};

View File

@@ -0,0 +1,30 @@
#pragma once
#include <mbgl/style/function/categorical_stops.hpp>
namespace mbgl {
namespace style {
template <class T>
class CompositeCategoricalStops {
public:
using Stops = std::map<float, std::map<CategoricalValue, T>>;
Stops stops;
CompositeCategoricalStops() = default;
CompositeCategoricalStops(Stops stops_)
: stops(std::move(stops_)) {
}
CategoricalStops<T> innerStops(const std::map<CategoricalValue, T>& stops_) const {
return CategoricalStops<T>(stops_);
}
friend bool operator==(const CompositeCategoricalStops& lhs,
const CompositeCategoricalStops& rhs) {
return lhs.stops == rhs.stops;
}
};
} // namespace style
} // namespace mbgl

View File

@@ -0,0 +1,35 @@
#pragma once
#include <mbgl/style/function/exponential_stops.hpp>
#include <map>
namespace mbgl {
namespace style {
template <class T>
class CompositeExponentialStops {
public:
using Stops = std::map<float, std::map<float, T>>;
Stops stops;
float base = 1.0f;
CompositeExponentialStops() = default;
CompositeExponentialStops(Stops stops_, float base_ = 1.0f)
: stops(std::move(stops_)),
base(base_) {
}
ExponentialStops<T> innerStops(const std::map<float, T>& stops_) const {
return ExponentialStops<T>(stops_, base);
}
friend bool operator==(const CompositeExponentialStops& lhs,
const CompositeExponentialStops& rhs) {
return lhs.stops == rhs.stops && lhs.base == rhs.base;
}
};
} // namespace style
} // namespace mbgl

View File

@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/style/function/exponential_stops.hpp>
#include <mbgl/style/function/interval_stops.hpp>
#include <mbgl/style/function/categorical_stops.hpp>
#include <mbgl/style/function/composite_exponential_stops.hpp>
#include <mbgl/style/function/composite_interval_stops.hpp>
#include <mbgl/style/function/composite_categorical_stops.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/variant.hpp>
@@ -36,12 +36,12 @@ public:
using Stops = std::conditional_t<
util::Interpolatable<T>,
variant<
std::map<float, ExponentialStops<T>>,
std::map<float, IntervalStops<T>>,
std::map<float, CategoricalStops<T>>>,
CompositeExponentialStops<T>,
CompositeIntervalStops<T>,
CompositeCategoricalStops<T>>,
variant<
std::map<float, IntervalStops<T>>,
std::map<float, CategoricalStops<T>>>>;
CompositeIntervalStops<T>,
CompositeCategoricalStops<T>>>;
CompositeFunction(std::string property_, Stops stops_, optional<T> defaultValue_ = {})
: property(std::move(property_)),
@@ -53,20 +53,20 @@ public:
coveringRanges(float zoom) const {
return stops.match(
[&] (const auto& s) {
assert(!s.empty());
auto minIt = s.lower_bound(zoom);
auto maxIt = s.upper_bound(zoom);
if (minIt != s.begin()) {
assert(!s.stops.empty());
auto minIt = s.stops.lower_bound(zoom);
auto maxIt = s.stops.upper_bound(zoom);
if (minIt != s.stops.begin()) {
minIt--;
}
return std::make_tuple(
Range<float> {
minIt == s.end() ? s.rbegin()->first : minIt->first,
maxIt == s.end() ? s.rbegin()->first : maxIt->first
minIt == s.stops.end() ? s.stops.rbegin()->first : minIt->first,
maxIt == s.stops.end() ? s.stops.rbegin()->first : maxIt->first
},
Range<InnerStops> {
minIt == s.end() ? s.rbegin()->second : minIt->second,
maxIt == s.end() ? s.rbegin()->second : maxIt->second
s.innerStops(minIt == s.stops.end() ? s.stops.rbegin()->second : minIt->second),
s.innerStops(maxIt == s.stops.end() ? s.stops.rbegin()->second : maxIt->second)
}
);
}

View File

@@ -0,0 +1,32 @@
#pragma once
#include <mbgl/style/function/interval_stops.hpp>
#include <map>
namespace mbgl {
namespace style {
template <class T>
class CompositeIntervalStops {
public:
using Stops = std::map<float, std::map<float, T>>;
Stops stops;
CompositeIntervalStops() = default;
CompositeIntervalStops(Stops stops_)
: stops(std::move(stops_)) {
}
IntervalStops<T> innerStops(const std::map<float, T>& stops_) const {
return IntervalStops<T>(stops_);
}
friend bool operator==(const CompositeIntervalStops& lhs,
const CompositeIntervalStops& rhs) {
return lhs.stops == rhs.stops;
}
};
} // namespace style
} // namespace mbgl

View File

@@ -155,7 +155,7 @@ public:
MGLCompositeStyleFunction<ObjCType> *compositeStyleFunction = (MGLCompositeStyleFunction<ObjCType> *)value;
switch (compositeStyleFunction.interpolationMode) {
case MGLInterpolationModeExponential: {
__block std::map<float, mbgl::style::ExponentialStops<MBGLType>> outerStops = {};
__block std::map<float, std::map<float, MBGLType>> outerStops = {};
[compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) {
std::map<float, MBGLType> stops = {};
for (NSNumber *key in stopValue.allKeys) {
@@ -166,10 +166,12 @@ public:
NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant");
stops[key.floatValue] = mbglStopValue.asConstant();
}
mbgl::style::ExponentialStops<MBGLType> innerStops = {stops, (float)compositeStyleFunction.interpolationBase};
outerStops[zoomKey.floatValue] = innerStops;
outerStops[zoomKey.floatValue] = stops;
}];
mbgl::style::CompositeFunction<MBGLType> compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops};
mbgl::style::CompositeFunction<MBGLType> compositeFunction {
compositeStyleFunction.attributeName.UTF8String,
mbgl::style::CompositeExponentialStops<MBGLType> { outerStops, (float)compositeStyleFunction.interpolationBase }
};
if (compositeStyleFunction.defaultValue) {
NSCAssert([compositeStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant");
MBGLType mbglValue;
@@ -181,7 +183,7 @@ public:
}
break;
case MGLInterpolationModeInterval: {
__block std::map<float, mbgl::style::IntervalStops<MBGLType>> outerStops = {};
__block std::map<float, std::map<float, MBGLType>> outerStops = {};
[compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) {
std::map<float, MBGLType> stops = {};
for (NSNumber *key in stopValue.allKeys) {
@@ -192,10 +194,12 @@ public:
NSCAssert(mbglStopValue.isConstant(), @"Stops must be constant");
stops[key.floatValue] = mbglStopValue.asConstant();
}
mbgl::style::IntervalStops<MBGLType> innerStops = {stops};
outerStops[zoomKey.floatValue] = innerStops;
outerStops[zoomKey.floatValue] = stops;
}];
mbgl::style::CompositeFunction<MBGLType> compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops};
mbgl::style::CompositeFunction<MBGLType> compositeFunction {
compositeStyleFunction.attributeName.UTF8String,
mbgl::style::CompositeIntervalStops<MBGLType> { outerStops }
};
if (compositeStyleFunction.defaultValue) {
NSCAssert([compositeStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant");
MBGLType mbglValue;
@@ -207,7 +211,7 @@ public:
}
break;
case MGLInterpolationModeCategorical: {
__block std::map<float, mbgl::style::CategoricalStops<MBGLType>> outerStops = {};
__block std::map<float, std::map<mbgl::style::CategoricalValue, MBGLType>> outerStops = {};
[compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) {
__block std::map<mbgl::style::CategoricalValue, MBGLType> stops = {};
[stopValue enumerateKeysAndObjectsUsingBlock:^(id _Nonnull categoryKey, MGLStyleValue<ObjCType> * _Nonnull innerValue, BOOL * _Nonnull stop) {
@@ -233,10 +237,12 @@ public:
}
}
}];
mbgl::style::CategoricalStops<MBGLType> categoricalStops = {stops};
outerStops[zoomKey.floatValue] = categoricalStops;
outerStops[zoomKey.floatValue] = stops;
}];
mbgl::style::CompositeFunction<MBGLType> compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops};
mbgl::style::CompositeFunction<MBGLType> compositeFunction {
compositeStyleFunction.attributeName.UTF8String,
mbgl::style::CompositeCategoricalStops<MBGLType> { outerStops }
};
if (compositeStyleFunction.defaultValue) {
NSCAssert([compositeStyleFunction.defaultValue isKindOfClass:[MGLStyleConstantValue class]], @"Default value must be constant");
MBGLType mbglValue;
@@ -655,27 +661,25 @@ private: // Private utilities for converting from mbgl to mgl values
// Converts a composite function and all possible mbgl stops into an equivilant mgl style value
class CompositeFunctionStopsVisitor {
public:
id operator()(const std::map<float, mbgl::style::ExponentialStops<MBGLType>> &mbglStops) {
float base = 1.0f;
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()];
for (auto const& outerStop: mbglStops) {
stops[@(outerStop.first)] = toConvertedStops(outerStop.second.stops);
base = outerStop.second.base;
id operator()(const mbgl::style::CompositeExponentialStops<MBGLType> &mbglStops) {
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()];
for (auto const& outerStop: mbglStops.stops) {
stops[@(outerStop.first)] = toConvertedStops(outerStop.second);
}
MGLCompositeStyleFunction *compositeFunction = [MGLCompositeStyleFunction functionWithInterpolationMode:MGLInterpolationModeExponential
stops:stops
attributeName:@(mbglFunction.property.c_str())
options:@{MGLStyleFunctionOptionInterpolationBase: @(base)}];
options:@{MGLStyleFunctionOptionInterpolationBase: @(mbglStops.base)}];
if (mbglFunction.defaultValue) {
compositeFunction.defaultValue = [MGLStyleValue valueWithRawValue:toMGLRawStyleValue(*mbglFunction.defaultValue)];
}
return compositeFunction;
}
id operator()(const std::map<float, mbgl::style::IntervalStops<MBGLType>> &mbglStops) {
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()];
for (auto const& outerStop: mbglStops) {
stops[@(outerStop.first)] = toConvertedStops(outerStop.second.stops);
id operator()(const mbgl::style::CompositeIntervalStops<MBGLType> &mbglStops) {
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()];
for (auto const& outerStop: mbglStops.stops) {
stops[@(outerStop.first)] = toConvertedStops(outerStop.second);
}
MGLCompositeStyleFunction *compositeFunction = [MGLCompositeStyleFunction functionWithInterpolationMode:MGLInterpolationModeInterval
stops:stops
@@ -687,11 +691,11 @@ private: // Private utilities for converting from mbgl to mgl values
return compositeFunction;
}
id operator()(const std::map<float, mbgl::style::CategoricalStops<MBGLType>> &mbglStops) {
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.size()];
for (auto const& outerStop: mbglStops) {
NSMutableDictionary *innerStops = [NSMutableDictionary dictionaryWithCapacity:outerStop.second.stops.size()];
for (const auto &mbglStop : outerStop.second.stops) {
id operator()(const mbgl::style::CompositeCategoricalStops<MBGLType> &mbglStops) {
NSMutableDictionary *stops = [NSMutableDictionary dictionaryWithCapacity:mbglStops.stops.size()];
for (auto const& outerStop: mbglStops.stops) {
NSMutableDictionary *innerStops = [NSMutableDictionary dictionaryWithCapacity:outerStop.second.size()];
for (const auto &mbglStop : outerStop.second) {
auto categoricalValue = mbglStop.first;
auto rawValue = toMGLRawStyleValue(mbglStop.second);
CategoricalValueVisitor categoricalValueVisitor;

View File

@@ -82,8 +82,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleBlur = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -139,8 +139,8 @@
functionStyleValue = [MGLStyleValue<MGLColor *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleColor = functionStyleValue;
mbgl::style::ExponentialStops<mbgl::Color> innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<mbgl::Color>> compositeStops = { {10.0, innerStops} };
std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} };
mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops };
@@ -196,8 +196,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleOpacity = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -253,8 +253,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleRadius = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -350,8 +350,8 @@
functionStyleValue = [MGLStyleValue<MGLColor *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleStrokeColor = functionStyleValue;
mbgl::style::ExponentialStops<mbgl::Color> innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<mbgl::Color>> compositeStops = { {10.0, innerStops} };
std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} };
mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops };
@@ -407,8 +407,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleStrokeOpacity = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -464,8 +464,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.circleStrokeWidth = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };

View File

@@ -122,8 +122,8 @@
functionStyleValue = [MGLStyleValue<MGLColor *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.fillColor = functionStyleValue;
mbgl::style::ExponentialStops<mbgl::Color> innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<mbgl::Color>> compositeStops = { {10.0, innerStops} };
std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} };
mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops };
@@ -179,8 +179,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.fillOpacity = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -236,8 +236,8 @@
functionStyleValue = [MGLStyleValue<MGLColor *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.fillOutlineColor = functionStyleValue;
mbgl::style::ExponentialStops<mbgl::Color> innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<mbgl::Color>> compositeStops = { {10.0, innerStops} };
std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} };
mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops };

View File

@@ -230,8 +230,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineBlur = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -287,8 +287,8 @@
functionStyleValue = [MGLStyleValue<MGLColor *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineColor = functionStyleValue;
mbgl::style::ExponentialStops<mbgl::Color> innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<mbgl::Color>> compositeStops = { {10.0, innerStops} };
std::map<float, mbgl::Color> innerStops { {18, { 1, 0, 0, 1 }} };
mbgl::style::CompositeExponentialStops<mbgl::Color> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<mbgl::Color> { "keyName", compositeStops };
@@ -384,8 +384,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineGapWidth = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -441,8 +441,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineOffset = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };
@@ -498,8 +498,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.lineOpacity = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };

View File

@@ -99,8 +99,8 @@
functionStyleValue = [MGLStyleValue<<%- propertyType(property) %>> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.<%- objCName(property) %> = functionStyleValue;
mbgl::style::ExponentialStops<<%- mbglType(property) %>> innerStops = { { {18, <%- mbglTestValue(property, type) %>}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<<%- mbglType(property) %>>> compositeStops = { {10.0, innerStops} };
std::map<float, <%- mbglType(property) %>> innerStops { {18, <%- mbglTestValue(property, type) %>} };
mbgl::style::CompositeExponentialStops<<%- mbglType(property) %>> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>> { "keyName", compositeStops };

View File

@@ -208,8 +208,8 @@
functionStyleValue = [MGLStyleValue<NSValue *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.iconOffset = functionStyleValue;
mbgl::style::ExponentialStops<std::array<float, 2>> innerStops = { { {18, { 1, 1 }}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<std::array<float, 2>>> compositeStops = { {10.0, innerStops} };
std::map<float, std::array<float, 2>> innerStops { {18, { 1, 1 }} };
mbgl::style::CompositeExponentialStops<std::array<float, 2>> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<std::array<float, 2>> { "keyName", compositeStops };
@@ -339,8 +339,8 @@
functionStyleValue = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil];
layer.iconRotation = functionStyleValue;
mbgl::style::ExponentialStops<float> innerStops = { { {18, 0xff}}, 1.0 };
std::map<float, mbgl::style::ExponentialStops<float>> compositeStops = { {10.0, innerStops} };
std::map<float, float> innerStops { {18, 0xff} };
mbgl::style::CompositeExponentialStops<float> compositeStops { { {10.0, innerStops} }, 1.0 };
propertyValue = mbgl::style::CompositeFunction<float> { "keyName", compositeStops };

View File

@@ -257,31 +257,29 @@ public:
}
template <class T>
void operator()(const std::map<float, ExponentialStops<T>>& f) {
void operator()(const CompositeExponentialStops<T>& f) {
writer.Key("type");
writer.String("exponential");
if (!f.empty()) {
writer.Key("base");
writer.Double(f.begin()->second.base);
}
writer.Key("base");
writer.Double(f.base);
writer.Key("stops");
stringifyCompositeStops(f);
stringifyCompositeStops(f.stops);
}
template <class T>
void operator()(const std::map<float, IntervalStops<T>>& f) {
void operator()(const CompositeIntervalStops<T>& f) {
writer.Key("type");
writer.String("interval");
writer.Key("stops");
stringifyCompositeStops(f);
stringifyCompositeStops(f.stops);
}
template <class T>
void operator()(const std::map<float, CategoricalStops<T>>& f) {
void operator()(const CompositeCategoricalStops<T>& f) {
writer.Key("type");
writer.String("categorical");
writer.Key("stops");
stringifyCompositeStops(f);
stringifyCompositeStops(f.stops);
}
private:
@@ -301,7 +299,7 @@ private:
void stringifyCompositeStops(const std::map<float, InnerStops>& stops) {
writer.StartArray();
for (const auto& outer : stops) {
for (const auto& inner : outer.second.stops) {
for (const auto& inner : outer.second) {
writer.StartArray();
writer.StartObject();
writer.Key("zoom");

View File

@@ -101,9 +101,12 @@ TEST(Stringify, SourceFunction) {
TEST(Stringify, CompositeFunction) {
ASSERT_EQ(stringify(CompositeFunction<float>("property",
std::map<float, ExponentialStops<float>> {
{ 0, ExponentialStops<float> { {{0, 1}}, 2 } },
{ 1, ExponentialStops<float> { {{0, 1}}, 2 } }
CompositeExponentialStops<float> {
{
{ 0, {{0, 1}} },
{ 1, {{0, 1}} }
},
2
}, 0.0f)),
"{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0,"
"\"stops\":["