diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-07 12:35:27 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-02-09 11:16:26 -0600 |
commit | f35ca0d9dfc8a6ba88273edbeda43e633ae0adce (patch) | |
tree | 74c11b9c7125c22516a5cbc46322763a72964c43 /platform/darwin/src | |
parent | 9df24addfbfd922baada7d9778f402b91e69ed33 (diff) | |
download | qtlocation-mapboxgl-f35ca0d9dfc8a6ba88273edbeda43e633ae0adce.tar.gz |
[core, ios, macos] Refactor composite stop types and conversions
Diffstat (limited to 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLStyleValue_Private.h | 60 |
1 files changed, 32 insertions, 28 deletions
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<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; |