diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2018-01-24 00:04:02 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-24 00:04:02 -0800 |
commit | fb5b8d34f20b696319cfc16838243265143ba972 (patch) | |
tree | bdbb9a02e89c84e26cdabd38add1a6d6f805b4d0 /include | |
parent | d4ed8d1a4474e43241e42610001403261353466f (diff) | |
download | qtlocation-mapboxgl-fb5b8d34f20b696319cfc16838243265143ba972.tar.gz |
Reimplement style values atop NSExpression (#10726)
* [ios, macos] Import headers, not implementation files
* [core] Added accessors for various expression parameters
Added missing parameter accessors to various expression operator classes, as well as a method on InterpolatorBase and Step that enumerates the stops and their values.
* [ios, macos] Silenced warning in test of error condition
* [ios, macos] Made MGLSphericalPosition boxable
* [ios, macos] Implemented array enumeration during conversion
* [ios, macos] Temporarily ignore heatmap layer type
* [ios, macos] Migrated MGLSymbolStyleLayer.text to NSExpression
MGLSymbolStyleLayer.text is now of type NSExpression instead of MGLStyleValue, as a first step toward migrating the entire layer API from style values to expressions.
Implemented conversions from NSExpression to JSON arrays and vice versa. The most common NSExpression functions are now converted into style expressions, but not all of the most common style expression operators are supported yet.
* [ios, macos] Implemented string coercion
* [ios, macos] Color literals
* [ios, macos] Null constant expressions
* [ios, macos] Convert dictionary literals
* [ios, macos] Interpolation expressions
* [ios, macos] to-boolean, to-number, get from object
* [ios, macos] Variable expressions
Implemented custom expression functions for assigning and referring to variables within the context of an expression. Variables are assigned via a “context dictionary” and applied to an subexpression that is given as another argument to the same expression. Also implemented built-in variable expressions for zoom level and heatmap density.
* [ios, macos] Convert colors, offsets, padding in expressions to JSON objects
* [ios, macos] Expression-based style property getters
Implemented a conversion from mbgl::style::PropertyValues to Objective-C JSON objects, which are then converted to NSExpressions.
* [ios, macos] Consolidated property value–expression conversion in MGLStyleValueTransformer
* [ios, macos] Predicate and expression guide
Extracted documentation about predicates from a documentation comment in MGLVectorStyleLayer.h to a new jazzy guide. Added details about NSExpression support as well. Began updating the “For Style Authors” guide to reflect the transition from style values to expressions.
* [ios, macos] Updated style authoring guide
Updated the Information for Style Authors guide to discuss expressions instead of style functions. Included a table mapping style specification expression operators to NSExpression syntaxes.
* [ios, macos] Migrated codegen templates to expressions
* [ios, macos] Applied expression changes via codegen
Ran make darwin-style-code.
* [macos] Migrated macosapp to expressions
* [ios, macos] Updated style function guide
This guide needs to be thoroughly rewritten, but for now the example code has been migrated to expressions.
* [ios, macos] Eviscerated style function tests
* [ios, macos] Updated changelogs
* [ios] Migrated iosapp to expressions
* [ios, macos] Exposed JSON conversion methods publicly
* [ios, macos] Removed MGLStyleValue, MGLStyleFunction
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/expression/interpolate.hpp | 7 | ||||
-rw-r--r-- | include/mbgl/style/expression/step.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/style/function/camera_function.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/style/function/composite_function.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/style/function/source_function.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/util/unitbezier.hpp | 11 |
6 files changed, 26 insertions, 1 deletions
diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index c82c04bbb0..dbed74b4cd 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -70,6 +70,7 @@ public: {} const std::unique_ptr<Expression>& getInput() const { return input; } + const Interpolator& getInterpolator() const { return interpolator; } void eachChild(const std::function<void(const Expression&)>& visit) const override { visit(*input); @@ -77,6 +78,12 @@ public: visit(*stop.second); } } + + void eachStop(const std::function<void(double, const Expression&)>& visit) const { + for (const auto& stop : stops) { + visit(stop.first, *stop.second); + } + } // Return the smallest range of stops that covers the interval [lower, upper] Range<float> getCoveringStops(const double lower, const double upper) const { diff --git a/include/mbgl/style/expression/step.hpp b/include/mbgl/style/expression/step.hpp index 4a0a724d7c..6bf42e20f1 100644 --- a/include/mbgl/style/expression/step.hpp +++ b/include/mbgl/style/expression/step.hpp @@ -27,6 +27,7 @@ public: EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function<void(const Expression&)>& visit) const override; + void eachStop(const std::function<void(double, const Expression&)>& visit) const; const std::unique_ptr<Expression>& getInput() const { return input; } Range<float> getCoveringStops(const double lower, const double upper) const; diff --git a/include/mbgl/style/function/camera_function.hpp b/include/mbgl/style/function/camera_function.hpp index 015abd3e62..1da5d2c601 100644 --- a/include/mbgl/style/function/camera_function.hpp +++ b/include/mbgl/style/function/camera_function.hpp @@ -76,7 +76,9 @@ public: } bool useIntegerZoom = false; - + + const expression::Expression& getExpression() const { return *expression; } + // retained for compatibility with pre-expression function API Stops stops; diff --git a/include/mbgl/style/function/composite_function.hpp b/include/mbgl/style/function/composite_function.hpp index 24578f599c..f391b101ae 100644 --- a/include/mbgl/style/function/composite_function.hpp +++ b/include/mbgl/style/function/composite_function.hpp @@ -111,6 +111,8 @@ public: return *lhs.expression == *rhs.expression; } + const expression::Expression& getExpression() const { return *expression; } + std::string property; Stops stops; optional<T> defaultValue; diff --git a/include/mbgl/style/function/source_function.hpp b/include/mbgl/style/function/source_function.hpp index bd7b109fd8..d3caa90ee5 100644 --- a/include/mbgl/style/function/source_function.hpp +++ b/include/mbgl/style/function/source_function.hpp @@ -68,6 +68,8 @@ public: bool useIntegerZoom = false; + const expression::Expression& getExpression() const { return *expression; } + // retained for compatibility with pre-expression function API std::string property; Stops stops; diff --git a/include/mbgl/util/unitbezier.hpp b/include/mbgl/util/unitbezier.hpp index 92f23d6718..56d2ab6ead 100644 --- a/include/mbgl/util/unitbezier.hpp +++ b/include/mbgl/util/unitbezier.hpp @@ -42,6 +42,17 @@ struct UnitBezier { , ay(1.0 - (3.0 * p1y) - (3.0 * (p2y - p1y) - (3.0 * p1y))) { } + std::pair<double, double> getP1() const { + return { cx / 3.0, cy / 3.0 }; + } + + std::pair<double, double> getP2() const { + return { + (bx + (3.0 * cx / 3.0) + cx) / 3.0, + (by + (3.0 * cy / 3.0) + cy) / 3.0, + }; + } + double sampleCurveX(double t) const { // `ax t^3 + bx t^2 + cx t' expanded using Horner's rule. return ((ax * t + bx) * t + cx) * t; |