diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/transform.cpp | 87 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.cpp | 52 | ||||
-rw-r--r-- | src/mbgl/map/transform_state.hpp | 34 |
3 files changed, 121 insertions, 52 deletions
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 213204e176..323efb9198 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -49,14 +49,13 @@ void Transform::resize(const Size size) { throw std::runtime_error("failed to resize: size is empty"); } - if (state.size == size) { + if (state.getSize() == size) { return; } observer.onCameraWillChange(MapObserver::CameraChangeMode::Immediate); - state.size = size; - state.constrain(state.scale, state.x, state.y); + state.setSize(size); observer.onCameraDidChange(MapObserver::CameraChangeMode::Immediate); } @@ -110,16 +109,16 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim // Find the shortest path otherwise. else startLatLng.unwrapForShortestPath(latLng); - const Point<double> startPoint = Projection::project(startLatLng, state.scale); - const Point<double> endPoint = Projection::project(latLng, state.scale); + const Point<double> startPoint = Projection::project(startLatLng, state.getScale()); + const Point<double> endPoint = Projection::project(latLng, state.getScale()); ScreenCoordinate center = getScreenCoordinate(padding); - center.y = state.size.height - center.y; + center.y = state.getSize().height - center.y; // Constrain camera options. zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom()); const double scale = state.zoomScale(zoom); - pitch = util::clamp(pitch, state.min_pitch, state.max_pitch); + pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch()); // Minimize rotation by taking the shorter path around the circle. bearing = _normalizeAngle(bearing, state.getBearing()); @@ -127,9 +126,9 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim Duration duration = animation.duration ? *animation.duration : Duration::zero(); - const double startScale = state.scale; + const double startScale = state.getScale(); const double startBearing = state.getBearing(); - const double startPitch = state.pitch; + const double startPitch = state.getPitch(); state.setTransitionInProgress(latLng != startLatLng || scale != startScale || bearing != startBearing); startTransition(camera, animation, [=](double t) { @@ -142,7 +141,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim state.setBearing(util::wrap(util::interpolate(startBearing, bearing, t), -M_PI, M_PI)); } if (pitch != startPitch) { - state.pitch = util::interpolate(startPitch, pitch, t); + state.setPitch(util::interpolate(startPitch, pitch, t)); } if (!padding.isFlush()) { @@ -165,7 +164,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima double bearing = camera.bearing.value_or(getBearing()); double pitch = camera.pitch.value_or(getPitch()); - if (std::isnan(zoom) || state.size.isEmpty()) { + if (std::isnan(zoom) || state.getSize().isEmpty()) { return; } @@ -174,28 +173,29 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima LatLng startLatLng = getLatLng(padding).wrapped(); startLatLng.unwrapForShortestPath(latLng); - const Point<double> startPoint = Projection::project(startLatLng, state.scale); - const Point<double> endPoint = Projection::project(latLng, state.scale); + const Point<double> startPoint = Projection::project(startLatLng, state.getScale()); + const Point<double> endPoint = Projection::project(latLng, state.getScale()); ScreenCoordinate center = getScreenCoordinate(padding); - center.y = state.size.height - center.y; + center.y = state.getSize().height - center.y; // Constrain camera options. zoom = util::clamp(zoom, state.getMinZoom(), state.getMaxZoom()); - pitch = util::clamp(pitch, state.min_pitch, state.max_pitch); + pitch = util::clamp(pitch, state.getMinPitch(), state.getMaxPitch()); // Minimize rotation by taking the shorter path around the circle. bearing = _normalizeAngle(bearing, state.getBearing()); state.setBearing(_normalizeAngle(state.getBearing(), bearing)); - const double startZoom = state.scaleZoom(state.scale); + const double startZoom = state.scaleZoom(state.getScale()); const double startBearing= state.getBearing(); - const double startPitch = state.pitch; + const double startPitch = state.getPitch(); /// w₀: Initial visible span, measured in pixels at the initial scale. /// Known henceforth as a <i>screenful</i>. - double w0 = std::max(state.size.width - padding.left() - padding.right(), - state.size.height - padding.top() - padding.bottom()); + const Size& size = state.getSize(); + double w0 = std::max(size.width - padding.left() - padding.right(), + size.height - padding.top() - padding.bottom()); /// w₁: Final visible span, measured in pixels with respect to the initial /// scale. double w1 = w0 / state.zoomScale(zoom - startZoom); @@ -275,7 +275,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima return; } - const double startScale = state.scale; + const double startScale = state.getScale(); state.setTransitionInProgress(true); startTransition(camera, animation, [=](double k) { @@ -301,7 +301,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima state.setBearing(util::wrap(util::interpolate(startBearing, bearing, k), -M_PI, M_PI)); } if (pitch != startPitch) { - state.pitch = util::interpolate(startPitch, pitch, k); + state.setPitch(util::interpolate(startPitch, pitch, k)); } if (!padding.isFlush()) { @@ -339,7 +339,8 @@ void Transform::setLatLng(const LatLng& latLng, optional<ScreenCoordinate> ancho CameraOptions camera; camera.center = latLng; if (anchor) { - camera.padding = EdgeInsets(anchor->y, anchor->x, state.size.height - anchor->y, state.size.width - anchor->x); + const Size& size = state.getSize(); + camera.padding = EdgeInsets(anchor->y, anchor->x, size.height - anchor->y, size.width - anchor->x); } easeTo(camera, animation); } @@ -362,15 +363,17 @@ LatLng Transform::getLatLng(const EdgeInsets& padding) const { if (padding.isFlush()) { return state.getLatLng(); } else { - return screenCoordinateToLatLng(padding.getCenter(state.size.width, state.size.height)); + const Size& size = state.getSize(); + return screenCoordinateToLatLng(padding.getCenter(size.width, size.height)); } } ScreenCoordinate Transform::getScreenCoordinate(const EdgeInsets& padding) const { + const Size& size = state.getSize(); if (padding.isFlush()) { - return { state.size.width / 2., state.size.height / 2. }; + return { size.width / 2.0, size.height / 2.0 }; } else { - return padding.getCenter(state.size.width, state.size.height); + return padding.getCenter(size.width, size.height); } } @@ -488,14 +491,13 @@ void Transform::setPitch(double pitch, optional<ScreenCoordinate> anchor, const } double Transform::getPitch() const { - return state.pitch; + return state.getPitch(); } #pragma mark - North Orientation void Transform::setNorthOrientation(NorthOrientation orientation) { - state.orientation = orientation; - state.constrain(state.scale, state.x, state.y); + state.setNorthOrientation(orientation); } NorthOrientation Transform::getNorthOrientation() const { @@ -504,9 +506,8 @@ NorthOrientation Transform::getNorthOrientation() const { #pragma mark - Constrain mode -void Transform::setConstrainMode(mbgl::ConstrainMode mode) { - state.constrainMode = mode; - state.constrain(state.scale, state.x, state.y); +void Transform::setConstrainMode(mbgl::ConstrainMode constrainMode) { + state.setConstrainMode(constrainMode); } ConstrainMode Transform::getConstrainMode() const { @@ -516,37 +517,37 @@ ConstrainMode Transform::getConstrainMode() const { #pragma mark - Viewport mode void Transform::setViewportMode(mbgl::ViewportMode mode) { - state.viewportMode = mode; + state.setViewportMode(mode); } ViewportMode Transform::getViewportMode() const { return state.getViewportMode(); } -#pragma mark - Projection mode +#pragma mark - Projection void Transform::setAxonometric(bool axonometric) { - state.axonometric = axonometric; + state.setAxonometric(axonometric); } bool Transform::getAxonometric() const { - return state.axonometric; + return state.getAxonometric(); } void Transform::setXSkew(double xSkew) { - state.xSkew = xSkew; + state.setXSkew(xSkew); } double Transform::getXSkew() const { - return state.xSkew; + return state.getXSkew(); } void Transform::setYSkew(double ySkew) { - state.ySkew = ySkew; + state.setYSkew(ySkew); } double Transform::getYSkew() const { - return state.ySkew; + return state.getYSkew(); } #pragma mark - Transition @@ -566,7 +567,7 @@ void Transform::startTransition(const CameraOptions& camera, optional<ScreenCoordinate> anchor = camera.anchor; LatLng anchorLatLng; if (anchor) { - anchor->y = state.size.height - anchor->y; + anchor->y = state.getSize().height - anchor->y; anchorLatLng = state.screenCoordinateToLatLng(*anchor); } @@ -672,20 +673,20 @@ void Transform::cancelTransitions() { } void Transform::setGestureInProgress(bool inProgress) { - state.gestureInProgress = inProgress; + state.setGestureInProgress(inProgress); } #pragma mark Conversion and projection ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const { ScreenCoordinate point = state.latLngToScreenCoordinate(latLng); - point.y = state.size.height - point.y; + point.y = state.getSize().height - point.y; return point; } LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const { ScreenCoordinate flippedPoint = point; - flippedPoint.y = state.size.height - flippedPoint.y; + flippedPoint.y = state.getSize().height - flippedPoint.y; return state.screenCoordinateToLatLng(flippedPoint).wrapped(); } diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index af5e5aea57..47805e6f30 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -100,12 +100,22 @@ Size TransformState::getSize() const { return size; } +void TransformState::setSize(const Size& size_) { + size = size_; + constrain(scale, x, y); +} + #pragma mark - North Orientation NorthOrientation TransformState::getNorthOrientation() const { return orientation; } +void TransformState::setNorthOrientation(NorthOrientation orientation_) { + orientation = orientation_; + constrain(scale, x, y); +} + double TransformState::getNorthOrientationAngle() const { double angleOrientation = 0; if (orientation == NorthOrientation::Rightwards) { @@ -124,12 +134,47 @@ ConstrainMode TransformState::getConstrainMode() const { return constrainMode; } +void TransformState::setConstrainMode(ConstrainMode constrainMode_) { + constrainMode = constrainMode_; + constrain(scale, x, y); +} + #pragma mark - ViewportMode ViewportMode TransformState::getViewportMode() const { return viewportMode; } +void TransformState::setViewportMode(ViewportMode viewportMode_) { + viewportMode = viewportMode_; +} + +#pragma mark - Projection + +void TransformState::setAxonometric(bool axonometric_) { + axonometric = axonometric_; +} + +bool TransformState::getAxonometric() const { + return axonometric; +} + +void TransformState::setXSkew(double xSkew_) { + xSkew = xSkew_; +} + +double TransformState::getXSkew() const { + return xSkew; +} + +void TransformState::setYSkew(double ySkew_) { + ySkew = ySkew_; +} + +double TransformState::getYSkew() const { + return ySkew; +} + #pragma mark - Position LatLng TransformState::getLatLng(LatLng::WrapMode wrapMode) const { @@ -156,6 +201,10 @@ double TransformState::getZoom() const { return scaleZoom(scale); } +double TransformState::getScale() const { + return scale; +} + uint8_t TransformState::getIntegerZoom() const { return getZoom(); } @@ -240,6 +289,9 @@ float TransformState::getPitch() const { return pitch; } +void TransformState::setPitch(double pitch_) { + pitch = pitch_; +} #pragma mark - State diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index 1019f47c30..70cd3d56a2 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -18,8 +18,6 @@ namespace mbgl { class UnwrappedTileID; class TransformState { - friend class Transform; - public: TransformState(ConstrainMode = ConstrainMode::HeightOnly, ViewportMode = ViewportMode::Default); @@ -29,16 +27,30 @@ public: // Dimensions Size getSize() const; + void setSize(const Size& size); // North Orientation NorthOrientation getNorthOrientation() const; + void setNorthOrientation(NorthOrientation); double getNorthOrientationAngle() const; // Constrain mode ConstrainMode getConstrainMode() const; + void setConstrainMode(ConstrainMode); // Viewport mode ViewportMode getViewportMode() const; + void setViewportMode(ViewportMode); + + // Projection mode + bool getAxonometric() const; + void setAxonometric(bool axonometric); + + double getXSkew() const; + void setXSkew(double xSkew); + + double getYSkew() const; + void setYSkew(double ySkew); // Position LatLng getLatLng(LatLng::WrapMode = LatLng::Unwrapped) const; @@ -47,6 +59,7 @@ public: // Zoom double getZoom() const; + double getScale() const; uint8_t getIntegerZoom() const; // Bounds @@ -65,9 +78,13 @@ public: float getBearing() const; void setBearing(double bearing); + // Camera float getFieldOfView() const; float getCameraToCenterDistance() const; + + // Tilt float getPitch() const; + void setPitch(double pitch); // State bool isChanging() const; @@ -92,6 +109,12 @@ public: float getCameraToTileDistance(const UnwrappedTileID&) const; float maxPitchScaleFactor() const; + /** Recenter the map so that the given coordinate is located at the given + point on screen. */ + void moveLatLng(const LatLng&, const ScreenCoordinate&); + void setScalePoint(const double scale, const ScreenCoordinate& point); + void setLatLngZoom(const LatLng &latLng, double zoom); + private: bool rotatedNorth() const; void constrain(double& scale, double& x, double& y) const; @@ -112,13 +135,6 @@ private: mat4 coordinatePointMatrix(double z) const; mat4 getPixelMatrix() const; - /** Recenter the map so that the given coordinate is located at the given - point on screen. */ - void moveLatLng(const LatLng&, const ScreenCoordinate&); - void setLatLngZoom(const LatLng &latLng, double zoom); - void setScalePoint(const double scale, const ScreenCoordinate& point); - -private: ConstrainMode constrainMode; ViewportMode viewportMode; |