summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-10 12:05:10 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-11-11 16:59:49 +0200
commitc78e7696352e73f94500fd94a5eaaafffb971be6 (patch)
treea41e8934d663d91b319bcc047a59282f23c63bc5 /src
parente2052ea3e46272f5b0eb26643c0d7e70bad46557 (diff)
downloadqtlocation-mapboxgl-c78e7696352e73f94500fd94a5eaaafffb971be6.tar.gz
[core] Use PrecisionPoint in coordinate functions
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map.cpp39
-rw-r--r--src/mbgl/map/transform.cpp8
-rw-r--r--src/mbgl/map/transform.hpp8
-rw-r--r--src/mbgl/map/transform_state.cpp10
-rw-r--r--src/mbgl/map/transform_state.hpp14
5 files changed, 41 insertions, 38 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 799f2be7af..bff0a42af1 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -161,12 +161,12 @@ void Map::moveBy(const PrecisionPoint& point, const Duration& duration) {
update(Update::Repaint);
}
-void Map::setLatLng(LatLng latLng, const Duration& duration) {
+void Map::setLatLng(const LatLng& latLng, const Duration& duration) {
transform->setLatLng(latLng, duration);
update(Update::Repaint);
}
-void Map::setLatLng(LatLng latLng, vec2<double> point, const Duration& duration) {
+void Map::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
transform->setLatLng(latLng, point, duration);
update(Update::Repaint);
}
@@ -210,7 +210,7 @@ double Map::getZoom() const {
return transform->getZoom();
}
-void Map::setLatLngZoom(LatLng latLng, double zoom, const Duration& duration) {
+void Map::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
transform->setLatLngZoom(latLng, zoom, duration);
update(Update::Zoom);
}
@@ -232,37 +232,40 @@ CameraOptions Map::cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padd
}
// Calculate the bounds of the possibly rotated shape with respect to the viewport.
- vec2<> nePixel = {-INFINITY, -INFINITY};
- vec2<> swPixel = {INFINITY, INFINITY};
+ PrecisionPoint nePixel = {-INFINITY, -INFINITY};
+ PrecisionPoint swPixel = {INFINITY, INFINITY};
for (LatLng latLng : latLngs) {
- vec2<> pixel = pixelForLatLng(latLng);
+ PrecisionPoint pixel = pixelForLatLng(latLng);
swPixel.x = std::min(swPixel.x, pixel.x);
nePixel.x = std::max(nePixel.x, pixel.x);
swPixel.y = std::min(swPixel.y, pixel.y);
nePixel.y = std::max(nePixel.y, pixel.y);
}
- vec2<> size = nePixel - swPixel;
+ double width = nePixel.x - swPixel.x;
+ double height = nePixel.y - swPixel.y;
// Calculate the zoom level.
- double scaleX = (getWidth() - padding.left - padding.right) / size.x;
- double scaleY = (getHeight() - padding.top - padding.bottom) / size.y;
+ double scaleX = (getWidth() - padding.left - padding.right) / width;
+ double scaleY = (getHeight() - padding.top - padding.bottom) / height;
double minScale = ::fmin(scaleX, scaleY);
double zoom = ::log2(getScale() * minScale);
zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom());
// Calculate the center point of a virtual bounds that is extended in all directions by padding.
- vec2<> paddedNEPixel = {
+ PrecisionPoint paddedNEPixel = {
nePixel.x + padding.right / minScale,
nePixel.y + padding.top / minScale,
};
- vec2<> paddedSWPixel = {
+ PrecisionPoint paddedSWPixel = {
swPixel.x - padding.left / minScale,
swPixel.y - padding.bottom / minScale,
};
- vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5;
- LatLng centerLatLng = latLngForPixel(centerPixel);
+ PrecisionPoint centerPixel = {
+ (paddedNEPixel.x + paddedSWPixel.x) / 2,
+ (paddedNEPixel.y + paddedSWPixel.y) / 2,
+ };
- options.center = centerLatLng;
+ options.center = latLngForPixel(centerPixel);
options.zoom = zoom;
return options;
}
@@ -344,19 +347,19 @@ double Map::getMetersPerPixelAtLatitude(const double lat, const double zoom) con
return Projection::getMetersPerPixelAtLatitude(lat, zoom);
}
-const ProjectedMeters Map::projectedMetersForLatLng(const LatLng latLng) const {
+ProjectedMeters Map::projectedMetersForLatLng(const LatLng& latLng) const {
return Projection::projectedMetersForLatLng(latLng);
}
-const LatLng Map::latLngForProjectedMeters(const ProjectedMeters projectedMeters) const {
+LatLng Map::latLngForProjectedMeters(const ProjectedMeters& projectedMeters) const {
return Projection::latLngForProjectedMeters(projectedMeters);
}
-const vec2<double> Map::pixelForLatLng(const LatLng latLng) const {
+PrecisionPoint Map::pixelForLatLng(const LatLng& latLng) const {
return transform->getState().latLngToPoint(latLng);
}
-const LatLng Map::latLngForPixel(const vec2<double> pixel) const {
+LatLng Map::latLngForPixel(const PrecisionPoint& pixel) const {
return transform->getState().pointToLatLng(pixel);
}
diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp
index 403d1a7a35..516591cda0 100644
--- a/src/mbgl/map/transform.cpp
+++ b/src/mbgl/map/transform.cpp
@@ -106,7 +106,7 @@ void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
_easeTo(options, state.scale, state.angle, x, y);
}
-void Transform::setLatLng(const LatLng latLng, const Duration& duration) {
+void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
if (!latLng.isValid()) {
return;
}
@@ -117,8 +117,8 @@ void Transform::setLatLng(const LatLng latLng, const Duration& duration) {
easeTo(options);
}
-void Transform::setLatLng(const LatLng latLng, vec2<double> point, const Duration& duration) {
- if (!latLng.isValid()) {
+void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
+ if (!latLng.isValid() || !point.isValid()) {
return;
}
@@ -138,7 +138,7 @@ void Transform::setLatLng(const LatLng latLng, vec2<double> point, const Duratio
setLatLng(newLatLng, duration);
}
-void Transform::setLatLngZoom(const LatLng latLng, const double zoom, const Duration& duration) {
+void Transform::setLatLngZoom(const LatLng& latLng, const double zoom, const Duration& duration) {
CameraOptions options;
options.center = latLng;
options.zoom = zoom;
diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp
index 06a7487582..5ec68ff4bb 100644
--- a/src/mbgl/map/transform.hpp
+++ b/src/mbgl/map/transform.hpp
@@ -28,10 +28,10 @@ public:
// Position
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
- void setLatLng(LatLng latLng, const Duration& = Duration::zero());
- void setLatLng(LatLng latLng, vec2<double> point, const Duration& duration = Duration::zero());
- void setLatLngZoom(LatLng latLng, double zoom, const Duration& = Duration::zero());
- inline const LatLng getLatLng() const { return state.getLatLng(); }
+ void setLatLng(const LatLng&, const Duration& = Duration::zero());
+ void setLatLng(const LatLng&, const PrecisionPoint&, const Duration& = Duration::zero());
+ void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
+ LatLng getLatLng() const { return state.getLatLng(); }
// Zoom
void scaleBy(double ds, double cx = -1, double cy = -1, const Duration& = Duration::zero());
diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp
index dd67a17c67..cb094577a3 100644
--- a/src/mbgl/map/transform_state.cpp
+++ b/src/mbgl/map/transform_state.cpp
@@ -69,7 +69,7 @@ uint16_t TransformState::getHeight() const {
#pragma mark - Position
-const LatLng TransformState::getLatLng() const {
+LatLng TransformState::getLatLng() const {
LatLng ll;
ll.longitude = -x / Bc;
@@ -216,11 +216,11 @@ float TransformState::worldSize() const {
return util::tileSize * scale;
}
-vec2<double> TransformState::latLngToPoint(const LatLng& latLng) const {
+PrecisionPoint TransformState::latLngToPoint(const LatLng& latLng) const {
return coordinateToPoint(latLngToCoordinate(latLng));
}
-LatLng TransformState::pointToLatLng(const vec2<double> point) const {
+LatLng TransformState::pointToLatLng(const PrecisionPoint& point) const {
return coordinateToLatLng(pointToCoordinate(point));
}
@@ -245,7 +245,7 @@ LatLng TransformState::coordinateToLatLng(const TileCoordinate& coord) const {
return latLng;
}
-vec2<double> TransformState::coordinateToPoint(const TileCoordinate& coord) const {
+PrecisionPoint TransformState::coordinateToPoint(const TileCoordinate& coord) const {
mat4 mat = coordinatePointMatrix(coord.zoom);
matrix::vec4 p;
matrix::vec4 c = {{ coord.column, coord.row, 0, 1 }};
@@ -253,7 +253,7 @@ vec2<double> TransformState::coordinateToPoint(const TileCoordinate& coord) cons
return { p[0] / p[3], height - p[1] / p[3] };
}
-TileCoordinate TransformState::pointToCoordinate(const vec2<double> point) const {
+TileCoordinate TransformState::pointToCoordinate(const PrecisionPoint& point) const {
float targetZ = 0;
const double tileZoom = getZoom();
diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp
index bb65e0ce71..b99595564f 100644
--- a/src/mbgl/map/transform_state.hpp
+++ b/src/mbgl/map/transform_state.hpp
@@ -35,7 +35,7 @@ public:
void getLonLat(double &lon, double &lat) const;
// Position
- const LatLng getLatLng() const;
+ LatLng getLatLng() const;
double pixel_x() const;
double pixel_y() const;
@@ -61,14 +61,14 @@ public:
bool isGestureInProgress() const;
// Conversion and projection
- vec2<double> latLngToPoint(const LatLng& latLng) const;
- LatLng pointToLatLng(const vec2<double> point) const;
+ PrecisionPoint latLngToPoint(const LatLng&) const;
+ LatLng pointToLatLng(const PrecisionPoint&) const;
- TileCoordinate latLngToCoordinate(const LatLng& latLng) const;
- LatLng coordinateToLatLng(const TileCoordinate& coord) const;
+ TileCoordinate latLngToCoordinate(const LatLng&) const;
+ LatLng coordinateToLatLng(const TileCoordinate&) const;
- vec2<double> coordinateToPoint(const TileCoordinate& coord) const;
- TileCoordinate pointToCoordinate(const vec2<double> point) const;
+ PrecisionPoint coordinateToPoint(const TileCoordinate&) const;
+ TileCoordinate pointToCoordinate(const PrecisionPoint&) const;
private:
void constrain(double& scale, double& y) const;