[core] PrecisionPoint is now ScreenCoordinate

This commit is contained in:
Bruno de Oliveira Abinader
2016-02-09 20:56:07 +02:00
parent 1ce99d2d7b
commit 4994b3dc57
16 changed files with 124 additions and 124 deletions

View File

@@ -36,7 +36,7 @@ static double _normalizeAngle(double angle, double anchorAngle)
return angle;
}
inline bool _validPoint(const PrecisionPoint& point) {
inline bool _validPoint(const ScreenCoordinate& point) {
return !std::isnan(point.x) && !std::isnan(point.y);
}
@@ -97,16 +97,16 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
padding = *camera.padding;
}
const LatLng startLatLng = getLatLng(padding);
const PrecisionPoint startPoint = {
const ScreenCoordinate startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
unwrapLatLng(latLng);
const PrecisionPoint endPoint = {
const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
PrecisionPoint center = padding.getCenter(state.width, state.height);
ScreenCoordinate center = padding.getCenter(state.width, state.height);
center.y = state.height - center.y;
// Constrain camera options.
@@ -134,7 +134,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
state.rotating = angle != startAngle;
startTransition(camera, animation, [=](double t) {
PrecisionPoint framePoint = util::interpolate(startPoint, endPoint, t);
ScreenCoordinate framePoint = util::interpolate(startPoint, endPoint, t);
LatLng frameLatLng = {
state.yLat(framePoint.y, startWorldSize),
state.xLng(framePoint.x, startWorldSize),
@@ -180,16 +180,16 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
padding = *camera.padding;
}
const LatLng startLatLng = getLatLng(padding);
const PrecisionPoint startPoint = {
const ScreenCoordinate startPoint = {
state.lngX(startLatLng.longitude),
state.latY(startLatLng.latitude),
};
unwrapLatLng(latLng);
const PrecisionPoint endPoint = {
const ScreenCoordinate endPoint = {
state.lngX(latLng.longitude),
state.latY(latLng.latitude),
};
PrecisionPoint center = padding.getCenter(state.width, state.height);
ScreenCoordinate center = padding.getCenter(state.width, state.height);
center.y = state.height - center.y;
// Constrain camera options.
@@ -305,7 +305,7 @@ void Transform::flyTo(const CameraOptions &camera, const AnimationOptions &anima
double us = u(s);
// Calculate the current point and zoom level along the flight path.
PrecisionPoint framePoint = util::interpolate(startPoint, endPoint, us);
ScreenCoordinate framePoint = util::interpolate(startPoint, endPoint, us);
double frameZoom = startZoom + state.scaleZoom(1 / w(s));
// Convert to geographic coordinates and set the new viewpoint.
@@ -344,19 +344,19 @@ void Transform::unwrapLatLng(LatLng& latLng) {
#pragma mark - Position
void Transform::moveBy(const PrecisionPoint& offset, const Duration& duration) {
void Transform::moveBy(const ScreenCoordinate& offset, const Duration& duration) {
if (!_validPoint(offset)) {
return;
}
PrecisionPoint centerOffset = {
ScreenCoordinate centerOffset = {
offset.x,
-offset.y,
};
PrecisionPoint centerPoint = state.latLngToPoint(state.getLatLng()) - centerOffset;
ScreenCoordinate centerPoint = state.latLngToScreenCoordinate(state.getLatLng()) - centerOffset;
CameraOptions camera;
camera.center = state.pointToLatLng(centerPoint);
camera.center = state.screenCoordinateToLatLng(centerPoint);
easeTo(camera, duration);
}
@@ -377,7 +377,7 @@ void Transform::setLatLng(const LatLng& latLng, const EdgeInsets& padding, const
easeTo(camera, duration);
}
void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
void Transform::setLatLng(const LatLng& latLng, const ScreenCoordinate& point, const Duration& duration) {
if (!latLng || !point) {
return;
}
@@ -414,7 +414,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const EdgeInset
LatLng Transform::getLatLng(const EdgeInsets& padding) const {
if (padding) {
return pointToLatLng(padding.getCenter(state.width, state.height));
return screenCoordinateToLatLng(padding.getCenter(state.width, state.height));
} else {
return state.getLatLng();
}
@@ -423,7 +423,7 @@ LatLng Transform::getLatLng(const EdgeInsets& padding) const {
#pragma mark - Zoom
void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration& duration) {
void Transform::scaleBy(double ds, const ScreenCoordinate& center, const Duration& duration) {
if (std::isnan(ds)) {
return;
}
@@ -432,12 +432,12 @@ void Transform::scaleBy(double ds, const PrecisionPoint& center, const Duration&
setScale(scale, center, duration);
}
void Transform::setZoom(double zoom, const PrecisionPoint& anchor, const Duration& duration) {
void Transform::setZoom(double zoom, const ScreenCoordinate& anchor, const Duration& duration) {
setScale(state.zoomScale(zoom), anchor, duration);
}
void Transform::setZoom(double zoom, const EdgeInsets& padding, const Duration& duration) {
const PrecisionPoint center = padding.getCenter(state.width, state.height);
const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setZoom(zoom, center, duration);
}
@@ -449,7 +449,7 @@ double Transform::getScale() const {
return state.scale;
}
void Transform::setScale(double scale, const PrecisionPoint& anchor, const Duration& duration) {
void Transform::setScale(double scale, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(scale)) {
return;
}
@@ -461,7 +461,7 @@ void Transform::setScale(double scale, const PrecisionPoint& anchor, const Durat
}
void Transform::setScale(double scale, const EdgeInsets& padding, const Duration& duration) {
const PrecisionPoint center = padding.getCenter(state.width, state.height);
const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setScale(scale, center, duration);
}
@@ -475,15 +475,15 @@ void Transform::setMaxZoom(const double maxZoom) {
#pragma mark - Angle
void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) {
void Transform::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const Duration& duration) {
if (!first || !second) {
return;
}
PrecisionPoint center(state.width, state.height);
ScreenCoordinate center(state.width, state.height);
center /= 2;
const PrecisionPoint offset = first - center;
const ScreenCoordinate offset = first - center;
const double distance = std::sqrt(std::pow(2, offset.x) + std::pow(2, offset.y));
// If the first click was too close to the center, move the center of rotation by 200 pixels
@@ -495,8 +495,8 @@ void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& seco
center.y = first.y + std::sin(rotateAngle) * heightOffset;
}
const PrecisionPoint newFirst = first - center;
const PrecisionPoint newSecond = second - center;
const ScreenCoordinate newFirst = first - center;
const ScreenCoordinate newSecond = second - center;
const double ang = state.angle + util::angle_between(newFirst.x, newFirst.y, newSecond.x, newSecond.y);
CameraOptions camera;
@@ -508,7 +508,7 @@ void Transform::setAngle(double angle, const Duration& duration) {
setAngle(angle, {NAN, NAN}, duration);
}
void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Duration& duration) {
void Transform::setAngle(double angle, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(angle)) {
return;
}
@@ -520,7 +520,7 @@ void Transform::setAngle(double angle, const PrecisionPoint& anchor, const Durat
}
void Transform::setAngle(double angle, const EdgeInsets& padding, const Duration& duration) {
const PrecisionPoint center = padding.getCenter(state.width, state.height);
const ScreenCoordinate center = padding.getCenter(state.width, state.height);
setAngle(angle, center, duration);
}
@@ -534,7 +534,7 @@ void Transform::setPitch(double pitch, const Duration& duration) {
setPitch(pitch, {NAN, NAN}, duration);
}
void Transform::setPitch(double pitch, const PrecisionPoint& anchor, const Duration& duration) {
void Transform::setPitch(double pitch, const ScreenCoordinate& anchor, const Duration& duration) {
if (std::isnan(pitch)) {
return;
}
@@ -585,11 +585,11 @@ void Transform::startTransition(const CameraOptions& camera,
view.notifyMapChange(isAnimated ? MapChangeRegionWillChangeAnimated : MapChangeRegionWillChange);
// Associate the anchor, if given, with a coordinate.
PrecisionPoint anchor = camera.anchor ? *camera.anchor : PrecisionPoint(NAN, NAN);
ScreenCoordinate anchor = camera.anchor ? *camera.anchor : ScreenCoordinate(NAN, NAN);
LatLng anchorLatLng;
if (_validPoint(anchor)) {
anchor.y = state.getHeight() - anchor.y;
anchorLatLng = state.pointToLatLng(anchor);
anchorLatLng = state.screenCoordinateToLatLng(anchor);
}
transitionStart = Clock::now();
@@ -664,14 +664,14 @@ void Transform::setGestureInProgress(bool inProgress) {
#pragma mark Conversion and projection
PrecisionPoint Transform::latLngToPoint(const LatLng& latLng) const {
PrecisionPoint point = state.latLngToPoint(latLng);
ScreenCoordinate Transform::latLngToScreenCoordinate(const LatLng& latLng) const {
ScreenCoordinate point = state.latLngToScreenCoordinate(latLng);
point.y = state.height - point.y;
return point;
}
LatLng Transform::pointToLatLng(const PrecisionPoint& point) const {
PrecisionPoint flippedPoint = point;
LatLng Transform::screenCoordinateToLatLng(const ScreenCoordinate& point) const {
ScreenCoordinate flippedPoint = point;
flippedPoint.y = state.height - flippedPoint.y;
return state.pointToLatLng(flippedPoint);
return state.screenCoordinateToLatLng(flippedPoint);
}