From f35ca0d9dfc8a6ba88273edbeda43e633ae0adce Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 7 Feb 2017 12:35:27 -0800 Subject: [core, ios, macos] Refactor composite stop types and conversions --- include/mbgl/style/conversion/function.hpp | 127 ++++++++++++--------- .../style/function/composite_categorical_stops.hpp | 30 +++++ .../style/function/composite_exponential_stops.hpp | 35 ++++++ include/mbgl/style/function/composite_function.hpp | 32 +++--- .../style/function/composite_interval_stops.hpp | 32 ++++++ platform/darwin/src/MGLStyleValue_Private.h | 60 +++++----- platform/darwin/test/MGLCircleStyleLayerTests.mm | 28 ++--- platform/darwin/test/MGLFillStyleLayerTests.mm | 12 +- platform/darwin/test/MGLLineStyleLayerTests.mm | 20 ++-- platform/darwin/test/MGLStyleLayerTests.mm.ejs | 4 +- platform/darwin/test/MGLSymbolStyleLayerTests.mm | 8 +- src/mbgl/style/conversion/stringify.hpp | 20 ++-- test/style/conversion/stringify.test.cpp | 9 +- 13 files changed, 268 insertions(+), 149 deletions(-) create mode 100644 include/mbgl/style/function/composite_categorical_stops.hpp create mode 100644 include/mbgl/style/function/composite_exponential_stops.hpp create mode 100644 include/mbgl/style/function/composite_interval_stops.hpp diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 7d69fa55c5..1f7a3fe778 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -282,6 +282,72 @@ struct Converter> { } }; +template +struct Converter> { + static constexpr const char * type = "exponential"; + + template + Result> operator()(const V& value) const { + auto stops = convertStops, 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> convertedStops; + for (const auto& stop : *stops) { + convertedStops[stop.first.first].emplace(stop.first.second, stop.second); + } + + return CompositeExponentialStops(convertedStops, base); + } +}; + +template +struct Converter> { + static constexpr const char * type = "interval"; + + template + Result> operator()(const V& value) const { + auto stops = convertStops, T>(value); + if (!stops) { + return stops.error(); + } + + std::map> convertedStops; + for (const auto& stop : *stops) { + convertedStops[stop.first.first].emplace(stop.first.second, stop.second); + } + + return CompositeIntervalStops(convertedStops); + } +}; + +template +struct Converter> { + static constexpr const char * type = "categorical"; + + template + Result> operator()(const V& value) const { + auto stops = convertStops, T>(value); + if (!stops) { + return stops.error(); + } + + std::map> convertedStops; + for (const auto& stop : *stops) { + convertedStops[stop.first.first].emplace(stop.first.second, stop.second); + } + + return CompositeCategoricalStops(convertedStops); + } +}; + template struct Converter> { template @@ -300,66 +366,17 @@ struct Converter> { return Error { "function property must be a string" }; } + auto stops = StopsConverter::Stops>()(value); + if (!stops) { + return stops.error(); + } + auto defaultValue = convertDefaultValue(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, 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> 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(*propertyString, convertedStops, *defaultValue); - } else if (type == "interval") { - auto stops = convertStops, T>(value); - if (!stops) { - return stops.error(); - } - - std::map> convertedStops; - for (const auto& stop : *stops) { - auto& inner = convertedStops[stop.first.first]; - inner.stops.emplace(stop.first.second, stop.second); - } - - return CompositeFunction(*propertyString, convertedStops, *defaultValue); - } else if (type == "categorical") { - auto stops = convertStops, T>(value); - if (!stops) { - return stops.error(); - } - - std::map> convertedStops; - for (const auto& stop : *stops) { - auto& inner = convertedStops[stop.first.first]; - inner.stops.emplace(stop.first.second, stop.second); - } - - return CompositeFunction(*propertyString, convertedStops, *defaultValue); - } else { - return Error { "unsupported function type" }; - } + return CompositeFunction(*propertyString, *stops, *defaultValue); } }; diff --git a/include/mbgl/style/function/composite_categorical_stops.hpp b/include/mbgl/style/function/composite_categorical_stops.hpp new file mode 100644 index 0000000000..b796621d1a --- /dev/null +++ b/include/mbgl/style/function/composite_categorical_stops.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace mbgl { +namespace style { + +template +class CompositeCategoricalStops { +public: + using Stops = std::map>; + Stops stops; + + CompositeCategoricalStops() = default; + CompositeCategoricalStops(Stops stops_) + : stops(std::move(stops_)) { + } + + CategoricalStops innerStops(const std::map& stops_) const { + return CategoricalStops(stops_); + } + + friend bool operator==(const CompositeCategoricalStops& lhs, + const CompositeCategoricalStops& rhs) { + return lhs.stops == rhs.stops; + } +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/function/composite_exponential_stops.hpp b/include/mbgl/style/function/composite_exponential_stops.hpp new file mode 100644 index 0000000000..f1ad32a04d --- /dev/null +++ b/include/mbgl/style/function/composite_exponential_stops.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include + +#include + +namespace mbgl { +namespace style { + +template +class CompositeExponentialStops { +public: + using Stops = std::map>; + + Stops stops; + float base = 1.0f; + + CompositeExponentialStops() = default; + CompositeExponentialStops(Stops stops_, float base_ = 1.0f) + : stops(std::move(stops_)), + base(base_) { + } + + ExponentialStops innerStops(const std::map& stops_) const { + return ExponentialStops(stops_, base); + } + + friend bool operator==(const CompositeExponentialStops& lhs, + const CompositeExponentialStops& rhs) { + return lhs.stops == rhs.stops && lhs.base == rhs.base; + } +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp index f42a5f06f4..be238fe9c3 100644 --- a/include/mbgl/style/function/composite_function.hpp +++ b/include/mbgl/style/function/composite_function.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include +#include +#include +#include #include #include #include @@ -36,12 +36,12 @@ public: using Stops = std::conditional_t< util::Interpolatable, variant< - std::map>, - std::map>, - std::map>>, + CompositeExponentialStops, + CompositeIntervalStops, + CompositeCategoricalStops>, variant< - std::map>, - std::map>>>; + CompositeIntervalStops, + CompositeCategoricalStops>>; CompositeFunction(std::string property_, Stops stops_, optional 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 { - 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 { - 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) } ); } diff --git a/include/mbgl/style/function/composite_interval_stops.hpp b/include/mbgl/style/function/composite_interval_stops.hpp new file mode 100644 index 0000000000..3c495f2a7f --- /dev/null +++ b/include/mbgl/style/function/composite_interval_stops.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include + +namespace mbgl { +namespace style { + +template +class CompositeIntervalStops { +public: + using Stops = std::map>; + Stops stops; + + CompositeIntervalStops() = default; + CompositeIntervalStops(Stops stops_) + : stops(std::move(stops_)) { + } + + IntervalStops innerStops(const std::map& stops_) const { + return IntervalStops(stops_); + } + + friend bool operator==(const CompositeIntervalStops& lhs, + const CompositeIntervalStops& rhs) { + return lhs.stops == rhs.stops; + } +}; + +} // namespace style +} // namespace mbgl diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 03a8f242cf..759c96c6bd 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -155,7 +155,7 @@ public: MGLCompositeStyleFunction *compositeStyleFunction = (MGLCompositeStyleFunction *)value; switch (compositeStyleFunction.interpolationMode) { case MGLInterpolationModeExponential: { - __block std::map> outerStops = {}; + __block std::map> outerStops = {}; [compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) { std::map 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 innerStops = {stops, (float)compositeStyleFunction.interpolationBase}; - outerStops[zoomKey.floatValue] = innerStops; + outerStops[zoomKey.floatValue] = stops; }]; - mbgl::style::CompositeFunction compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops}; + mbgl::style::CompositeFunction compositeFunction { + compositeStyleFunction.attributeName.UTF8String, + mbgl::style::CompositeExponentialStops { 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> outerStops = {}; + __block std::map> outerStops = {}; [compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) { std::map 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 innerStops = {stops}; - outerStops[zoomKey.floatValue] = innerStops; + outerStops[zoomKey.floatValue] = stops; }]; - mbgl::style::CompositeFunction compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops}; + mbgl::style::CompositeFunction compositeFunction { + compositeStyleFunction.attributeName.UTF8String, + mbgl::style::CompositeIntervalStops { 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> outerStops = {}; + __block std::map> outerStops = {}; [compositeStyleFunction.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSDictionary * _Nonnull stopValue, BOOL * _Nonnull stop) { __block std::map stops = {}; [stopValue enumerateKeysAndObjectsUsingBlock:^(id _Nonnull categoryKey, MGLStyleValue * _Nonnull innerValue, BOOL * _Nonnull stop) { @@ -233,10 +237,12 @@ public: } } }]; - mbgl::style::CategoricalStops categoricalStops = {stops}; - outerStops[zoomKey.floatValue] = categoricalStops; + outerStops[zoomKey.floatValue] = stops; }]; - mbgl::style::CompositeFunction compositeFunction = {compositeStyleFunction.attributeName.UTF8String, outerStops}; + mbgl::style::CompositeFunction compositeFunction { + compositeStyleFunction.attributeName.UTF8String, + mbgl::style::CompositeCategoricalStops { 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> &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 &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> &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 &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> &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 &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; diff --git a/platform/darwin/test/MGLCircleStyleLayerTests.mm b/platform/darwin/test/MGLCircleStyleLayerTests.mm index 2bf8aab195..2976093708 100644 --- a/platform/darwin/test/MGLCircleStyleLayerTests.mm +++ b/platform/darwin/test/MGLCircleStyleLayerTests.mm @@ -82,8 +82,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleBlur = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -139,8 +139,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleColor = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, { 1, 0, 0, 1 }} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -196,8 +196,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleOpacity = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -253,8 +253,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleRadius = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -350,8 +350,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleStrokeColor = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, { 1, 0, 0, 1 }} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -407,8 +407,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleStrokeOpacity = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -464,8 +464,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.circleStrokeWidth = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; diff --git a/platform/darwin/test/MGLFillStyleLayerTests.mm b/platform/darwin/test/MGLFillStyleLayerTests.mm index 9aeba53174..b3e0465c87 100644 --- a/platform/darwin/test/MGLFillStyleLayerTests.mm +++ b/platform/darwin/test/MGLFillStyleLayerTests.mm @@ -122,8 +122,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.fillColor = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, { 1, 0, 0, 1 }} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -179,8 +179,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.fillOpacity = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -236,8 +236,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.fillOutlineColor = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, { 1, 0, 0, 1 }} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; diff --git a/platform/darwin/test/MGLLineStyleLayerTests.mm b/platform/darwin/test/MGLLineStyleLayerTests.mm index e150dca0e4..dea3320dea 100644 --- a/platform/darwin/test/MGLLineStyleLayerTests.mm +++ b/platform/darwin/test/MGLLineStyleLayerTests.mm @@ -230,8 +230,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.lineBlur = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -287,8 +287,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.lineColor = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, { 1, 0, 0, 1 }}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, { 1, 0, 0, 1 }} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -384,8 +384,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.lineGapWidth = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -441,8 +441,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.lineOffset = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; @@ -498,8 +498,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.lineOpacity = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; diff --git a/platform/darwin/test/MGLStyleLayerTests.mm.ejs b/platform/darwin/test/MGLStyleLayerTests.mm.ejs index baa5337430..bc5a3cdde0 100644 --- a/platform/darwin/test/MGLStyleLayerTests.mm.ejs +++ b/platform/darwin/test/MGLStyleLayerTests.mm.ejs @@ -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>> compositeStops = { {10.0, innerStops} }; + std::map> innerStops { {18, <%- mbglTestValue(property, type) %>} }; + mbgl::style::CompositeExponentialStops<<%- mbglType(property) %>> compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction<<%- mbglType(property) %>> { "keyName", compositeStops }; diff --git a/platform/darwin/test/MGLSymbolStyleLayerTests.mm b/platform/darwin/test/MGLSymbolStyleLayerTests.mm index badd62e709..481f8fbb1d 100644 --- a/platform/darwin/test/MGLSymbolStyleLayerTests.mm +++ b/platform/darwin/test/MGLSymbolStyleLayerTests.mm @@ -208,8 +208,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.iconOffset = functionStyleValue; - mbgl::style::ExponentialStops> innerStops = { { {18, { 1, 1 }}}, 1.0 }; - std::map>> compositeStops = { {10.0, innerStops} }; + std::map> innerStops { {18, { 1, 1 }} }; + mbgl::style::CompositeExponentialStops> compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction> { "keyName", compositeStops }; @@ -339,8 +339,8 @@ functionStyleValue = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential compositeStops:@{@10: @{@18: constantStyleValue}} attributeName:@"keyName" options:nil]; layer.iconRotation = functionStyleValue; - mbgl::style::ExponentialStops innerStops = { { {18, 0xff}}, 1.0 }; - std::map> compositeStops = { {10.0, innerStops} }; + std::map innerStops { {18, 0xff} }; + mbgl::style::CompositeExponentialStops compositeStops { { {10.0, innerStops} }, 1.0 }; propertyValue = mbgl::style::CompositeFunction { "keyName", compositeStops }; diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 5aab1076fd..4b9cf6d26e 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -257,31 +257,29 @@ public: } template - void operator()(const std::map>& f) { + void operator()(const CompositeExponentialStops& 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 - void operator()(const std::map>& f) { + void operator()(const CompositeIntervalStops& f) { writer.Key("type"); writer.String("interval"); writer.Key("stops"); - stringifyCompositeStops(f); + stringifyCompositeStops(f.stops); } template - void operator()(const std::map>& f) { + void operator()(const CompositeCategoricalStops& 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& 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"); diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index dd04789d4b..1dae20b26b 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -101,9 +101,12 @@ TEST(Stringify, SourceFunction) { TEST(Stringify, CompositeFunction) { ASSERT_EQ(stringify(CompositeFunction("property", - std::map> { - { 0, ExponentialStops { {{0, 1}}, 2 } }, - { 1, ExponentialStops { {{0, 1}}, 2 } } + CompositeExponentialStops { + { + { 0, {{0, 1}} }, + { 1, {{0, 1}} } + }, + 2 }, 0.0f)), "{\"property\":\"property\",\"type\":\"exponential\",\"base\":2.0," "\"stops\":[" -- cgit v1.2.1