[core] Added PrecisionPoint to represent pixel points
This commit is contained in:
@@ -100,7 +100,7 @@ public:
|
||||
void easeTo(CameraOptions options);
|
||||
|
||||
// Position
|
||||
void moveBy(double dx, double dy, const Duration& = Duration::zero());
|
||||
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
void setLatLng(LatLng latLng, vec2<double> point, const Duration& = Duration::zero());
|
||||
void setLatLng(LatLng latLng, const Duration& = Duration::zero());
|
||||
LatLng getLatLng() const;
|
||||
|
||||
@@ -3,10 +3,24 @@
|
||||
|
||||
#include <mbgl/util/vec.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class TileID;
|
||||
|
||||
struct PrecisionPoint {
|
||||
double x = 0;
|
||||
double y = 0;
|
||||
|
||||
inline PrecisionPoint(double x_ = 0, double y_ = 0)
|
||||
: x(x_), y(y_) {}
|
||||
|
||||
inline bool isValid() const {
|
||||
return !(std::isnan(x) || std::isnan(y));
|
||||
}
|
||||
};
|
||||
|
||||
struct LatLng {
|
||||
double latitude = 0;
|
||||
double longitude = 0;
|
||||
@@ -21,7 +35,7 @@ struct LatLng {
|
||||
// Constructs a LatLng object with the top left position of the specified tile.
|
||||
LatLng(const TileID& id);
|
||||
|
||||
vec2<double> project() const;
|
||||
PrecisionPoint project() const;
|
||||
};
|
||||
|
||||
struct ProjectedMeters {
|
||||
|
||||
@@ -13,7 +13,7 @@ void PointAnnotationImpl::updateLayer(const TileID& tileID, AnnotationTileLayer&
|
||||
featureProperties.emplace("sprite", point.icon.empty() ? std::string("default_marker") : point.icon);
|
||||
|
||||
const uint16_t extent = 4096;
|
||||
const vec2<double> pp = point.position.project();
|
||||
const mbgl::PrecisionPoint pp = point.position.project();
|
||||
const uint32_t z2 = 1 << tileID.z;
|
||||
const uint32_t x = pp.x * z2;
|
||||
const uint32_t y = pp.y * z2;
|
||||
|
||||
@@ -156,8 +156,8 @@ void Map::easeTo(CameraOptions options) {
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
void Map::moveBy(double dx, double dy, const Duration& duration) {
|
||||
transform->moveBy(dx, dy, duration);
|
||||
void Map::moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
transform->moveBy(point, duration);
|
||||
update(Update::Repaint);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,21 +87,20 @@ void Transform::easeTo(CameraOptions options) {
|
||||
_easeTo(options, new_scale, angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::moveBy(const double dx, const double dy, const Duration& duration) {
|
||||
if (std::isnan(dx) || std::isnan(dy)) {
|
||||
void Transform::moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
if (!point.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_moveBy(dx, dy, duration);
|
||||
_moveBy(point, duration);
|
||||
}
|
||||
|
||||
void Transform::_moveBy(const double dx, const double dy, const Duration& duration) {
|
||||
|
||||
double x = state.x + std::cos(state.angle) * dx + std::sin( state.angle) * dy;
|
||||
double y = state.y + std::cos(state.angle) * dy + std::sin(-state.angle) * dx;
|
||||
void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
double x = state.x + std::cos(state.angle) * point.x + std::sin( state.angle) * point.y;
|
||||
double y = state.y + std::cos(state.angle) * point.y + std::sin(-state.angle) * point.x;
|
||||
|
||||
state.constrain(state.scale, y);
|
||||
|
||||
|
||||
CameraOptions options;
|
||||
options.duration = duration;
|
||||
_easeTo(options, state.scale, state.angle, x, y);
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
void easeTo(const CameraOptions options);
|
||||
|
||||
// Position
|
||||
void moveBy(double dx, double dy, const Duration& = Duration::zero());
|
||||
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());
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
bool isPanning() const { return state.isPanning(); }
|
||||
|
||||
private:
|
||||
void _moveBy(double dx, double dy, const Duration& = Duration::zero());
|
||||
void _moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
void _setScale(double scale, double cx, double cy, const Duration& = Duration::zero());
|
||||
void _setScaleXY(double new_scale, double xn, double yn, const Duration& = Duration::zero());
|
||||
void _easeTo(CameraOptions options, const double new_scale, const double new_angle,
|
||||
|
||||
@@ -372,7 +372,7 @@ void Painter::renderBackground(const BackgroundLayer& layer) {
|
||||
patternShader->u_opacity = properties.opacity;
|
||||
|
||||
LatLng latLng = state.getLatLng();
|
||||
vec2<double> center = state.latLngToPoint(latLng);
|
||||
PrecisionPoint center = state.latLngToPoint(latLng);
|
||||
float scale = 1 / std::pow(2, zoomFraction);
|
||||
|
||||
std::array<float, 2> sizeA = imagePosA.size;
|
||||
|
||||
@@ -12,7 +12,7 @@ LatLng::LatLng(const TileID& id) {
|
||||
latitude = 180.0 / M_PI * std::atan(0.5 * (std::exp(n) - std::exp(-n)));
|
||||
}
|
||||
|
||||
vec2<double> LatLng::project() const {
|
||||
PrecisionPoint LatLng::project() const {
|
||||
// Clamp to the latitude limits of Mercator.
|
||||
const double constrainedLatitude = ::fmin(::fmax(latitude, -util::LATITUDE_MAX), util::LATITUDE_MAX);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user