diff options
26 files changed, 767 insertions, 684 deletions
diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/layer/background_layer.hpp index 79f24990e6..211597f6ea 100644 --- a/include/mbgl/layer/background_layer.hpp +++ b/include/mbgl/layer/background_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> namespace mbgl { @@ -13,14 +14,14 @@ public: // Paint properties - Function<Color> getBackgroundColor() const; - void setBackgroundColor(Function<Color>); + PropertyValue<Color> getBackgroundColor() const; + void setBackgroundColor(PropertyValue<Color>); - Function<std::string> getBackgroundPattern() const; - void setBackgroundPattern(Function<std::string>); + PropertyValue<std::string> getBackgroundPattern() const; + void setBackgroundPattern(PropertyValue<std::string>); - Function<float> getBackgroundOpacity() const; - void setBackgroundOpacity(Function<float>); + PropertyValue<float> getBackgroundOpacity() const; + void setBackgroundOpacity(PropertyValue<float>); // Private implementation diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/layer/circle_layer.hpp index 14b9da895f..28e5c2fa7a 100644 --- a/include/mbgl/layer/circle_layer.hpp +++ b/include/mbgl/layer/circle_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> namespace mbgl { @@ -19,23 +20,23 @@ public: // Paint properties - Function<float> getCircleRadius() const; - void setCircleRadius(Function<float>); + PropertyValue<float> getCircleRadius() const; + void setCircleRadius(PropertyValue<float>); - Function<Color> getCircleColor() const; - void setCircleColor(Function<Color>); + PropertyValue<Color> getCircleColor() const; + void setCircleColor(PropertyValue<Color>); - Function<float> getCircleBlur() const; - void setCircleBlur(Function<float>); + PropertyValue<float> getCircleBlur() const; + void setCircleBlur(PropertyValue<float>); - Function<float> getCircleOpacity() const; - void setCircleOpacity(Function<float>); + PropertyValue<float> getCircleOpacity() const; + void setCircleOpacity(PropertyValue<float>); - Function<std::array<float, 2>> getCircleTranslate() const; - void setCircleTranslate(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getCircleTranslate() const; + void setCircleTranslate(PropertyValue<std::array<float, 2>>); - Function<TranslateAnchorType> getCircleTranslateAnchor() const; - void setCircleTranslateAnchor(Function<TranslateAnchorType>); + PropertyValue<TranslateAnchorType> getCircleTranslateAnchor() const; + void setCircleTranslateAnchor(PropertyValue<TranslateAnchorType>); // Private implementation diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/layer/fill_layer.hpp index dc0752f9e2..76c043957d 100644 --- a/include/mbgl/layer/fill_layer.hpp +++ b/include/mbgl/layer/fill_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> namespace mbgl { @@ -19,26 +20,26 @@ public: // Paint properties - Function<bool> getFillAntialias() const; - void setFillAntialias(Function<bool>); + PropertyValue<bool> getFillAntialias() const; + void setFillAntialias(PropertyValue<bool>); - Function<float> getFillOpacity() const; - void setFillOpacity(Function<float>); + PropertyValue<float> getFillOpacity() const; + void setFillOpacity(PropertyValue<float>); - Function<Color> getFillColor() const; - void setFillColor(Function<Color>); + PropertyValue<Color> getFillColor() const; + void setFillColor(PropertyValue<Color>); - Function<Color> getFillOutlineColor() const; - void setFillOutlineColor(Function<Color>); + PropertyValue<Color> getFillOutlineColor() const; + void setFillOutlineColor(PropertyValue<Color>); - Function<std::array<float, 2>> getFillTranslate() const; - void setFillTranslate(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getFillTranslate() const; + void setFillTranslate(PropertyValue<std::array<float, 2>>); - Function<TranslateAnchorType> getFillTranslateAnchor() const; - void setFillTranslateAnchor(Function<TranslateAnchorType>); + PropertyValue<TranslateAnchorType> getFillTranslateAnchor() const; + void setFillTranslateAnchor(PropertyValue<TranslateAnchorType>); - Function<std::string> getFillPattern() const; - void setFillPattern(Function<std::string>); + PropertyValue<std::string> getFillPattern() const; + void setFillPattern(PropertyValue<std::string>); // Private implementation diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/layer/line_layer.hpp index 0f898d3c69..b438799116 100644 --- a/include/mbgl/layer/line_layer.hpp +++ b/include/mbgl/layer/line_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> #include <vector> @@ -21,49 +22,49 @@ public: // Layout properties - Function<LineCapType> getLineCap() const; - void setLineCap(Function<LineCapType>); + PropertyValue<LineCapType> getLineCap() const; + void setLineCap(PropertyValue<LineCapType>); - Function<LineJoinType> getLineJoin() const; - void setLineJoin(Function<LineJoinType>); + PropertyValue<LineJoinType> getLineJoin() const; + void setLineJoin(PropertyValue<LineJoinType>); - Function<float> getLineMiterLimit() const; - void setLineMiterLimit(Function<float>); + PropertyValue<float> getLineMiterLimit() const; + void setLineMiterLimit(PropertyValue<float>); - Function<float> getLineRoundLimit() const; - void setLineRoundLimit(Function<float>); + PropertyValue<float> getLineRoundLimit() const; + void setLineRoundLimit(PropertyValue<float>); // Paint properties - Function<float> getLineOpacity() const; - void setLineOpacity(Function<float>); + PropertyValue<float> getLineOpacity() const; + void setLineOpacity(PropertyValue<float>); - Function<Color> getLineColor() const; - void setLineColor(Function<Color>); + PropertyValue<Color> getLineColor() const; + void setLineColor(PropertyValue<Color>); - Function<std::array<float, 2>> getLineTranslate() const; - void setLineTranslate(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getLineTranslate() const; + void setLineTranslate(PropertyValue<std::array<float, 2>>); - Function<TranslateAnchorType> getLineTranslateAnchor() const; - void setLineTranslateAnchor(Function<TranslateAnchorType>); + PropertyValue<TranslateAnchorType> getLineTranslateAnchor() const; + void setLineTranslateAnchor(PropertyValue<TranslateAnchorType>); - Function<float> getLineWidth() const; - void setLineWidth(Function<float>); + PropertyValue<float> getLineWidth() const; + void setLineWidth(PropertyValue<float>); - Function<float> getLineGapWidth() const; - void setLineGapWidth(Function<float>); + PropertyValue<float> getLineGapWidth() const; + void setLineGapWidth(PropertyValue<float>); - Function<float> getLineOffset() const; - void setLineOffset(Function<float>); + PropertyValue<float> getLineOffset() const; + void setLineOffset(PropertyValue<float>); - Function<float> getLineBlur() const; - void setLineBlur(Function<float>); + PropertyValue<float> getLineBlur() const; + void setLineBlur(PropertyValue<float>); - Function<std::vector<float>> getLineDasharray() const; - void setLineDasharray(Function<std::vector<float>>); + PropertyValue<std::vector<float>> getLineDasharray() const; + void setLineDasharray(PropertyValue<std::vector<float>>); - Function<std::string> getLinePattern() const; - void setLinePattern(Function<std::string>); + PropertyValue<std::string> getLinePattern() const; + void setLinePattern(PropertyValue<std::string>); // Private implementation diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/layer/raster_layer.hpp index 9dc27a274a..5d747737c0 100644 --- a/include/mbgl/layer/raster_layer.hpp +++ b/include/mbgl/layer/raster_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> namespace mbgl { @@ -18,26 +19,26 @@ public: // Paint properties - Function<float> getRasterOpacity() const; - void setRasterOpacity(Function<float>); + PropertyValue<float> getRasterOpacity() const; + void setRasterOpacity(PropertyValue<float>); - Function<float> getRasterHueRotate() const; - void setRasterHueRotate(Function<float>); + PropertyValue<float> getRasterHueRotate() const; + void setRasterHueRotate(PropertyValue<float>); - Function<float> getRasterBrightnessMin() const; - void setRasterBrightnessMin(Function<float>); + PropertyValue<float> getRasterBrightnessMin() const; + void setRasterBrightnessMin(PropertyValue<float>); - Function<float> getRasterBrightnessMax() const; - void setRasterBrightnessMax(Function<float>); + PropertyValue<float> getRasterBrightnessMax() const; + void setRasterBrightnessMax(PropertyValue<float>); - Function<float> getRasterSaturation() const; - void setRasterSaturation(Function<float>); + PropertyValue<float> getRasterSaturation() const; + void setRasterSaturation(PropertyValue<float>); - Function<float> getRasterContrast() const; - void setRasterContrast(Function<float>); + PropertyValue<float> getRasterContrast() const; + void setRasterContrast(PropertyValue<float>); - Function<float> getRasterFadeDuration() const; - void setRasterFadeDuration(Function<float>); + PropertyValue<float> getRasterFadeDuration() const; + void setRasterFadeDuration(PropertyValue<float>); // Private implementation diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/layer/symbol_layer.hpp index f9b2956390..2339515201 100644 --- a/include/mbgl/layer/symbol_layer.hpp +++ b/include/mbgl/layer/symbol_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include <mbgl/style/layer.hpp> +#include <mbgl/style/property_value.hpp> #include <vector> @@ -21,142 +22,142 @@ public: // Layout properties - Function<SymbolPlacementType> getSymbolPlacement() const; - void setSymbolPlacement(Function<SymbolPlacementType>); + PropertyValue<SymbolPlacementType> getSymbolPlacement() const; + void setSymbolPlacement(PropertyValue<SymbolPlacementType>); - Function<float> getSymbolSpacing() const; - void setSymbolSpacing(Function<float>); + PropertyValue<float> getSymbolSpacing() const; + void setSymbolSpacing(PropertyValue<float>); - Function<bool> getSymbolAvoidEdges() const; - void setSymbolAvoidEdges(Function<bool>); + PropertyValue<bool> getSymbolAvoidEdges() const; + void setSymbolAvoidEdges(PropertyValue<bool>); - Function<bool> getIconAllowOverlap() const; - void setIconAllowOverlap(Function<bool>); + PropertyValue<bool> getIconAllowOverlap() const; + void setIconAllowOverlap(PropertyValue<bool>); - Function<bool> getIconIgnorePlacement() const; - void setIconIgnorePlacement(Function<bool>); + PropertyValue<bool> getIconIgnorePlacement() const; + void setIconIgnorePlacement(PropertyValue<bool>); - Function<bool> getIconOptional() const; - void setIconOptional(Function<bool>); + PropertyValue<bool> getIconOptional() const; + void setIconOptional(PropertyValue<bool>); - Function<RotationAlignmentType> getIconRotationAlignment() const; - void setIconRotationAlignment(Function<RotationAlignmentType>); + PropertyValue<RotationAlignmentType> getIconRotationAlignment() const; + void setIconRotationAlignment(PropertyValue<RotationAlignmentType>); - Function<float> getIconSize() const; - void setIconSize(Function<float>); + PropertyValue<float> getIconSize() const; + void setIconSize(PropertyValue<float>); - Function<std::string> getIconImage() const; - void setIconImage(Function<std::string>); + PropertyValue<std::string> getIconImage() const; + void setIconImage(PropertyValue<std::string>); - Function<float> getIconRotate() const; - void setIconRotate(Function<float>); + PropertyValue<float> getIconRotate() const; + void setIconRotate(PropertyValue<float>); - Function<float> getIconPadding() const; - void setIconPadding(Function<float>); + PropertyValue<float> getIconPadding() const; + void setIconPadding(PropertyValue<float>); - Function<bool> getIconKeepUpright() const; - void setIconKeepUpright(Function<bool>); + PropertyValue<bool> getIconKeepUpright() const; + void setIconKeepUpright(PropertyValue<bool>); - Function<std::array<float, 2>> getIconOffset() const; - void setIconOffset(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getIconOffset() const; + void setIconOffset(PropertyValue<std::array<float, 2>>); - Function<RotationAlignmentType> getTextRotationAlignment() const; - void setTextRotationAlignment(Function<RotationAlignmentType>); + PropertyValue<RotationAlignmentType> getTextRotationAlignment() const; + void setTextRotationAlignment(PropertyValue<RotationAlignmentType>); - Function<std::string> getTextField() const; - void setTextField(Function<std::string>); + PropertyValue<std::string> getTextField() const; + void setTextField(PropertyValue<std::string>); - Function<std::vector<std::string>> getTextFont() const; - void setTextFont(Function<std::vector<std::string>>); + PropertyValue<std::vector<std::string>> getTextFont() const; + void setTextFont(PropertyValue<std::vector<std::string>>); - Function<float> getTextSize() const; - void setTextSize(Function<float>); + PropertyValue<float> getTextSize() const; + void setTextSize(PropertyValue<float>); - Function<float> getTextMaxWidth() const; - void setTextMaxWidth(Function<float>); + PropertyValue<float> getTextMaxWidth() const; + void setTextMaxWidth(PropertyValue<float>); - Function<float> getTextLineHeight() const; - void setTextLineHeight(Function<float>); + PropertyValue<float> getTextLineHeight() const; + void setTextLineHeight(PropertyValue<float>); - Function<float> getTextLetterSpacing() const; - void setTextLetterSpacing(Function<float>); + PropertyValue<float> getTextLetterSpacing() const; + void setTextLetterSpacing(PropertyValue<float>); - Function<TextJustifyType> getTextJustify() const; - void setTextJustify(Function<TextJustifyType>); + PropertyValue<TextJustifyType> getTextJustify() const; + void setTextJustify(PropertyValue<TextJustifyType>); - Function<TextAnchorType> getTextAnchor() const; - void setTextAnchor(Function<TextAnchorType>); + PropertyValue<TextAnchorType> getTextAnchor() const; + void setTextAnchor(PropertyValue<TextAnchorType>); - Function<float> getTextMaxAngle() const; - void setTextMaxAngle(Function<float>); + PropertyValue<float> getTextMaxAngle() const; + void setTextMaxAngle(PropertyValue<float>); - Function<float> getTextRotate() const; - void setTextRotate(Function<float>); + PropertyValue<float> getTextRotate() const; + void setTextRotate(PropertyValue<float>); - Function<float> getTextPadding() const; - void setTextPadding(Function<float>); + PropertyValue<float> getTextPadding() const; + void setTextPadding(PropertyValue<float>); - Function<bool> getTextKeepUpright() const; - void setTextKeepUpright(Function<bool>); + PropertyValue<bool> getTextKeepUpright() const; + void setTextKeepUpright(PropertyValue<bool>); - Function<TextTransformType> getTextTransform() const; - void setTextTransform(Function<TextTransformType>); + PropertyValue<TextTransformType> getTextTransform() const; + void setTextTransform(PropertyValue<TextTransformType>); - Function<std::array<float, 2>> getTextOffset() const; - void setTextOffset(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getTextOffset() const; + void setTextOffset(PropertyValue<std::array<float, 2>>); - Function<bool> getTextAllowOverlap() const; - void setTextAllowOverlap(Function<bool>); + PropertyValue<bool> getTextAllowOverlap() const; + void setTextAllowOverlap(PropertyValue<bool>); - Function<bool> getTextIgnorePlacement() const; - void setTextIgnorePlacement(Function<bool>); + PropertyValue<bool> getTextIgnorePlacement() const; + void setTextIgnorePlacement(PropertyValue<bool>); - Function<bool> getTextOptional() const; - void setTextOptional(Function<bool>); + PropertyValue<bool> getTextOptional() const; + void setTextOptional(PropertyValue<bool>); // Paint properties - Function<float> getIconOpacity() const; - void setIconOpacity(Function<float>); + PropertyValue<float> getIconOpacity() const; + void setIconOpacity(PropertyValue<float>); - Function<Color> getIconColor() const; - void setIconColor(Function<Color>); + PropertyValue<Color> getIconColor() const; + void setIconColor(PropertyValue<Color>); - Function<Color> getIconHaloColor() const; - void setIconHaloColor(Function<Color>); + PropertyValue<Color> getIconHaloColor() const; + void setIconHaloColor(PropertyValue<Color>); - Function<float> getIconHaloWidth() const; - void setIconHaloWidth(Function<float>); + PropertyValue<float> getIconHaloWidth() const; + void setIconHaloWidth(PropertyValue<float>); - Function<float> getIconHaloBlur() const; - void setIconHaloBlur(Function<float>); + PropertyValue<float> getIconHaloBlur() const; + void setIconHaloBlur(PropertyValue<float>); - Function<std::array<float, 2>> getIconTranslate() const; - void setIconTranslate(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getIconTranslate() const; + void setIconTranslate(PropertyValue<std::array<float, 2>>); - Function<TranslateAnchorType> getIconTranslateAnchor() const; - void setIconTranslateAnchor(Function<TranslateAnchorType>); + PropertyValue<TranslateAnchorType> getIconTranslateAnchor() const; + void setIconTranslateAnchor(PropertyValue<TranslateAnchorType>); - Function<float> getTextOpacity() const; - void setTextOpacity(Function<float>); + PropertyValue<float> getTextOpacity() const; + void setTextOpacity(PropertyValue<float>); - Function<Color> getTextColor() const; - void setTextColor(Function<Color>); + PropertyValue<Color> getTextColor() const; + void setTextColor(PropertyValue<Color>); - Function<Color> getTextHaloColor() const; - void setTextHaloColor(Function<Color>); + PropertyValue<Color> getTextHaloColor() const; + void setTextHaloColor(PropertyValue<Color>); - Function<float> getTextHaloWidth() const; - void setTextHaloWidth(Function<float>); + PropertyValue<float> getTextHaloWidth() const; + void setTextHaloWidth(PropertyValue<float>); - Function<float> getTextHaloBlur() const; - void setTextHaloBlur(Function<float>); + PropertyValue<float> getTextHaloBlur() const; + void setTextHaloBlur(PropertyValue<float>); - Function<std::array<float, 2>> getTextTranslate() const; - void setTextTranslate(Function<std::array<float, 2>>); + PropertyValue<std::array<float, 2>> getTextTranslate() const; + void setTextTranslate(PropertyValue<std::array<float, 2>>); - Function<TranslateAnchorType> getTextTranslateAnchor() const; - void setTextTranslateAnchor(Function<TranslateAnchorType>); + PropertyValue<TranslateAnchorType> getTextTranslateAnchor() const; + void setTextTranslateAnchor(PropertyValue<TranslateAnchorType>); // Private implementation diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index ea09ccfb0c..56f3570357 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -27,9 +27,6 @@ public: using Stop = std::pair<float, T>; using Stops = std::vector<Stop>; - Function(const T& constant) - : stops({{ 0, constant }}) {} - explicit Function(const Stops& stops_, float base_) : base(base_), stops(stops_) {} diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 2904a1429a..b26e0520f6 100644 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -77,10 +77,12 @@ const layerHpp = ejs.compile(`<% #pragma once #include <mbgl/style/layer.hpp> -<% if (type === 'line' || type === 'symbol') { %> +#include <mbgl/style/property_value.hpp> + +<% if (type === 'line' || type === 'symbol') { -%> #include <vector> -<% } -%> +<% } -%> namespace mbgl { class <%- camelize(type) %>Layer : public Layer { @@ -106,16 +108,16 @@ public: // Layout properties <% for (const property of layoutProperties) { -%> - Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; - void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>); <% } -%> <% } -%> // Paint properties <% for (const property of paintProperties) { -%> - Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; - void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>); <% } -%> // Private implementation @@ -194,23 +196,23 @@ const std::string& <%- camelize(type) %>Layer::getSourceLayer() const { // Layout properties <% for (const property of layoutProperties) { -%> -Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return *impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue; +PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.get(); } -void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { - impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue = value; +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { + impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); } <% } -%> // Paint properties <% for (const property of paintProperties) { %> -Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.at(ClassID::Default); +PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get(); } -void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { - impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.emplace(ClassID::Default, value); +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { + impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); } <% } -%> @@ -255,7 +257,7 @@ public: <% for (const property of paintProperties) { -%> <% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> - PaintProperty<<%- propertyType(property) %>, CrossFadedFunctionEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; + PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } else if (property.name === 'fill-outline-color') { -%> PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} }; <% } else { -%> diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp index 8d097344fc..36cf6be07c 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/layer/background_layer.cpp @@ -28,28 +28,28 @@ std::unique_ptr<Layer> BackgroundLayer::Impl::clone() const { // Paint properties -Function<Color> BackgroundLayer::getBackgroundColor() const { - return impl->paint.backgroundColor.values.at(ClassID::Default); +PropertyValue<Color> BackgroundLayer::getBackgroundColor() const { + return impl->paint.backgroundColor.get(); } -void BackgroundLayer::setBackgroundColor(Function<Color> value) { - impl->paint.backgroundColor.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundColor(PropertyValue<Color> value) { + impl->paint.backgroundColor.set(value); } -Function<std::string> BackgroundLayer::getBackgroundPattern() const { - return impl->paint.backgroundPattern.values.at(ClassID::Default); +PropertyValue<std::string> BackgroundLayer::getBackgroundPattern() const { + return impl->paint.backgroundPattern.get(); } -void BackgroundLayer::setBackgroundPattern(Function<std::string> value) { - impl->paint.backgroundPattern.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundPattern(PropertyValue<std::string> value) { + impl->paint.backgroundPattern.set(value); } -Function<float> BackgroundLayer::getBackgroundOpacity() const { - return impl->paint.backgroundOpacity.values.at(ClassID::Default); +PropertyValue<float> BackgroundLayer::getBackgroundOpacity() const { + return impl->paint.backgroundOpacity.get(); } -void BackgroundLayer::setBackgroundOpacity(Function<float> value) { - impl->paint.backgroundOpacity.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundOpacity(PropertyValue<float> value) { + impl->paint.backgroundOpacity.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.hpp b/src/mbgl/layer/background_layer_properties.hpp index 5e388a7928..20db9b22fb 100644 --- a/src/mbgl/layer/background_layer_properties.hpp +++ b/src/mbgl/layer/background_layer_properties.hpp @@ -18,7 +18,7 @@ public: bool recalculate(const StyleCalculationParameters&); PaintProperty<Color> backgroundColor { {{ 0, 0, 0, 1 }} }; - PaintProperty<std::string, CrossFadedFunctionEvaluator> backgroundPattern { "" }; + PaintProperty<std::string, CrossFadedPropertyEvaluator> backgroundPattern { "" }; PaintProperty<float> backgroundOpacity { 1 }; }; diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index bf385c997c..b1ca06dff7 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -42,52 +42,52 @@ const std::string& CircleLayer::getSourceLayer() const { // Paint properties -Function<float> CircleLayer::getCircleRadius() const { - return impl->paint.circleRadius.values.at(ClassID::Default); +PropertyValue<float> CircleLayer::getCircleRadius() const { + return impl->paint.circleRadius.get(); } -void CircleLayer::setCircleRadius(Function<float> value) { - impl->paint.circleRadius.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleRadius(PropertyValue<float> value) { + impl->paint.circleRadius.set(value); } -Function<Color> CircleLayer::getCircleColor() const { - return impl->paint.circleColor.values.at(ClassID::Default); +PropertyValue<Color> CircleLayer::getCircleColor() const { + return impl->paint.circleColor.get(); } -void CircleLayer::setCircleColor(Function<Color> value) { - impl->paint.circleColor.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleColor(PropertyValue<Color> value) { + impl->paint.circleColor.set(value); } -Function<float> CircleLayer::getCircleBlur() const { - return impl->paint.circleBlur.values.at(ClassID::Default); +PropertyValue<float> CircleLayer::getCircleBlur() const { + return impl->paint.circleBlur.get(); } -void CircleLayer::setCircleBlur(Function<float> value) { - impl->paint.circleBlur.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleBlur(PropertyValue<float> value) { + impl->paint.circleBlur.set(value); } -Function<float> CircleLayer::getCircleOpacity() const { - return impl->paint.circleOpacity.values.at(ClassID::Default); +PropertyValue<float> CircleLayer::getCircleOpacity() const { + return impl->paint.circleOpacity.get(); } -void CircleLayer::setCircleOpacity(Function<float> value) { - impl->paint.circleOpacity.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleOpacity(PropertyValue<float> value) { + impl->paint.circleOpacity.set(value); } -Function<std::array<float, 2>> CircleLayer::getCircleTranslate() const { - return impl->paint.circleTranslate.values.at(ClassID::Default); +PropertyValue<std::array<float, 2>> CircleLayer::getCircleTranslate() const { + return impl->paint.circleTranslate.get(); } -void CircleLayer::setCircleTranslate(Function<std::array<float, 2>> value) { - impl->paint.circleTranslate.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleTranslate(PropertyValue<std::array<float, 2>> value) { + impl->paint.circleTranslate.set(value); } -Function<TranslateAnchorType> CircleLayer::getCircleTranslateAnchor() const { - return impl->paint.circleTranslateAnchor.values.at(ClassID::Default); +PropertyValue<TranslateAnchorType> CircleLayer::getCircleTranslateAnchor() const { + return impl->paint.circleTranslateAnchor.get(); } -void CircleLayer::setCircleTranslateAnchor(Function<TranslateAnchorType> value) { - impl->paint.circleTranslateAnchor.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleTranslateAnchor(PropertyValue<TranslateAnchorType> value) { + impl->paint.circleTranslateAnchor.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index 9a376089df..f7a9418c0e 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -42,60 +42,60 @@ const std::string& FillLayer::getSourceLayer() const { // Paint properties -Function<bool> FillLayer::getFillAntialias() const { - return impl->paint.fillAntialias.values.at(ClassID::Default); +PropertyValue<bool> FillLayer::getFillAntialias() const { + return impl->paint.fillAntialias.get(); } -void FillLayer::setFillAntialias(Function<bool> value) { - impl->paint.fillAntialias.values.emplace(ClassID::Default, value); +void FillLayer::setFillAntialias(PropertyValue<bool> value) { + impl->paint.fillAntialias.set(value); } -Function<float> FillLayer::getFillOpacity() const { - return impl->paint.fillOpacity.values.at(ClassID::Default); +PropertyValue<float> FillLayer::getFillOpacity() const { + return impl->paint.fillOpacity.get(); } -void FillLayer::setFillOpacity(Function<float> value) { - impl->paint.fillOpacity.values.emplace(ClassID::Default, value); +void FillLayer::setFillOpacity(PropertyValue<float> value) { + impl->paint.fillOpacity.set(value); } -Function<Color> FillLayer::getFillColor() const { - return impl->paint.fillColor.values.at(ClassID::Default); +PropertyValue<Color> FillLayer::getFillColor() const { + return impl->paint.fillColor.get(); } -void FillLayer::setFillColor(Function<Color> value) { - impl->paint.fillColor.values.emplace(ClassID::Default, value); +void FillLayer::setFillColor(PropertyValue<Color> value) { + impl->paint.fillColor.set(value); } -Function<Color> FillLayer::getFillOutlineColor() const { - return impl->paint.fillOutlineColor.values.at(ClassID::Default); +PropertyValue<Color> FillLayer::getFillOutlineColor() const { + return impl->paint.fillOutlineColor.get(); } -void FillLayer::setFillOutlineColor(Function<Color> value) { - impl->paint.fillOutlineColor.values.emplace(ClassID::Default, value); +void FillLayer::setFillOutlineColor(PropertyValue<Color> value) { + impl->paint.fillOutlineColor.set(value); } -Function<std::array<float, 2>> FillLayer::getFillTranslate() const { - return impl->paint.fillTranslate.values.at(ClassID::Default); +PropertyValue<std::array<float, 2>> FillLayer::getFillTranslate() const { + return impl->paint.fillTranslate.get(); } -void FillLayer::setFillTranslate(Function<std::array<float, 2>> value) { - impl->paint.fillTranslate.values.emplace(ClassID::Default, value); +void FillLayer::setFillTranslate(PropertyValue<std::array<float, 2>> value) { + impl->paint.fillTranslate.set(value); } -Function<TranslateAnchorType> FillLayer::getFillTranslateAnchor() const { - return impl->paint.fillTranslateAnchor.values.at(ClassID::Default); +PropertyValue<TranslateAnchorType> FillLayer::getFillTranslateAnchor() const { + return impl->paint.fillTranslateAnchor.get(); } -void FillLayer::setFillTranslateAnchor(Function<TranslateAnchorType> value) { - impl->paint.fillTranslateAnchor.values.emplace(ClassID::Default, value); +void FillLayer::setFillTranslateAnchor(PropertyValue<TranslateAnchorType> value) { + impl->paint.fillTranslateAnchor.set(value); } -Function<std::string> FillLayer::getFillPattern() const { - return impl->paint.fillPattern.values.at(ClassID::Default); +PropertyValue<std::string> FillLayer::getFillPattern() const { + return impl->paint.fillPattern.get(); } -void FillLayer::setFillPattern(Function<std::string> value) { - impl->paint.fillPattern.values.emplace(ClassID::Default, value); +void FillLayer::setFillPattern(PropertyValue<std::string> value) { + impl->paint.fillPattern.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.hpp b/src/mbgl/layer/fill_layer_properties.hpp index fb327a2d6c..2ae67ef0a0 100644 --- a/src/mbgl/layer/fill_layer_properties.hpp +++ b/src/mbgl/layer/fill_layer_properties.hpp @@ -23,7 +23,7 @@ public: PaintProperty<Color> fillOutlineColor { {{ 0, 0, 0, -1 }} }; PaintProperty<std::array<float, 2>> fillTranslate { {{ 0, 0 }} }; PaintProperty<TranslateAnchorType> fillTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty<std::string, CrossFadedFunctionEvaluator> fillPattern { "" }; + PaintProperty<std::string, CrossFadedPropertyEvaluator> fillPattern { "" }; }; } // namespace mbgl diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index 0064a0b8da..c77a5c3e83 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -39,115 +39,115 @@ const std::string& LineLayer::getSourceLayer() const { // Layout properties -Function<LineCapType> LineLayer::getLineCap() const { - return *impl->layout.lineCap.parsedValue; +PropertyValue<LineCapType> LineLayer::getLineCap() const { + return impl->layout.lineCap.get(); } -void LineLayer::setLineCap(Function<LineCapType> value) { - impl->layout.lineCap.parsedValue = value; +void LineLayer::setLineCap(PropertyValue<LineCapType> value) { + impl->layout.lineCap.set(value); } -Function<LineJoinType> LineLayer::getLineJoin() const { - return *impl->layout.lineJoin.parsedValue; +PropertyValue<LineJoinType> LineLayer::getLineJoin() const { + return impl->layout.lineJoin.get(); } -void LineLayer::setLineJoin(Function<LineJoinType> value) { - impl->layout.lineJoin.parsedValue = value; +void LineLayer::setLineJoin(PropertyValue<LineJoinType> value) { + impl->layout.lineJoin.set(value); } -Function<float> LineLayer::getLineMiterLimit() const { - return *impl->layout.lineMiterLimit.parsedValue; +PropertyValue<float> LineLayer::getLineMiterLimit() const { + return impl->layout.lineMiterLimit.get(); } -void LineLayer::setLineMiterLimit(Function<float> value) { - impl->layout.lineMiterLimit.parsedValue = value; +void LineLayer::setLineMiterLimit(PropertyValue<float> value) { + impl->layout.lineMiterLimit.set(value); } -Function<float> LineLayer::getLineRoundLimit() const { - return *impl->layout.lineRoundLimit.parsedValue; +PropertyValue<float> LineLayer::getLineRoundLimit() const { + return impl->layout.lineRoundLimit.get(); } -void LineLayer::setLineRoundLimit(Function<float> value) { - impl->layout.lineRoundLimit.parsedValue = value; +void LineLayer::setLineRoundLimit(PropertyValue<float> value) { + impl->layout.lineRoundLimit.set(value); } // Paint properties -Function<float> LineLayer::getLineOpacity() const { - return impl->paint.lineOpacity.values.at(ClassID::Default); +PropertyValue<float> LineLayer::getLineOpacity() const { + return impl->paint.lineOpacity.get(); } -void LineLayer::setLineOpacity(Function<float> value) { - impl->paint.lineOpacity.values.emplace(ClassID::Default, value); +void LineLayer::setLineOpacity(PropertyValue<float> value) { + impl->paint.lineOpacity.set(value); } -Function<Color> LineLayer::getLineColor() const { - return impl->paint.lineColor.values.at(ClassID::Default); +PropertyValue<Color> LineLayer::getLineColor() const { + return impl->paint.lineColor.get(); } -void LineLayer::setLineColor(Function<Color> value) { - impl->paint.lineColor.values.emplace(ClassID::Default, value); +void LineLayer::setLineColor(PropertyValue<Color> value) { + impl->paint.lineColor.set(value); } -Function<std::array<float, 2>> LineLayer::getLineTranslate() const { - return impl->paint.lineTranslate.values.at(ClassID::Default); +PropertyValue<std::array<float, 2>> LineLayer::getLineTranslate() const { + return impl->paint.lineTranslate.get(); } -void LineLayer::setLineTranslate(Function<std::array<float, 2>> value) { - impl->paint.lineTranslate.values.emplace(ClassID::Default, value); +void LineLayer::setLineTranslate(PropertyValue<std::array<float, 2>> value) { + impl->paint.lineTranslate.set(value); } -Function<TranslateAnchorType> LineLayer::getLineTranslateAnchor() const { - return impl->paint.lineTranslateAnchor.values.at(ClassID::Default); +PropertyValue<TranslateAnchorType> LineLayer::getLineTranslateAnchor() const { + return impl->paint.lineTranslateAnchor.get(); } -void LineLayer::setLineTranslateAnchor(Function<TranslateAnchorType> value) { - impl->paint.lineTranslateAnchor.values.emplace(ClassID::Default, value); +void LineLayer::setLineTranslateAnchor(PropertyValue<TranslateAnchorType> value) { + impl->paint.lineTranslateAnchor.set(value); } -Function<float> LineLayer::getLineWidth() const { - return impl->paint.lineWidth.values.at(ClassID::Default); +PropertyValue<float> LineLayer::getLineWidth() const { + return impl->paint.lineWidth.get(); } -void LineLayer::setLineWidth(Function<float> value) { - impl->paint.lineWidth.values.emplace(ClassID::Default, value); +void LineLayer::setLineWidth(PropertyValue<float> value) { + impl->paint.lineWidth.set(value); } -Function<float> LineLayer::getLineGapWidth() const { - return impl->paint.lineGapWidth.values.at(ClassID::Default); +PropertyValue<float> LineLayer::getLineGapWidth() const { + return impl->paint.lineGapWidth.get(); } -void LineLayer::setLineGapWidth(Function<float> value) { - impl->paint.lineGapWidth.values.emplace(ClassID::Default, value); +void LineLayer::setLineGapWidth(PropertyValue<float> value) { + impl->paint.lineGapWidth.set(value); } -Function<float> LineLayer::getLineOffset() const { - return impl->paint.lineOffset.values.at(ClassID::Default); +PropertyValue<float> LineLayer::getLineOffset() const { + return impl->paint.lineOffset.get(); } -void LineLayer::setLineOffset(Function<float> value) { - impl->paint.lineOffset.values.emplace(ClassID::Default, value); +void LineLayer::setLineOffset(PropertyValue<float> value) { + impl->paint.lineOffset.set(value); } -Function<float> LineLayer::getLineBlur() const { - return impl->paint.lineBlur.values.at(ClassID::Default); +PropertyValue<float> LineLayer::getLineBlur() const { + return impl->paint.lineBlur.get(); } -void LineLayer::setLineBlur(Function<float> value) { - impl->paint.lineBlur.values.emplace(ClassID::Default, value); +void LineLayer::setLineBlur(PropertyValue<float> value) { + impl->paint.lineBlur.set(value); } -Function<std::vector<float>> LineLayer::getLineDasharray() const { - return impl->paint.lineDasharray.values.at(ClassID::Default); +PropertyValue<std::vector<float>> LineLayer::getLineDasharray() const { + return impl->paint.lineDasharray.get(); } -void LineLayer::setLineDasharray(Function<std::vector<float>> value) { - impl->paint.lineDasharray.values.emplace(ClassID::Default, value); +void LineLayer::setLineDasharray(PropertyValue<std::vector<float>> value) { + impl->paint.lineDasharray.set(value); } -Function<std::string> LineLayer::getLinePattern() const { - return impl->paint.linePattern.values.at(ClassID::Default); +PropertyValue<std::string> LineLayer::getLinePattern() const { + return impl->paint.linePattern.get(); } -void LineLayer::setLinePattern(Function<std::string> value) { - impl->paint.linePattern.values.emplace(ClassID::Default, value); +void LineLayer::setLinePattern(PropertyValue<std::string> value) { + impl->paint.linePattern.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.hpp b/src/mbgl/layer/line_layer_properties.hpp index ae87d6da5e..f4dad055bd 100644 --- a/src/mbgl/layer/line_layer_properties.hpp +++ b/src/mbgl/layer/line_layer_properties.hpp @@ -36,8 +36,8 @@ public: PaintProperty<float> lineGapWidth { 0 }; PaintProperty<float> lineOffset { 0 }; PaintProperty<float> lineBlur { 0 }; - PaintProperty<std::vector<float>, CrossFadedFunctionEvaluator> lineDasharray { { } }; - PaintProperty<std::string, CrossFadedFunctionEvaluator> linePattern { "" }; + PaintProperty<std::vector<float>, CrossFadedPropertyEvaluator> lineDasharray { { } }; + PaintProperty<std::string, CrossFadedPropertyEvaluator> linePattern { "" }; }; } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp index 1ec2e4c0d4..661c44b7d5 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/layer/raster_layer.cpp @@ -37,60 +37,60 @@ const std::string& RasterLayer::getSourceID() const { // Paint properties -Function<float> RasterLayer::getRasterOpacity() const { - return impl->paint.rasterOpacity.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterOpacity() const { + return impl->paint.rasterOpacity.get(); } -void RasterLayer::setRasterOpacity(Function<float> value) { - impl->paint.rasterOpacity.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterOpacity(PropertyValue<float> value) { + impl->paint.rasterOpacity.set(value); } -Function<float> RasterLayer::getRasterHueRotate() const { - return impl->paint.rasterHueRotate.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterHueRotate() const { + return impl->paint.rasterHueRotate.get(); } -void RasterLayer::setRasterHueRotate(Function<float> value) { - impl->paint.rasterHueRotate.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterHueRotate(PropertyValue<float> value) { + impl->paint.rasterHueRotate.set(value); } -Function<float> RasterLayer::getRasterBrightnessMin() const { - return impl->paint.rasterBrightnessMin.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterBrightnessMin() const { + return impl->paint.rasterBrightnessMin.get(); } -void RasterLayer::setRasterBrightnessMin(Function<float> value) { - impl->paint.rasterBrightnessMin.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterBrightnessMin(PropertyValue<float> value) { + impl->paint.rasterBrightnessMin.set(value); } -Function<float> RasterLayer::getRasterBrightnessMax() const { - return impl->paint.rasterBrightnessMax.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterBrightnessMax() const { + return impl->paint.rasterBrightnessMax.get(); } -void RasterLayer::setRasterBrightnessMax(Function<float> value) { - impl->paint.rasterBrightnessMax.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterBrightnessMax(PropertyValue<float> value) { + impl->paint.rasterBrightnessMax.set(value); } -Function<float> RasterLayer::getRasterSaturation() const { - return impl->paint.rasterSaturation.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterSaturation() const { + return impl->paint.rasterSaturation.get(); } -void RasterLayer::setRasterSaturation(Function<float> value) { - impl->paint.rasterSaturation.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterSaturation(PropertyValue<float> value) { + impl->paint.rasterSaturation.set(value); } -Function<float> RasterLayer::getRasterContrast() const { - return impl->paint.rasterContrast.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterContrast() const { + return impl->paint.rasterContrast.get(); } -void RasterLayer::setRasterContrast(Function<float> value) { - impl->paint.rasterContrast.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterContrast(PropertyValue<float> value) { + impl->paint.rasterContrast.set(value); } -Function<float> RasterLayer::getRasterFadeDuration() const { - return impl->paint.rasterFadeDuration.values.at(ClassID::Default); +PropertyValue<float> RasterLayer::getRasterFadeDuration() const { + return impl->paint.rasterFadeDuration.get(); } -void RasterLayer::setRasterFadeDuration(Function<float> value) { - impl->paint.rasterFadeDuration.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterFadeDuration(PropertyValue<float> value) { + impl->paint.rasterFadeDuration.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index de2428fd25..6152d7104a 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -39,336 +39,336 @@ const std::string& SymbolLayer::getSourceLayer() const { // Layout properties -Function<SymbolPlacementType> SymbolLayer::getSymbolPlacement() const { - return *impl->layout.symbolPlacement.parsedValue; +PropertyValue<SymbolPlacementType> SymbolLayer::getSymbolPlacement() const { + return impl->layout.symbolPlacement.get(); } -void SymbolLayer::setSymbolPlacement(Function<SymbolPlacementType> value) { - impl->layout.symbolPlacement.parsedValue = value; +void SymbolLayer::setSymbolPlacement(PropertyValue<SymbolPlacementType> value) { + impl->layout.symbolPlacement.set(value); } -Function<float> SymbolLayer::getSymbolSpacing() const { - return *impl->layout.symbolSpacing.parsedValue; +PropertyValue<float> SymbolLayer::getSymbolSpacing() const { + return impl->layout.symbolSpacing.get(); } -void SymbolLayer::setSymbolSpacing(Function<float> value) { - impl->layout.symbolSpacing.parsedValue = value; +void SymbolLayer::setSymbolSpacing(PropertyValue<float> value) { + impl->layout.symbolSpacing.set(value); } -Function<bool> SymbolLayer::getSymbolAvoidEdges() const { - return *impl->layout.symbolAvoidEdges.parsedValue; +PropertyValue<bool> SymbolLayer::getSymbolAvoidEdges() const { + return impl->layout.symbolAvoidEdges.get(); } -void SymbolLayer::setSymbolAvoidEdges(Function<bool> value) { - impl->layout.symbolAvoidEdges.parsedValue = value; +void SymbolLayer::setSymbolAvoidEdges(PropertyValue<bool> value) { + impl->layout.symbolAvoidEdges.set(value); } -Function<bool> SymbolLayer::getIconAllowOverlap() const { - return *impl->layout.iconAllowOverlap.parsedValue; +PropertyValue<bool> SymbolLayer::getIconAllowOverlap() const { + return impl->layout.iconAllowOverlap.get(); } -void SymbolLayer::setIconAllowOverlap(Function<bool> value) { - impl->layout.iconAllowOverlap.parsedValue = value; +void SymbolLayer::setIconAllowOverlap(PropertyValue<bool> value) { + impl->layout.iconAllowOverlap.set(value); } -Function<bool> SymbolLayer::getIconIgnorePlacement() const { - return *impl->layout.iconIgnorePlacement.parsedValue; +PropertyValue<bool> SymbolLayer::getIconIgnorePlacement() const { + return impl->layout.iconIgnorePlacement.get(); } -void SymbolLayer::setIconIgnorePlacement(Function<bool> value) { - impl->layout.iconIgnorePlacement.parsedValue = value; +void SymbolLayer::setIconIgnorePlacement(PropertyValue<bool> value) { + impl->layout.iconIgnorePlacement.set(value); } -Function<bool> SymbolLayer::getIconOptional() const { - return *impl->layout.iconOptional.parsedValue; +PropertyValue<bool> SymbolLayer::getIconOptional() const { + return impl->layout.iconOptional.get(); } -void SymbolLayer::setIconOptional(Function<bool> value) { - impl->layout.iconOptional.parsedValue = value; +void SymbolLayer::setIconOptional(PropertyValue<bool> value) { + impl->layout.iconOptional.set(value); } -Function<RotationAlignmentType> SymbolLayer::getIconRotationAlignment() const { - return *impl->layout.iconRotationAlignment.parsedValue; +PropertyValue<RotationAlignmentType> SymbolLayer::getIconRotationAlignment() const { + return impl->layout.iconRotationAlignment.get(); } -void SymbolLayer::setIconRotationAlignment(Function<RotationAlignmentType> value) { - impl->layout.iconRotationAlignment.parsedValue = value; +void SymbolLayer::setIconRotationAlignment(PropertyValue<RotationAlignmentType> value) { + impl->layout.iconRotationAlignment.set(value); } -Function<float> SymbolLayer::getIconSize() const { - return *impl->layout.iconSize.parsedValue; +PropertyValue<float> SymbolLayer::getIconSize() const { + return impl->layout.iconSize.get(); } -void SymbolLayer::setIconSize(Function<float> value) { - impl->layout.iconSize.parsedValue = value; +void SymbolLayer::setIconSize(PropertyValue<float> value) { + impl->layout.iconSize.set(value); } -Function<std::string> SymbolLayer::getIconImage() const { - return *impl->layout.iconImage.parsedValue; +PropertyValue<std::string> SymbolLayer::getIconImage() const { + return impl->layout.iconImage.get(); } -void SymbolLayer::setIconImage(Function<std::string> value) { - impl->layout.iconImage.parsedValue = value; +void SymbolLayer::setIconImage(PropertyValue<std::string> value) { + impl->layout.iconImage.set(value); } -Function<float> SymbolLayer::getIconRotate() const { - return *impl->layout.iconRotate.parsedValue; +PropertyValue<float> SymbolLayer::getIconRotate() const { + return impl->layout.iconRotate.get(); } -void SymbolLayer::setIconRotate(Function<float> value) { - impl->layout.iconRotate.parsedValue = value; +void SymbolLayer::setIconRotate(PropertyValue<float> value) { + impl->layout.iconRotate.set(value); } -Function<float> SymbolLayer::getIconPadding() const { - return *impl->layout.iconPadding.parsedValue; +PropertyValue<float> SymbolLayer::getIconPadding() const { + return impl->layout.iconPadding.get(); } -void SymbolLayer::setIconPadding(Function<float> value) { - impl->layout.iconPadding.parsedValue = value; +void SymbolLayer::setIconPadding(PropertyValue<float> value) { + impl->layout.iconPadding.set(value); } -Function<bool> SymbolLayer::getIconKeepUpright() const { - return *impl->layout.iconKeepUpright.parsedValue; +PropertyValue<bool> SymbolLayer::getIconKeepUpright() const { + return impl->layout.iconKeepUpright.get(); } -void SymbolLayer::setIconKeepUpright(Function<bool> value) { - impl->layout.iconKeepUpright.parsedValue = value; +void SymbolLayer::setIconKeepUpright(PropertyValue<bool> value) { + impl->layout.iconKeepUpright.set(value); } -Function<std::array<float, 2>> SymbolLayer::getIconOffset() const { - return *impl->layout.iconOffset.parsedValue; +PropertyValue<std::array<float, 2>> SymbolLayer::getIconOffset() const { + return impl->layout.iconOffset.get(); } -void SymbolLayer::setIconOffset(Function<std::array<float, 2>> value) { - impl->layout.iconOffset.parsedValue = value; +void SymbolLayer::setIconOffset(PropertyValue<std::array<float, 2>> value) { + impl->layout.iconOffset.set(value); } -Function<RotationAlignmentType> SymbolLayer::getTextRotationAlignment() const { - return *impl->layout.textRotationAlignment.parsedValue; +PropertyValue<RotationAlignmentType> SymbolLayer::getTextRotationAlignment() const { + return impl->layout.textRotationAlignment.get(); } -void SymbolLayer::setTextRotationAlignment(Function<RotationAlignmentType> value) { - impl->layout.textRotationAlignment.parsedValue = value; +void SymbolLayer::setTextRotationAlignment(PropertyValue<RotationAlignmentType> value) { + impl->layout.textRotationAlignment.set(value); } -Function<std::string> SymbolLayer::getTextField() const { - return *impl->layout.textField.parsedValue; +PropertyValue<std::string> SymbolLayer::getTextField() const { + return impl->layout.textField.get(); } -void SymbolLayer::setTextField(Function<std::string> value) { - impl->layout.textField.parsedValue = value; +void SymbolLayer::setTextField(PropertyValue<std::string> value) { + impl->layout.textField.set(value); } -Function<std::vector<std::string>> SymbolLayer::getTextFont() const { - return *impl->layout.textFont.parsedValue; +PropertyValue<std::vector<std::string>> SymbolLayer::getTextFont() const { + return impl->layout.textFont.get(); } -void SymbolLayer::setTextFont(Function<std::vector<std::string>> value) { - impl->layout.textFont.parsedValue = value; +void SymbolLayer::setTextFont(PropertyValue<std::vector<std::string>> value) { + impl->layout.textFont.set(value); } -Function<float> SymbolLayer::getTextSize() const { - return *impl->layout.textSize.parsedValue; +PropertyValue<float> SymbolLayer::getTextSize() const { + return impl->layout.textSize.get(); } -void SymbolLayer::setTextSize(Function<float> value) { - impl->layout.textSize.parsedValue = value; +void SymbolLayer::setTextSize(PropertyValue<float> value) { + impl->layout.textSize.set(value); } -Function<float> SymbolLayer::getTextMaxWidth() const { - return *impl->layout.textMaxWidth.parsedValue; +PropertyValue<float> SymbolLayer::getTextMaxWidth() const { + return impl->layout.textMaxWidth.get(); } -void SymbolLayer::setTextMaxWidth(Function<float> value) { - impl->layout.textMaxWidth.parsedValue = value; +void SymbolLayer::setTextMaxWidth(PropertyValue<float> value) { + impl->layout.textMaxWidth.set(value); } -Function<float> SymbolLayer::getTextLineHeight() const { - return *impl->layout.textLineHeight.parsedValue; +PropertyValue<float> SymbolLayer::getTextLineHeight() const { + return impl->layout.textLineHeight.get(); } -void SymbolLayer::setTextLineHeight(Function<float> value) { - impl->layout.textLineHeight.parsedValue = value; +void SymbolLayer::setTextLineHeight(PropertyValue<float> value) { + impl->layout.textLineHeight.set(value); } -Function<float> SymbolLayer::getTextLetterSpacing() const { - return *impl->layout.textLetterSpacing.parsedValue; +PropertyValue<float> SymbolLayer::getTextLetterSpacing() const { + return impl->layout.textLetterSpacing.get(); } -void SymbolLayer::setTextLetterSpacing(Function<float> value) { - impl->layout.textLetterSpacing.parsedValue = value; +void SymbolLayer::setTextLetterSpacing(PropertyValue<float> value) { + impl->layout.textLetterSpacing.set(value); } -Function<TextJustifyType> SymbolLayer::getTextJustify() const { - return *impl->layout.textJustify.parsedValue; +PropertyValue<TextJustifyType> SymbolLayer::getTextJustify() const { + return impl->layout.textJustify.get(); } -void SymbolLayer::setTextJustify(Function<TextJustifyType> value) { - impl->layout.textJustify.parsedValue = value; +void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) { + impl->layout.textJustify.set(value); } -Function<TextAnchorType> SymbolLayer::getTextAnchor() const { - return *impl->layout.textAnchor.parsedValue; +PropertyValue<TextAnchorType> SymbolLayer::getTextAnchor() const { + return impl->layout.textAnchor.get(); } -void SymbolLayer::setTextAnchor(Function<TextAnchorType> value) { - impl->layout.textAnchor.parsedValue = value; +void SymbolLayer::setTextAnchor(PropertyValue<TextAnchorType> value) { + impl->layout.textAnchor.set(value); } -Function<float> SymbolLayer::getTextMaxAngle() const { - return *impl->layout.textMaxAngle.parsedValue; +PropertyValue<float> SymbolLayer::getTextMaxAngle() const { + return impl->layout.textMaxAngle.get(); } -void SymbolLayer::setTextMaxAngle(Function<float> value) { - impl->layout.textMaxAngle.parsedValue = value; +void SymbolLayer::setTextMaxAngle(PropertyValue<float> value) { + impl->layout.textMaxAngle.set(value); } -Function<float> SymbolLayer::getTextRotate() const { - return *impl->layout.textRotate.parsedValue; +PropertyValue<float> SymbolLayer::getTextRotate() const { + return impl->layout.textRotate.get(); } -void SymbolLayer::setTextRotate(Function<float> value) { - impl->layout.textRotate.parsedValue = value; +void SymbolLayer::setTextRotate(PropertyValue<float> value) { + impl->layout.textRotate.set(value); } -Function<float> SymbolLayer::getTextPadding() const { - return *impl->layout.textPadding.parsedValue; +PropertyValue<float> SymbolLayer::getTextPadding() const { + return impl->layout.textPadding.get(); } -void SymbolLayer::setTextPadding(Function<float> value) { - impl->layout.textPadding.parsedValue = value; +void SymbolLayer::setTextPadding(PropertyValue<float> value) { + impl->layout.textPadding.set(value); } -Function<bool> SymbolLayer::getTextKeepUpright() const { - return *impl->layout.textKeepUpright.parsedValue; +PropertyValue<bool> SymbolLayer::getTextKeepUpright() const { + return impl->layout.textKeepUpright.get(); } -void SymbolLayer::setTextKeepUpright(Function<bool> value) { - impl->layout.textKeepUpright.parsedValue = value; +void SymbolLayer::setTextKeepUpright(PropertyValue<bool> value) { + impl->layout.textKeepUpright.set(value); } -Function<TextTransformType> SymbolLayer::getTextTransform() const { - return *impl->layout.textTransform.parsedValue; +PropertyValue<TextTransformType> SymbolLayer::getTextTransform() const { + return impl->layout.textTransform.get(); } -void SymbolLayer::setTextTransform(Function<TextTransformType> value) { - impl->layout.textTransform.parsedValue = value; +void SymbolLayer::setTextTransform(PropertyValue<TextTransformType> value) { + impl->layout.textTransform.set(value); } -Function<std::array<float, 2>> SymbolLayer::getTextOffset() const { - return *impl->layout.textOffset.parsedValue; +PropertyValue<std::array<float, 2>> SymbolLayer::getTextOffset() const { + return impl->layout.textOffset.get(); } -void SymbolLayer::setTextOffset(Function<std::array<float, 2>> value) { - impl->layout.textOffset.parsedValue = value; +void SymbolLayer::setTextOffset(PropertyValue<std::array<float, 2>> value) { + impl->layout.textOffset.set(value); } -Function<bool> SymbolLayer::getTextAllowOverlap() const { - return *impl->layout.textAllowOverlap.parsedValue; +PropertyValue<bool> SymbolLayer::getTextAllowOverlap() const { + return impl->layout.textAllowOverlap.get(); } -void SymbolLayer::setTextAllowOverlap(Function<bool> value) { - impl->layout.textAllowOverlap.parsedValue = value; +void SymbolLayer::setTextAllowOverlap(PropertyValue<bool> value) { + impl->layout.textAllowOverlap.set(value); } -Function<bool> SymbolLayer::getTextIgnorePlacement() const { - return *impl->layout.textIgnorePlacement.parsedValue; +PropertyValue<bool> SymbolLayer::getTextIgnorePlacement() const { + return impl->layout.textIgnorePlacement.get(); } -void SymbolLayer::setTextIgnorePlacement(Function<bool> value) { - impl->layout.textIgnorePlacement.parsedValue = value; +void SymbolLayer::setTextIgnorePlacement(PropertyValue<bool> value) { + impl->layout.textIgnorePlacement.set(value); } -Function<bool> SymbolLayer::getTextOptional() const { - return *impl->layout.textOptional.parsedValue; +PropertyValue<bool> SymbolLayer::getTextOptional() const { + return impl->layout.textOptional.get(); } -void SymbolLayer::setTextOptional(Function<bool> value) { - impl->layout.textOptional.parsedValue = value; +void SymbolLayer::setTextOptional(PropertyValue<bool> value) { + impl->layout.textOptional.set(value); } // Paint properties -Function<float> SymbolLayer::getIconOpacity() const { - return impl->paint.iconOpacity.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getIconOpacity() const { + return impl->paint.iconOpacity.get(); } -void SymbolLayer::setIconOpacity(Function<float> value) { - impl->paint.iconOpacity.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconOpacity(PropertyValue<float> value) { + impl->paint.iconOpacity.set(value); } -Function<Color> SymbolLayer::getIconColor() const { - return impl->paint.iconColor.values.at(ClassID::Default); +PropertyValue<Color> SymbolLayer::getIconColor() const { + return impl->paint.iconColor.get(); } -void SymbolLayer::setIconColor(Function<Color> value) { - impl->paint.iconColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconColor(PropertyValue<Color> value) { + impl->paint.iconColor.set(value); } -Function<Color> SymbolLayer::getIconHaloColor() const { - return impl->paint.iconHaloColor.values.at(ClassID::Default); +PropertyValue<Color> SymbolLayer::getIconHaloColor() const { + return impl->paint.iconHaloColor.get(); } -void SymbolLayer::setIconHaloColor(Function<Color> value) { - impl->paint.iconHaloColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloColor(PropertyValue<Color> value) { + impl->paint.iconHaloColor.set(value); } -Function<float> SymbolLayer::getIconHaloWidth() const { - return impl->paint.iconHaloWidth.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getIconHaloWidth() const { + return impl->paint.iconHaloWidth.get(); } -void SymbolLayer::setIconHaloWidth(Function<float> value) { - impl->paint.iconHaloWidth.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloWidth(PropertyValue<float> value) { + impl->paint.iconHaloWidth.set(value); } -Function<float> SymbolLayer::getIconHaloBlur() const { - return impl->paint.iconHaloBlur.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getIconHaloBlur() const { + return impl->paint.iconHaloBlur.get(); } -void SymbolLayer::setIconHaloBlur(Function<float> value) { - impl->paint.iconHaloBlur.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloBlur(PropertyValue<float> value) { + impl->paint.iconHaloBlur.set(value); } -Function<std::array<float, 2>> SymbolLayer::getIconTranslate() const { - return impl->paint.iconTranslate.values.at(ClassID::Default); +PropertyValue<std::array<float, 2>> SymbolLayer::getIconTranslate() const { + return impl->paint.iconTranslate.get(); } -void SymbolLayer::setIconTranslate(Function<std::array<float, 2>> value) { - impl->paint.iconTranslate.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconTranslate(PropertyValue<std::array<float, 2>> value) { + impl->paint.iconTranslate.set(value); } -Function<TranslateAnchorType> SymbolLayer::getIconTranslateAnchor() const { - return impl->paint.iconTranslateAnchor.values.at(ClassID::Default); +PropertyValue<TranslateAnchorType> SymbolLayer::getIconTranslateAnchor() const { + return impl->paint.iconTranslateAnchor.get(); } -void SymbolLayer::setIconTranslateAnchor(Function<TranslateAnchorType> value) { - impl->paint.iconTranslateAnchor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconTranslateAnchor(PropertyValue<TranslateAnchorType> value) { + impl->paint.iconTranslateAnchor.set(value); } -Function<float> SymbolLayer::getTextOpacity() const { - return impl->paint.textOpacity.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getTextOpacity() const { + return impl->paint.textOpacity.get(); } -void SymbolLayer::setTextOpacity(Function<float> value) { - impl->paint.textOpacity.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextOpacity(PropertyValue<float> value) { + impl->paint.textOpacity.set(value); } -Function<Color> SymbolLayer::getTextColor() const { - return impl->paint.textColor.values.at(ClassID::Default); +PropertyValue<Color> SymbolLayer::getTextColor() const { + return impl->paint.textColor.get(); } -void SymbolLayer::setTextColor(Function<Color> value) { - impl->paint.textColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextColor(PropertyValue<Color> value) { + impl->paint.textColor.set(value); } -Function<Color> SymbolLayer::getTextHaloColor() const { - return impl->paint.textHaloColor.values.at(ClassID::Default); +PropertyValue<Color> SymbolLayer::getTextHaloColor() const { + return impl->paint.textHaloColor.get(); } -void SymbolLayer::setTextHaloColor(Function<Color> value) { - impl->paint.textHaloColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloColor(PropertyValue<Color> value) { + impl->paint.textHaloColor.set(value); } -Function<float> SymbolLayer::getTextHaloWidth() const { - return impl->paint.textHaloWidth.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getTextHaloWidth() const { + return impl->paint.textHaloWidth.get(); } -void SymbolLayer::setTextHaloWidth(Function<float> value) { - impl->paint.textHaloWidth.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloWidth(PropertyValue<float> value) { + impl->paint.textHaloWidth.set(value); } -Function<float> SymbolLayer::getTextHaloBlur() const { - return impl->paint.textHaloBlur.values.at(ClassID::Default); +PropertyValue<float> SymbolLayer::getTextHaloBlur() const { + return impl->paint.textHaloBlur.get(); } -void SymbolLayer::setTextHaloBlur(Function<float> value) { - impl->paint.textHaloBlur.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloBlur(PropertyValue<float> value) { + impl->paint.textHaloBlur.set(value); } -Function<std::array<float, 2>> SymbolLayer::getTextTranslate() const { - return impl->paint.textTranslate.values.at(ClassID::Default); +PropertyValue<std::array<float, 2>> SymbolLayer::getTextTranslate() const { + return impl->paint.textTranslate.get(); } -void SymbolLayer::setTextTranslate(Function<std::array<float, 2>> value) { - impl->paint.textTranslate.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextTranslate(PropertyValue<std::array<float, 2>> value) { + impl->paint.textTranslate.set(value); } -Function<TranslateAnchorType> SymbolLayer::getTextTranslateAnchor() const { - return impl->paint.textTranslateAnchor.values.at(ClassID::Default); +PropertyValue<TranslateAnchorType> SymbolLayer::getTextTranslateAnchor() const { + return impl->paint.textTranslateAnchor.get(); } -void SymbolLayer::setTextTranslateAnchor(Function<TranslateAnchorType> value) { - impl->paint.textTranslateAnchor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextTranslateAnchor(PropertyValue<TranslateAnchorType> value) { + impl->paint.textTranslateAnchor.set(value); } } // namespace mbgl diff --git a/src/mbgl/style/function_evaluator.hpp b/src/mbgl/style/function_evaluator.hpp deleted file mode 100644 index de49e79f98..0000000000 --- a/src/mbgl/style/function_evaluator.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include <mbgl/style/types.hpp> -#include <mbgl/util/interpolate.hpp> - -namespace mbgl { - -class StyleCalculationParameters; - -template <typename T> -class NormalFunctionEvaluator { -public: - using ResultType = T; - T operator()(const Function<T>&, const StyleCalculationParameters&) const; -}; - -template <typename T> -struct Faded { - Faded() = default; - Faded(const T& v) : to(v) {} - - T from; - float fromScale = 0; - T to; - float toScale = 0; - float t = 0; -}; - -template <typename T> -class CrossFadedFunctionEvaluator { -public: - using ResultType = Faded<T>; - Faded<T> operator()(const Function<T>&, const StyleCalculationParameters&) const; -}; - -namespace util { -template <typename T> -struct Interpolator<Faded<T>> - : Uninterpolated {}; -} - -} // namespace mbgl diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index a856e7589c..b4857aeae5 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -1,7 +1,8 @@ #pragma once +#include <mbgl/style/property_value.hpp> #include <mbgl/style/property_parsing.hpp> -#include <mbgl/style/function_evaluator.hpp> +#include <mbgl/style/property_evaluator.hpp> #include <mbgl/util/rapidjson.hpp> #include <utility> @@ -11,25 +12,38 @@ namespace mbgl { template <typename T> class LayoutProperty { public: - explicit LayoutProperty(T v) : value(std::move(v)) {} + explicit LayoutProperty(T v) + : value(std::move(v)), + defaultValue(value) {} + + const PropertyValue<T>& get() const { + return currentValue; + } + + void set(const PropertyValue<T>& value_) { + currentValue = value_; + } void parse(const char * name, const JSValue& layout) { if (layout.HasMember(name)) { - parsedValue = parseProperty<T>(name, layout[name]); + currentValue = parseProperty<T>(name, layout[name]); } } void calculate(const StyleCalculationParameters& parameters) { - if (parsedValue) { - NormalFunctionEvaluator<T> evaluator; - value = evaluator(*parsedValue, parameters); + if (currentValue) { + PropertyEvaluator<T> evaluator(parameters, defaultValue); + value = PropertyValue<T>::visit(currentValue, evaluator); } } + // TODO: remove / privatize operator T() const { return value; } - - optional<Function<T>> parsedValue; T value; + +private: + T defaultValue; + PropertyValue<T> currentValue; }; } // namespace mbgl diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 4bbc564398..8428a90533 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -2,7 +2,7 @@ #include <mbgl/style/class_dictionary.hpp> #include <mbgl/style/property_parsing.hpp> -#include <mbgl/style/function_evaluator.hpp> +#include <mbgl/style/property_evaluator.hpp> #include <mbgl/style/property_transition.hpp> #include <mbgl/style/style_cascade_parameters.hpp> #include <mbgl/style/style_calculation_parameters.hpp> @@ -15,15 +15,14 @@ namespace mbgl { -template <class T, template <class S> class Evaluator = NormalFunctionEvaluator> +template <class T, template <class S> class Evaluator = PropertyEvaluator> class PaintProperty { public: - using Fn = Function<T>; using Result = typename Evaluator<T>::ResultType; - explicit PaintProperty(T fallbackValue) - : value(fallbackValue) { - values.emplace(ClassID::Fallback, Fn(fallbackValue)); + explicit PaintProperty(T defaultValue_) + : defaultValue(defaultValue_) { + values.emplace(ClassID::Fallback, defaultValue_); } PaintProperty(const PaintProperty& other) @@ -31,6 +30,14 @@ public: transitions(other.transitions) { } + const PropertyValue<T>& get() const { + return values.at(ClassID::Default); + } + + void set(const PropertyValue<T>& value_) { + values.emplace(ClassID::Default, value_); + } + void parse(const char* name, const JSValue& layer) { mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; }); @@ -49,15 +56,13 @@ public: ClassID classID = isClass ? ClassDictionary::Get().lookup(paintName.substr(6)) : ClassID::Default; if (it->value.HasMember(name)) { - auto v = parseProperty<T>(name, it->value[name]); - if (v) { - values.emplace(classID, *v); + if (auto v = parseProperty<T>(name, it->value[name])) { + values.emplace(classID, v); } } if (it->value.HasMember(transitionName.c_str())) { - auto v = parsePropertyTransition(name, it->value[transitionName.c_str()]); - if (v) { + if (auto v = parsePropertyTransition(name, it->value[transitionName.c_str()])) { transitions.emplace(classID, *v); } } @@ -92,52 +97,54 @@ public: bool calculate(const StyleCalculationParameters& parameters) { assert(cascaded); - value = cascaded->calculate(parameters); + Evaluator<T> evaluator(parameters, defaultValue); + value = cascaded->calculate(evaluator, parameters.now); return cascaded->prior.operator bool(); } + // TODO: remove / privatize operator T() const { return value; } + Result value; - std::map<ClassID, Fn> values; +private: + T defaultValue; + std::map<ClassID, PropertyValue<T>> values; std::map<ClassID, PropertyTransition> transitions; struct CascadedValue { CascadedValue(std::unique_ptr<CascadedValue> prior_, TimePoint begin_, TimePoint end_, - Fn value_) + PropertyValue<T> value_) : prior(std::move(prior_)), begin(begin_), end(end_), value(std::move(value_)) { } - Result calculate(const StyleCalculationParameters& parameters) { - Evaluator<T> evaluator; - Result final = evaluator(value, parameters); + Result calculate(const Evaluator<T>& evaluator, const TimePoint& now) { + Result final = PropertyValue<T>::visit(value, evaluator); if (!prior) { // No prior value. return final; - } else if (parameters.now >= end) { + } else if (now >= end) { // Transition from prior value is now complete. prior.reset(); return final; } else { // Interpolate between recursively-calculated prior value and final. - float t = std::chrono::duration<float>(parameters.now - begin) / (end - begin); - return util::interpolate(prior->calculate(parameters), final, t); + float t = std::chrono::duration<float>(now - begin) / (end - begin); + return util::interpolate(prior->calculate(evaluator, now), final, t); } } std::unique_ptr<CascadedValue> prior; TimePoint begin; TimePoint end; - Fn value; + PropertyValue<T> value; }; std::unique_ptr<CascadedValue> cascaded; - - Result value; }; } // namespace mbgl diff --git a/src/mbgl/style/function_evaluator.cpp b/src/mbgl/style/property_evaluator.cpp index c58e1d39d2..08eea899c2 100644 --- a/src/mbgl/style/function_evaluator.cpp +++ b/src/mbgl/style/property_evaluator.cpp @@ -1,4 +1,4 @@ -#include <mbgl/style/function_evaluator.hpp> +#include <mbgl/style/property_evaluator.hpp> #include <mbgl/style/style_calculation_parameters.hpp> #include <mbgl/style/types.hpp> #include <mbgl/util/interpolate.hpp> @@ -30,7 +30,7 @@ template <> inline TextTransformType defaultStopsValue() { return {}; }; template <> inline RotationAlignmentType defaultStopsValue() { return {}; }; template <typename T> -T NormalFunctionEvaluator<T>::operator()(const Function<T>& fn, const StyleCalculationParameters& parameters) const { +T PropertyEvaluator<T>::operator()(const Function<T>& fn) const { float base = fn.getBase(); const std::vector<std::pair<float, T>>& stops = fn.getStops(); float z = parameters.z; @@ -79,68 +79,65 @@ T NormalFunctionEvaluator<T>::operator()(const Function<T>& fn, const StyleCalcu } } -template class NormalFunctionEvaluator<bool>; -template class NormalFunctionEvaluator<float>; -template class NormalFunctionEvaluator<Color>; -template class NormalFunctionEvaluator<std::vector<float>>; -template class NormalFunctionEvaluator<std::vector<std::string>>; -template class NormalFunctionEvaluator<std::array<float, 2>>; - -template class NormalFunctionEvaluator<std::string>; -template class NormalFunctionEvaluator<TranslateAnchorType>; -template class NormalFunctionEvaluator<RotateAnchorType>; -template class NormalFunctionEvaluator<LineCapType>; -template class NormalFunctionEvaluator<LineJoinType>; -template class NormalFunctionEvaluator<SymbolPlacementType>; -template class NormalFunctionEvaluator<TextAnchorType>; -template class NormalFunctionEvaluator<TextJustifyType>; -template class NormalFunctionEvaluator<TextTransformType>; -template class NormalFunctionEvaluator<RotationAlignmentType>; +template class PropertyEvaluator<bool>; +template class PropertyEvaluator<float>; +template class PropertyEvaluator<Color>; +template class PropertyEvaluator<std::vector<float>>; +template class PropertyEvaluator<std::vector<std::string>>; +template class PropertyEvaluator<std::array<float, 2>>; + +template class PropertyEvaluator<std::string>; +template class PropertyEvaluator<TranslateAnchorType>; +template class PropertyEvaluator<RotateAnchorType>; +template class PropertyEvaluator<LineCapType>; +template class PropertyEvaluator<LineJoinType>; +template class PropertyEvaluator<SymbolPlacementType>; +template class PropertyEvaluator<TextAnchorType>; +template class PropertyEvaluator<TextJustifyType>; +template class PropertyEvaluator<TextTransformType>; +template class PropertyEvaluator<RotationAlignmentType>; template <typename T> -inline size_t getBiggestStopLessThan(const std::vector<std::pair<float, T>>& stops, float z) { +Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const Undefined&) const { + return calculate(defaultValue, defaultValue, defaultValue); +} + +template <typename T> +Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const T& constant) const { + return calculate(constant, constant, constant); +} + +template <typename T> +inline T getBiggestStopLessThan(const Function<T>& function, float z) { + const auto& stops = function.getStops(); for (uint32_t i = 0; i < stops.size(); i++) { if (stops[i].first > z) { - return i == 0 ? i : i - 1; + return stops[i == 0 ? i : i - 1].second; } } - return stops.size() - 1; + return stops.at(stops.size() - 1).second; } template <typename T> -Faded<T> CrossFadedFunctionEvaluator<T>::operator()(const Function<T>& fn, const StyleCalculationParameters& parameters) const { - Faded<T> result; +Faded<T> CrossFadedPropertyEvaluator<T>::operator()(const Function<T>& function) const { + return calculate(getBiggestStopLessThan(function, parameters.z - 1.0f), + getBiggestStopLessThan(function, parameters.z), + getBiggestStopLessThan(function, parameters.z + 1.0f)); +} - const std::vector<std::pair<float, T>>& stops = fn.getStops(); - float z = parameters.z; +template <typename T> +Faded<T> CrossFadedPropertyEvaluator<T>::calculate(const T& min, const T& mid, const T& max) const { + const float z = parameters.z; const float fraction = z - std::floor(z); - std::chrono::duration<float> d = parameters.defaultFadeDuration; - float t = std::min((parameters.now - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f); - float fromScale = 1.0f; - float toScale = 1.0f; - size_t from, to; - - if (z > parameters.zoomHistory.lastIntegerZoom) { - result.t = fraction + (1.0f - fraction) * t; - from = getBiggestStopLessThan(stops, z - 1.0f); - to = getBiggestStopLessThan(stops, z); - fromScale *= 2.0f; - - } else { - result.t = 1 - (1 - t) * fraction; - to = getBiggestStopLessThan(stops, z); - from = getBiggestStopLessThan(stops, z + 1.0f); - fromScale /= 2.0f; - } + const std::chrono::duration<float> d = parameters.defaultFadeDuration; + const float t = std::min((parameters.now - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f); - result.from = stops[from].second; - result.to = stops[to].second; - result.fromScale = fromScale; - result.toScale = toScale; - return result; + return z > parameters.zoomHistory.lastIntegerZoom + ? Faded<T> { min, mid, 2.0f, 1.0f, fraction + (1.0f - fraction) * t } + : Faded<T> { max, mid, 0.5f, 1.0f, 1 - (1 - t) * fraction }; } -template class CrossFadedFunctionEvaluator<std::string>; -template class CrossFadedFunctionEvaluator<std::vector<float>>; +template class CrossFadedPropertyEvaluator<std::string>; +template class CrossFadedPropertyEvaluator<std::vector<float>>; } // namespace mbgl diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp new file mode 100644 index 0000000000..112c373a44 --- /dev/null +++ b/src/mbgl/style/property_evaluator.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include <mbgl/style/property_value.hpp> +#include <mbgl/util/interpolate.hpp> + +namespace mbgl { + +class StyleCalculationParameters; + +template <typename T> +class PropertyEvaluator { +public: + using ResultType = T; + + PropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + : parameters(parameters_), + defaultValue(defaultValue_) {} + + T operator()(const Undefined&) const { return defaultValue; } + T operator()(const T& constant) const { return constant; } + T operator()(const Function<T>&) const; + +private: + const StyleCalculationParameters& parameters; + T defaultValue; +}; + +template <typename T> +struct Faded { + T from; + T to; + float fromScale; + float toScale; + float t; +}; + +template <typename T> +class CrossFadedPropertyEvaluator { +public: + using ResultType = Faded<T>; + + CrossFadedPropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + : parameters(parameters_), + defaultValue(defaultValue_) {} + + Faded<T> operator()(const Undefined&) const; + Faded<T> operator()(const T& constant) const; + Faded<T> operator()(const Function<T>&) const; + +private: + Faded<T> calculate(const T& min, const T& mid, const T& max) const; + + const StyleCalculationParameters& parameters; + T defaultValue; +}; + +namespace util { +template <typename T> +struct Interpolator<Faded<T>> + : Uninterpolated {}; +} + +} // namespace mbgl diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 17c9bf6ba8..c0fe5ce2bc 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/style/types.hpp> +#include <mbgl/style/property_value.hpp> #include <mbgl/style/property_transition.hpp> #include <mbgl/util/rapidjson.hpp> @@ -35,7 +36,7 @@ template <> optional<std::vector<float>> parseConstant(const char*, const JSValu template <> optional<std::vector<std::string>> parseConstant(const char*, const JSValue&); template <typename T> -optional<Function<T>> parseProperty(const char* name, const JSValue& value) { +PropertyValue<T> parseProperty(const char* name, const JSValue& value) { if (!value.IsObject()) { auto constant = parseConstant<T>(name, value); @@ -43,7 +44,7 @@ optional<Function<T>> parseProperty(const char* name, const JSValue& value) { return {}; } - return { Function<T>(*constant) }; + return *constant; } if (!value.HasMember("stops")) { @@ -100,7 +101,7 @@ optional<Function<T>> parseProperty(const char* name, const JSValue& value) { stops.emplace_back(z.GetDouble(), *v); } - return { Function<T>(stops, base) }; + return Function<T>(stops, base); } optional<PropertyTransition> parsePropertyTransition(const char * name, const JSValue&); diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp new file mode 100644 index 0000000000..377e4f17e0 --- /dev/null +++ b/src/mbgl/style/property_value.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include <mbgl/util/variant.hpp> +#include <mbgl/style/types.hpp> + +namespace mbgl { + +class Undefined {}; + +template <class T> +class PropertyValue { +private: + using Value = variant<Undefined, T, Function<T>>; + Value value; + +public: + PropertyValue() : value() {} + PropertyValue( T constant) : value(constant) {} + PropertyValue(Function<T> function) : value(function) {} + + bool isUndefined() const { return value.which() == 0; } + bool isConstant() const { return value.which() == 1; } + bool isFunction() const { return value.which() == 2; } + + const T & asConstant() const { return value.template get< T >(); } + const Function<T>& asFunction() const { return value.template get<Function<T>>(); } + + explicit operator bool() const { return !isUndefined(); }; + + template <typename Visitor> + static auto visit(const PropertyValue<T>& value, Visitor&& visitor) { + return Value::visit(value.value, visitor); + } +}; + +} diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 6a67ea9daa..95ab36498d 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -6,7 +6,6 @@ #include <mbgl/layer/raster_layer.hpp> #include <mbgl/layer/background_layer.hpp> #include <mbgl/layer/layer_impl.hpp> -#include <mbgl/layer/symbol_layer_impl.hpp> #include <mbgl/platform/log.hpp> @@ -670,13 +669,15 @@ std::vector<FontStack> StyleParser::fontStacks() const { for (const auto& layer : layers) { if (layer->is<SymbolLayer>()) { - LayoutProperty<FontStack> property = layer->as<SymbolLayer>()->impl->layout.textFont; - if (property.parsedValue) { - for (const auto& stop : property.parsedValue->getStops()) { + PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont(); + if (textFont.isUndefined()) { + result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); + } else if (textFont.isConstant()) { + result.insert(textFont.asConstant()); + } else if (textFont.isFunction()) { + for (const auto& stop : textFont.asFunction().getStops()) { result.insert(stop.second); } - } else { - result.insert(property.value); } } } diff --git a/test/style/functions.cpp b/test/style/functions.cpp index 586941ecf0..8812c77b55 100644 --- a/test/style/functions.cpp +++ b/test/style/functions.cpp @@ -1,62 +1,63 @@ #include <iostream> #include <mbgl/test/util.hpp> -#include <mbgl/style/function_evaluator.hpp> +#include <mbgl/style/property_evaluator.hpp> #include <mbgl/style/style_calculation_parameters.hpp> using namespace mbgl; +float evaluate(PropertyValue<float> value, float zoom) { + return PropertyValue<float>::visit(value, PropertyEvaluator<float>(StyleCalculationParameters(zoom), 0)); +} + TEST(Function, Constant) { - NormalFunctionEvaluator<float> evaluate; - EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(0))); - EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(0))); - EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(0))); - EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(4))); - EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(4))); - EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(4))); - EXPECT_EQ(2.0f, evaluate(Function<float>(2), StyleCalculationParameters(22))); - EXPECT_EQ(3.8f, evaluate(Function<float>(3.8), StyleCalculationParameters(22))); - EXPECT_EQ(22.0f, evaluate(Function<float>(22), StyleCalculationParameters(22))); + EXPECT_EQ(2.0f, evaluate(2, 0)); + EXPECT_EQ(3.8f, evaluate(3.8, 0)); + EXPECT_EQ(22.0f, evaluate(22, 0)); + EXPECT_EQ(2.0f, evaluate(2, 4)); + EXPECT_EQ(3.8f, evaluate(3.8, 4)); + EXPECT_EQ(22.0f, evaluate(22, 4)); + EXPECT_EQ(2.0f, evaluate(2, 22)); + EXPECT_EQ(3.8f, evaluate(3.8, 22)); + EXPECT_EQ(22.0f, evaluate(22, 22)); } TEST(Function, Stops) { - NormalFunctionEvaluator<float> evaluate; - // Explicit constant slope in fringe regions. Function<float> slope_1({ { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(0))); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(4))); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(6))); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, StyleCalculationParameters(7))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(8))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(9))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(15))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(22))); + EXPECT_EQ(1.5, evaluate(slope_1, 0)); + EXPECT_EQ(1.5, evaluate(slope_1, 4)); + EXPECT_EQ(1.5, evaluate(slope_1, 6)); + ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, 7)); + EXPECT_EQ(3.0, evaluate(slope_1, 8)); + EXPECT_EQ(3.0, evaluate(slope_1, 9)); + EXPECT_EQ(3.0, evaluate(slope_1, 15)); + EXPECT_EQ(3.0, evaluate(slope_1, 22)); // Test constant values in fringe regions. Function<float> slope_2({ { 6, 1.5 }, { 8, 3 } }, 1.75); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(0))); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(4))); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(6))); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, StyleCalculationParameters(7))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(8))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(9))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(15))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(22))); + EXPECT_EQ(1.5, evaluate(slope_2, 0)); + EXPECT_EQ(1.5, evaluate(slope_2, 4)); + EXPECT_EQ(1.5, evaluate(slope_2, 6)); + ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, 7)); + EXPECT_EQ(3.0, evaluate(slope_2, 8)); + EXPECT_EQ(3.0, evaluate(slope_2, 9)); + EXPECT_EQ(3.0, evaluate(slope_2, 15)); + EXPECT_EQ(3.0, evaluate(slope_2, 22)); // Test no values. Function<float> slope_3({}, 1.75); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(2))); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(6))); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(12))); + EXPECT_EQ(1, evaluate(slope_3, 2)); + EXPECT_EQ(1, evaluate(slope_3, 6)); + EXPECT_EQ(1, evaluate(slope_3, 12)); // Explicit constant slope in fringe regions. Function<float> slope_4({ { 0, 2 }, { 8, 10 } }, 1); - EXPECT_EQ(2, evaluate(slope_4, StyleCalculationParameters(0))); - EXPECT_EQ(3, evaluate(slope_4, StyleCalculationParameters(1))); - EXPECT_EQ(4, evaluate(slope_4, StyleCalculationParameters(2))); - EXPECT_EQ(4.75, evaluate(slope_4, StyleCalculationParameters(2.75))); - EXPECT_EQ(10, evaluate(slope_4, StyleCalculationParameters(8))); + EXPECT_EQ(2, evaluate(slope_4, 0)); + EXPECT_EQ(3, evaluate(slope_4, 1)); + EXPECT_EQ(4, evaluate(slope_4, 2)); + EXPECT_EQ(4.75, evaluate(slope_4, 2.75)); + EXPECT_EQ(10, evaluate(slope_4, 8)); } |