[core] PrecisionPoint is now a vec2<double>

We could reuse all the operators defined in vec2<>, including operator
bool() that checks if the contained values are !NaN.
This commit is contained in:
Bruno de Oliveira Abinader
2015-11-12 17:19:34 +02:00
committed by Minh Nguyễn
parent 6748b6155e
commit 8b76f00d8c
7 changed files with 41 additions and 43 deletions

View File

@@ -124,7 +124,7 @@ public:
void setBearing(double degrees, const Duration& = Duration::zero());
void setBearing(double degrees, const PrecisionPoint&);
double getBearing() const;
void resetNorth();
void resetNorth(const Duration& = std::chrono::milliseconds(500));
// Pitch
void setPitch(double pitch, const Duration& = Duration::zero());

View File

@@ -9,17 +9,7 @@ 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));
}
};
using PrecisionPoint = vec2<double>;
struct LatLng {
double latitude = 0;
@@ -28,7 +18,7 @@ struct LatLng {
inline LatLng(double lat = 0, double lon = 0)
: latitude(lat), longitude(lon) {}
inline bool isValid() const {
inline operator bool() const {
return !(std::isnan(latitude) || std::isnan(longitude));
}
@@ -45,7 +35,7 @@ struct ProjectedMeters {
inline ProjectedMeters(double n = 0, double e = 0)
: northing(n), easting(e) {}
inline bool isValid() const {
inline operator bool() const {
return !(std::isnan(northing) || std::isnan(easting));
}
};
@@ -57,8 +47,8 @@ struct LatLngBounds {
inline LatLngBounds(const LatLng& sw_ = {90, 180}, const LatLng& ne_ = {-90, -180})
: sw(sw_), ne(ne_) {}
inline bool isValid() const {
return sw.isValid() && ne.isValid();
inline operator bool() const {
return sw && ne;
}
// Constructs a LatLngBounds object with the tile's exact boundaries.
@@ -98,8 +88,8 @@ struct MetersBounds {
inline MetersBounds(const ProjectedMeters& sw_, const ProjectedMeters& ne_)
: sw(sw_), ne(ne_) {}
inline bool isValid() const {
return sw.isValid() && ne.isValid();
inline operator bool() const {
return sw && ne;
}
};

View File

@@ -41,13 +41,22 @@ struct vec2 {
return {x * o, y * o};
}
template <typename O>
inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type &
operator*=(O o) {
inline void operator*=(T o) {
x *= o;
y *= o;
}
template <typename O>
inline typename std::enable_if<std::is_arithmetic<O>::value, vec2>::type
operator/(O o) const {
return {x / o, y / o};
}
inline void operator/=(T o) {
x /= o;
y /= o;
}
inline vec2<T> operator *(const std::array<float, 16>& matrix) {
return { x * matrix[0] + y * matrix[4] + matrix[12], x * matrix[1] + y * matrix[5] + matrix[13] };
}
@@ -111,7 +120,7 @@ struct vec4 {
};
typedef vec2<int16_t> Coordinate;
using Coordinate = vec2<int16_t>;
}

View File

@@ -777,11 +777,12 @@ void JNICALL nativeRotateBy(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jd
}
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,
jlong duration) {
jlong milliseconds) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetBearing");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().setBearing(degrees, std::chrono::milliseconds(duration));
mbgl::Duration duration((std::chrono::milliseconds(milliseconds)));
nativeMapView->getMap().setBearing(degrees, duration);
}
void JNICALL nativeSetBearing(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble degrees,

View File

@@ -1039,7 +1039,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
CGFloat newRadians = radians + velocity * duration * 0.1;
CGFloat newDegrees = MGLDegreesFromRadians(newRadians) * -1;
_mbglMap->setBearing(newDegrees, secondsAsDuration(duration));
_mbglMap->setBearing(newDegrees, mbgl::Duration(secondsAsDuration(duration)));
_mbglMap->setGestureInProgress(false);
@@ -1555,9 +1555,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
- (void)resetNorthAnimated:(BOOL)animated
{
CGFloat duration = (animated ? MGLAnimationDuration : 0);
_mbglMap->setBearing(0, secondsAsDuration(duration));
_mbglMap->setBearing(0, mbgl::Duration(secondsAsDuration(animated ? MGLAnimationDuration : 0)));
}
- (void)resetPosition
@@ -1789,10 +1787,10 @@ mbgl::LatLngBounds MGLLatLngBoundsFromCoordinateBounds(MGLCoordinateBounds coord
self.userTrackingMode = MGLUserTrackingModeFollow;
}
CGFloat duration = (animated ? MGLAnimationDuration : 0);
CGFloat duration = animated ? MGLAnimationDuration : 0;
_mbglMap->setBearing(direction, mbgl::Duration(secondsAsDuration(duration)));
_mbglMap->setBearing(direction, secondsAsDuration(duration));
if (animated)
{
__weak MGLMapView *weakSelf = self;
@@ -2820,7 +2818,7 @@ CLLocationCoordinate2D MGLLocationCoordinate2DFromLatLng(mbgl::LatLng latLng)
if (headingDirection >= 0 && self.userTrackingMode == MGLUserTrackingModeFollowWithHeading)
{
_mbglMap->setBearing(headingDirection, secondsAsDuration(MGLAnimationDuration));
_mbglMap->setBearing(headingDirection, mbgl::Duration(secondsAsDuration(MGLAnimationDuration)));
}
}

View File

@@ -315,8 +315,8 @@ double Map::getBearing() const {
return -transform->getAngle() / M_PI * 180;
}
void Map::resetNorth() {
transform->setAngle(0, std::chrono::milliseconds(500));
void Map::resetNorth(const Duration& duration) {
transform->setAngle(0, duration);
update(Update::Repaint);
}

View File

@@ -71,7 +71,7 @@ void Transform::easeTo(const CameraOptions& options) {
LatLng latLng = easeOptions.center ? *easeOptions.center : getLatLng();
double zoom = easeOptions.zoom ? *easeOptions.zoom : getZoom();
double angle = easeOptions.angle ? *easeOptions.angle : getAngle();
if (!latLng.isValid() || std::isnan(zoom) || std::isnan(angle)) {
if (!latLng || std::isnan(zoom) || std::isnan(angle)) {
return;
}
@@ -94,7 +94,7 @@ void Transform::easeTo(const CameraOptions& options) {
}
void Transform::moveBy(const PrecisionPoint& point, const Duration& duration) {
if (!point.isValid()) {
if (!point) {
return;
}
@@ -113,7 +113,7 @@ void Transform::_moveBy(const PrecisionPoint& point, const Duration& duration) {
}
void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
if (!latLng.isValid()) {
if (!latLng) {
return;
}
@@ -124,7 +124,7 @@ void Transform::setLatLng(const LatLng& latLng, const Duration& duration) {
}
void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, const Duration& duration) {
if (!latLng.isValid() || !point.isValid()) {
if (!latLng || !point) {
return;
}
@@ -145,7 +145,7 @@ void Transform::setLatLng(const LatLng& latLng, const PrecisionPoint& point, con
}
void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& duration) {
if (!latLng.isValid() || std::isnan(zoom)) {
if (!latLng || std::isnan(zoom)) {
return;
}
@@ -160,7 +160,7 @@ void Transform::setLatLngZoom(const LatLng& latLng, double zoom, const Duration&
#pragma mark - Zoom
void Transform::scaleBy(const double ds, const PrecisionPoint& center, const Duration& duration) {
if (std::isnan(ds) || !center.isValid()) {
if (std::isnan(ds) || !center) {
return;
}
@@ -176,7 +176,7 @@ void Transform::scaleBy(const double ds, const PrecisionPoint& center, const Dur
}
void Transform::setScale(const double scale, const PrecisionPoint& center, const Duration& duration) {
if (std::isnan(scale) || !center.isValid()) {
if (std::isnan(scale) || !center) {
return;
}
@@ -306,7 +306,7 @@ void Transform::_easeTo(const CameraOptions& options, double new_scale, double n
#pragma mark - Angle
void Transform::rotateBy(const PrecisionPoint& first, const PrecisionPoint& second, const Duration& duration) {
if (!first.isValid() || !second.isValid()) {
if (!first || !second) {
return;
}
@@ -346,7 +346,7 @@ void Transform::setAngle(const double new_angle, const Duration& duration) {
}
void Transform::setAngle(const double new_angle, const PrecisionPoint& center) {
if (std::isnan(new_angle) || !center.isValid()) {
if (std::isnan(new_angle) || !center) {
return;
}