[core] Use pass-by-ref in CameraOptions
Pass-by-const-ref is not always possible because CameraOptions gets its members modified along the way. Also fixes a case in Map::jumpTo where Update::Zoom should be called if zoom is affected.
This commit is contained in:
@@ -96,8 +96,8 @@ public:
|
||||
bool isPanning() const;
|
||||
|
||||
// Camera
|
||||
void jumpTo(CameraOptions options);
|
||||
void easeTo(CameraOptions options);
|
||||
void jumpTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&);
|
||||
|
||||
// Position
|
||||
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
@@ -113,8 +113,8 @@ public:
|
||||
void setZoom(double zoom, const Duration& = Duration::zero());
|
||||
double getZoom() const;
|
||||
void setLatLngZoom(const LatLng&, double zoom, const Duration& = Duration::zero());
|
||||
CameraOptions cameraForLatLngBounds(LatLngBounds bounds, EdgeInsets padding);
|
||||
CameraOptions cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padding);
|
||||
CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&);
|
||||
CameraOptions cameraForLatLngs(const std::vector<LatLng>&, const EdgeInsets&);
|
||||
void resetZoom();
|
||||
double getMinZoom() const;
|
||||
double getMaxZoom() const;
|
||||
|
||||
@@ -144,12 +144,12 @@ bool Map::isPanning() const {
|
||||
|
||||
#pragma mark -
|
||||
|
||||
void Map::jumpTo(CameraOptions options) {
|
||||
void Map::jumpTo(const CameraOptions& options) {
|
||||
transform->jumpTo(options);
|
||||
update(Update::Repaint);
|
||||
update(options.zoom ? Update::Zoom : Update::Repaint);
|
||||
}
|
||||
|
||||
void Map::easeTo(CameraOptions options) {
|
||||
void Map::easeTo(const CameraOptions& options) {
|
||||
transform->easeTo(options);
|
||||
update(options.zoom ? Update::Zoom : Update::Repaint);
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void Map::setLatLngZoom(const LatLng& latLng, double zoom, const Duration& durat
|
||||
update(Update::Zoom);
|
||||
}
|
||||
|
||||
CameraOptions Map::cameraForLatLngBounds(LatLngBounds bounds, EdgeInsets padding) {
|
||||
CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding) {
|
||||
AnnotationSegment segment = {
|
||||
{bounds.ne.latitude, bounds.sw.longitude},
|
||||
bounds.sw,
|
||||
@@ -225,7 +225,7 @@ CameraOptions Map::cameraForLatLngBounds(LatLngBounds bounds, EdgeInsets padding
|
||||
return cameraForLatLngs(segment, padding);
|
||||
}
|
||||
|
||||
CameraOptions Map::cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padding) {
|
||||
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding) {
|
||||
CameraOptions options;
|
||||
if (latLngs.empty()) {
|
||||
return options;
|
||||
|
||||
@@ -55,36 +55,37 @@ bool Transform::resize(const std::array<uint16_t, 2> size) {
|
||||
|
||||
#pragma mark - Position
|
||||
|
||||
void Transform::jumpTo(const CameraOptions options) {
|
||||
CameraOptions jumpOptions = options;
|
||||
void Transform::jumpTo(const CameraOptions& options) {
|
||||
CameraOptions jumpOptions(options);
|
||||
jumpOptions.duration.reset();
|
||||
easeTo(jumpOptions);
|
||||
}
|
||||
|
||||
void Transform::easeTo(CameraOptions options) {
|
||||
LatLng latLng = options.center ? *options.center : getLatLng();
|
||||
double zoom = options.zoom ? *options.zoom : getZoom();
|
||||
double angle = options.angle ? *options.angle : getAngle();
|
||||
void Transform::easeTo(const CameraOptions& options) {
|
||||
CameraOptions easeOptions(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)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
double new_scale = std::pow(2.0, zoom);
|
||||
|
||||
|
||||
const double s = new_scale * util::tileSize;
|
||||
state.Bc = s / 360;
|
||||
state.Cc = s / util::M2PI;
|
||||
|
||||
|
||||
const double m = 1 - 1e-15;
|
||||
const double f = std::fmin(std::fmax(std::sin(util::DEG2RAD * latLng.latitude), -m), m);
|
||||
|
||||
|
||||
double xn = -latLng.longitude * state.Bc;
|
||||
double yn = 0.5 * state.Cc * std::log((1 + f) / (1 - f));
|
||||
|
||||
options.center.reset();
|
||||
options.zoom.reset();
|
||||
options.angle.reset();
|
||||
_easeTo(options, new_scale, angle, xn, yn);
|
||||
|
||||
easeOptions.center.reset();
|
||||
easeOptions.zoom.reset();
|
||||
easeOptions.angle.reset();
|
||||
_easeTo(easeOptions, new_scale, angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::moveBy(const PrecisionPoint& point, const Duration& duration) {
|
||||
@@ -223,7 +224,8 @@ void Transform::_setScaleXY(const double new_scale, const double xn, const doubl
|
||||
_easeTo(options, new_scale, state.angle, xn, yn);
|
||||
}
|
||||
|
||||
void Transform::_easeTo(CameraOptions options, const double new_scale, const double new_angle, const double xn, const double yn) {
|
||||
void Transform::_easeTo(const CameraOptions& options, double new_scale, double new_angle, double xn, double yn) {
|
||||
CameraOptions easeOptions(options);
|
||||
Update update = state.scale == new_scale ? Update::Repaint : Update::Zoom;
|
||||
double scale = new_scale;
|
||||
double x = xn;
|
||||
@@ -233,12 +235,12 @@ void Transform::_easeTo(CameraOptions options, const double new_scale, const dou
|
||||
|
||||
double angle = _normalizeAngle(new_angle, state.angle);
|
||||
state.angle = _normalizeAngle(state.angle, angle);
|
||||
double pitch = options.pitch ? *options.pitch : state.pitch;
|
||||
double pitch = easeOptions.pitch ? *easeOptions.pitch : state.pitch;
|
||||
|
||||
if (!options.duration) {
|
||||
options.duration = Duration::zero();
|
||||
if (!easeOptions.duration) {
|
||||
easeOptions.duration = Duration::zero();
|
||||
}
|
||||
if (!options.duration || *options.duration == Duration::zero()) {
|
||||
if (!easeOptions.duration || *easeOptions.duration == Duration::zero()) {
|
||||
view.notifyMapChange(MapChangeRegionWillChange);
|
||||
|
||||
state.scale = scale;
|
||||
@@ -266,7 +268,7 @@ void Transform::_easeTo(CameraOptions options, const double new_scale, const dou
|
||||
|
||||
startTransition(
|
||||
[=](double t) {
|
||||
util::UnitBezier ease = options.easing ? *options.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
util::UnitBezier ease = easeOptions.easing ? *easeOptions.easing : util::UnitBezier(0, 0, 0.25, 1);
|
||||
return ease.solve(t, 0.001);
|
||||
},
|
||||
[=](double t) {
|
||||
@@ -289,7 +291,7 @@ void Transform::_easeTo(CameraOptions options, const double new_scale, const dou
|
||||
state.scaling = false;
|
||||
state.rotating = false;
|
||||
view.notifyMapChange(MapChangeRegionDidChangeAnimated);
|
||||
}, *options.duration);
|
||||
}, *easeOptions.duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ public:
|
||||
// Map view
|
||||
bool resize(std::array<uint16_t, 2> size);
|
||||
|
||||
void jumpTo(const CameraOptions options);
|
||||
void easeTo(const CameraOptions options);
|
||||
void jumpTo(const CameraOptions&);
|
||||
void easeTo(const CameraOptions&);
|
||||
|
||||
// Position
|
||||
void moveBy(const PrecisionPoint&, const Duration& = Duration::zero());
|
||||
@@ -69,8 +69,7 @@ private:
|
||||
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,
|
||||
const double xn, const double yn);
|
||||
void _easeTo(const CameraOptions&, double new_scale, double new_angle, double xn, double yn);
|
||||
void _setAngle(double angle, const Duration& = Duration::zero());
|
||||
|
||||
View &view;
|
||||
|
||||
Reference in New Issue
Block a user