diff options
author | Sudarsana Babu Nagineni <sudarsana.babu@mapbox.com> | 2019-03-06 14:30:23 +0200 |
---|---|---|
committer | Sudarsana Babu Nagineni <sudarsana.babu@mapbox.com> | 2019-03-08 17:36:40 +0200 |
commit | 744d92e7636ffcba7aea7a302315326b1098d8dc (patch) | |
tree | 11df789f9b6dc0913b3d95f1debbfd87c9225a6a | |
parent | c6598fc5da063f9b60204639cd619647cbbc89da (diff) | |
download | qtlocation-mapboxgl-744d92e7636ffcba7aea7a302315326b1098d8dc.tar.gz |
[core] consolidate Axonometric rendering API
Instead of having individual APIs for setting axonometric
and skew options, create ProjectionMode struct that holds
all the relevant options for Axonometric rendering and
introduce setter/getter on the Map for those options.
-rw-r--r-- | include/mbgl/map/map.hpp | 11 | ||||
-rw-r--r-- | include/mbgl/map/projection_mode.hpp | 34 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 25 | ||||
-rw-r--r-- | src/core-files.json | 1 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/map/transform.cpp | 29 | ||||
-rw-r--r-- | src/mbgl/map/transform.hpp | 9 | ||||
-rw-r--r-- | test/map/map.test.cpp | 11 | ||||
-rw-r--r-- | test/map/transform.test.cpp | 11 |
9 files changed, 89 insertions, 68 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 55f2ab2895..1450b0b3ed 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,6 +9,7 @@ #include <mbgl/annotation/annotation.hpp> #include <mbgl/map/camera.hpp> #include <mbgl/util/geometry.hpp> +#include <mbgl/map/projection_mode.hpp> #include <cstdint> #include <string> @@ -101,13 +102,9 @@ public: void setViewportMode(ViewportMode); ViewportMode getViewportMode() const; - // Projection mode - void setAxonometric(bool); - bool getAxonometric() const; - void setXSkew(double ySkew); - double getXSkew() const; - void setYSkew(double ySkew); - double getYSkew() const; + //Projection Mode + void setProjectionMode(const ProjectionMode&); + ProjectionMode getProjectionMode() const; // Size void setSize(Size); diff --git a/include/mbgl/map/projection_mode.hpp b/include/mbgl/map/projection_mode.hpp new file mode 100644 index 0000000000..4617371e15 --- /dev/null +++ b/include/mbgl/map/projection_mode.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include <mbgl/util/optional.hpp> + +#include <functional> + +namespace mbgl { + +/** + * @brief Holds values for Axonometric rendering. All fields are + * optional. + */ +struct ProjectionMode { + ProjectionMode& withAxonometric(bool o) { axonometric = o; return *this; } + ProjectionMode& withXSkew(double o) { xSkew = o; return *this; } + ProjectionMode& withYSkew(double o) { ySkew = o; return *this; } + + /** + * @brief Set to True to enable axonometric rendering, false otherwise. + */ + optional<bool> axonometric; + + /** + * @brief The X skew value represents how much to skew on the x-axis. + */ + optional<double> xSkew; + + /** + * @brief The Y skew value represents how much to skew on the y-axis. + */ + optional<double> ySkew; +}; + +} // namespace mbgl diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 068fc57a5c..533399a47c 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -3,6 +3,7 @@ #include "node_feature.hpp" #include "node_conversion.hpp" +#include <mbgl/map/projection_mode.hpp> #include <mbgl/util/exception.hpp> #include <mbgl/renderer/renderer.hpp> #include <mbgl/gl/headless_frontend.hpp> @@ -446,17 +447,12 @@ void NodeMap::startRender(NodeMap::RenderOptions options) { camera.bearing = options.bearing; camera.pitch = options.pitch; - if (map->getAxonometric() != options.axonometric) { - map->setAxonometric(options.axonometric); - } - - if (map->getXSkew() != options.xSkew) { - map->setXSkew(options.xSkew); - } + auto projectionOptions = mbgl::ProjectionMode() + .withAxonometric(options.axonometric) + .withXSkew(options.xSkew) + .withYSkew(options.ySkew); - if (map->getYSkew() != options.ySkew) { - map->setYSkew(options.ySkew); - } + map->setProjectionMode(projectionOptions); map->renderStill(camera, options.debugOptions, [this](const std::exception_ptr eptr) { if (eptr) { @@ -1035,7 +1031,8 @@ void NodeMap::SetAxonometric(const Nan::FunctionCallbackInfo<v8::Value>& info) { } try { - nodeMap->map->setAxonometric(info[0]->BooleanValue()); + nodeMap->map->setProjectionMode(mbgl::ProjectionMode() + .withAxonometric(info[0]->BooleanValue())); } catch (const std::exception &ex) { return Nan::ThrowError(ex.what()); } @@ -1052,7 +1049,8 @@ void NodeMap::SetXSkew(const Nan::FunctionCallbackInfo<v8::Value>& info) { } try { - nodeMap->map->setXSkew(info[0]->NumberValue()); + nodeMap->map->setProjectionMode(mbgl::ProjectionMode() + .withXSkew(info[0]->NumberValue())); } catch (const std::exception &ex) { return Nan::ThrowError(ex.what()); } @@ -1069,7 +1067,8 @@ void NodeMap::SetYSkew(const Nan::FunctionCallbackInfo<v8::Value>& info) { } try { - nodeMap->map->setYSkew(info[0]->NumberValue()); + nodeMap->map->setProjectionMode(mbgl::ProjectionMode() + .withYSkew(info[0]->NumberValue())); } catch (const std::exception &ex) { return Nan::ThrowError(ex.what()); } diff --git a/src/core-files.json b/src/core-files.json index ab43e6b409..bba2a94bf2 100644 --- a/src/core-files.json +++ b/src/core-files.json @@ -330,6 +330,7 @@ "mbgl/map/map.hpp": "include/mbgl/map/map.hpp", "mbgl/map/map_observer.hpp": "include/mbgl/map/map_observer.hpp", "mbgl/map/mode.hpp": "include/mbgl/map/mode.hpp", + "mbgl/map/projection_mode.hpp": "include/mbgl/map/projection_mode.hpp", "mbgl/math/clamp.hpp": "include/mbgl/math/clamp.hpp", "mbgl/math/log2.hpp": "include/mbgl/math/log2.hpp", "mbgl/math/minmax.hpp": "include/mbgl/math/minmax.hpp", diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 7fe99e3867..42e14abeb5 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -378,31 +378,13 @@ ViewportMode Map::getViewportMode() const { #pragma mark - Projection mode -void Map::setAxonometric(bool axonometric) { - impl->transform.setAxonometric(axonometric); +void Map::setProjectionMode(const ProjectionMode& options) { + impl->transform.setProjectionMode(options); impl->onUpdate(); } -bool Map::getAxonometric() const { - return impl->transform.getAxonometric(); -} - -void Map::setXSkew(double xSkew) { - impl->transform.setXSkew(xSkew); - impl->onUpdate(); -} - -double Map::getXSkew() const { - return impl->transform.getXSkew(); -} - -void Map::setYSkew(double ySkew) { - impl->transform.setYSkew(ySkew); - impl->onUpdate(); -} - -double Map::getYSkew() const { - return impl->transform.getYSkew(); +ProjectionMode Map::getProjectionMode() const { + return impl->transform.getProjectionMode(); } #pragma mark - Projection diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 96aa5d2f4a..e60ce7a1bd 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -435,28 +435,17 @@ ViewportMode Transform::getViewportMode() const { #pragma mark - Projection mode -void Transform::setAxonometric(bool axonometric) { - state.axonometric = axonometric; +void Transform::setProjectionMode(const ProjectionMode& options) { + state.axonometric = options.axonometric.value_or(state.axonometric); + state.xSkew = options.xSkew.value_or(state.xSkew); + state.ySkew = options.ySkew.value_or(state.ySkew); } -bool Transform::getAxonometric() const { - return state.axonometric; -} - -void Transform::setXSkew(double xSkew) { - state.xSkew = xSkew; -} - -double Transform::getXSkew() const { - return state.xSkew; -} - -void Transform::setYSkew(double ySkew) { - state.ySkew = ySkew; -} - -double Transform::getYSkew() const { - return state.ySkew; +ProjectionMode Transform::getProjectionMode() const { + return ProjectionMode() + .withAxonometric(state.axonometric) + .withXSkew(state.xSkew) + .withYSkew(state.ySkew); } #pragma mark - Transition diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index cf342181b1..c4e10ec797 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -1,6 +1,7 @@ #pragma once #include <mbgl/map/camera.hpp> +#include <mbgl/map/projection_mode.hpp> #include <mbgl/map/map_observer.hpp> #include <mbgl/map/mode.hpp> #include <mbgl/map/transform_state.hpp> @@ -84,12 +85,8 @@ public: ViewportMode getViewportMode() const; // Projection mode - void setAxonometric(bool); - bool getAxonometric() const; - void setXSkew(double xSkew); - double getXSkew() const; - void setYSkew(double ySkew); - double getYSkew() const; + void setProjectionMode(const ProjectionMode&); + ProjectionMode getProjectionMode() const; // Transitions bool inTransition() const; diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 6d1650b82c..3a8d05ebb2 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -268,6 +268,17 @@ TEST(Map, SetStyleDefaultCamera) { EXPECT_DOUBLE_EQ(*camera.zoom, 0.5); } +TEST(Map, ProjectionMode) { + MapTest<> test; + + test.map.setProjectionMode(ProjectionMode().withAxonometric(true).withXSkew(1.0).withYSkew(0.0)); + auto options = test.map.getProjectionMode(); + + EXPECT_TRUE(*options.axonometric); + EXPECT_EQ(*options.xSkew, 1.0); + EXPECT_EQ(*options.ySkew, 0.0); +} + TEST(Map, SetStyleInvalidJSON) { Log::setObserver(std::make_unique<FixtureLogObserver>()); diff --git a/test/map/transform.test.cpp b/test/map/transform.test.cpp index 6e59ca37f3..04b9c1a931 100644 --- a/test/map/transform.test.cpp +++ b/test/map/transform.test.cpp @@ -472,6 +472,17 @@ TEST(Transform, Camera) { ASSERT_DOUBLE_EQ(transform.getLatLng().longitude(), 0); } +TEST(Transform, ProjectionMode) { + Transform transform; + + transform.setProjectionMode(ProjectionMode().withAxonometric(true).withXSkew(1.0).withYSkew(0.0)); + auto options = transform.getProjectionMode(); + + EXPECT_TRUE(*options.axonometric); + EXPECT_EQ(*options.xSkew, 1.0); + EXPECT_EQ(*options.ySkew, 0.0); +} + TEST(Transform, IsPanning) { Transform transform; |