Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Transform cleanup #13452

Merged
merged 3 commits into from
Nov 27, 2018
Merged

Transform cleanup #13452

merged 3 commits into from
Nov 27, 2018

Conversation

brunoabinader
Copy link
Member

A follow-up to #13445, this PR refactors Transform to reduce its API surface.

@brunoabinader
Copy link
Member Author

screenshot from 2018-11-26 16-42-58
😍

Copy link
Contributor

@pozdnyakov pozdnyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall

platform/glfw/glfw_view.cpp Outdated Show resolved Hide resolved
@@ -88,7 +88,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
double angle = camera.angle ? -*camera.angle * util::DEG2RAD : getAngle();
double pitch = camera.pitch ? *camera.pitch * util::DEG2RAD : getPitch();

if (std::isnan(zoom)) {
if (std::isnan(zoom) || std::isnan(angle) || std::isnan(pitch)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's out of this patch scope, however, is it fine we just return here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could transform this into an assertion, or throw an exception (though I know you're not fond of it) ;) but I'd prefer to treat this in a separate issue/PR.

src/mbgl/map/transform.cpp Outdated Show resolved Hide resolved
src/mbgl/map/transform_state.cpp Outdated Show resolved Hide resolved
@brunoabinader
Copy link
Member Author

@pozdnyakov applied review changes 👍 thanks! ✔️ ?

Copy link
Contributor

@pozdnyakov pozdnyakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

include/mbgl/map/camera.hpp Outdated Show resolved Hide resolved
platform/ios/src/MGLMapView.mm Outdated Show resolved Hide resolved
// If the number of touches has changed, the remembered center point is
// meaningless.
if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches)
{
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
self.mbglMap.setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
mbgl::EdgeInsets { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this line doing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s still adjusting the frame of reference for the center coordinate, but now it does so by padding all four sides so that the padding covers the entire view, instead of setting an anchor point explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - as @1ec5 mentioned, this was previously done inside an overload for setLatLng in Transform that also received an anchor point as a parameter - this overload has been removed in this PR to avoid confusion.

// If the number of touches has changed, the remembered center point is
// meaningless.
if (self.userTrackingMode == MGLUserTrackingModeNone && pinch.numberOfTouches == _previousPinchNumberOfTouches)
{
CLLocationCoordinate2D centerCoordinate = _previousPinchCenterCoordinate;
self.mbglMap.setLatLng(MGLLatLngFromLocationCoordinate2D(centerCoordinate),
mbgl::ScreenCoordinate { centerPoint.x, centerPoint.y });
mbgl::EdgeInsets { centerPoint.y, centerPoint.x, self.size.height - centerPoint.y, self.size.width - centerPoint.x });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s still adjusting the frame of reference for the center coordinate, but now it does so by padding all four sides so that the padding covers the entire view, instead of setting an anchor point explicitly.

transform.setAngle(5.0);
transform.setPitch(40.0 * M_PI / 180.0);

transform.jumpTo(CameraOptions().withCenter(LatLng { 0.1, -0.1 }).withZoom(8.0).withAngle(5.0).withPitch(40.0));
Copy link
Contributor

@1ec5 1ec5 Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past, we avoided designated initializer lists because certain compilers we targeted didn’t support them. Is that still the case, or could we use designated initializer lists instead of the builder pattern?

transform.jumpTo(CameraOptions {
    .center = LatLng { 0.1, -0.1 },
    .zoom = 8.0,
    .angle = 5.0,
    .pitch = 40.0,
});

Both syntaxes provide more clarity than unlabeled constructor parameters, but I find designated initializer lists to be more elegant. We already use designated initializer lists liberally in Objective-C++ code in platform/{darwin,ios,macos}/, since Clang supports them as an extension to C++. For example:

MGLMatrix4 mat4 = {
.m00 = array[0], .m01 = array[1], .m02 = array[2], .m03 = array[3],
.m10 = array[4], .m11 = array[5], .m12 = array[6], .m13 = array[7],
.m20 = array[8], .m21 = array[9], .m22 = array[10], .m23 = array[11],
.m30 = array[12], .m31 = array[13], .m32 = array[14], .m33 = array[15]
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I'm quite fond of designated initializer lists too, this technique is a bit different as it links chained setters via a reference to the CameraOptions object, but the constructor still remains empty. In C++, support for designated initializers comes in C++20, so it'll take a while until all our supported platforms can get availability on this.

Copy link
Contributor

@1ec5 1ec5 Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, Clang has supported designated initializers in C++ for years as an extension to the C++ standard. GCC at some point introduced support for “trivial designated initializers”, which means the fields have to come in the same order as they’re declared, like in Swift.

/ref #26 #4722

@brunoabinader brunoabinader merged commit f772a63 into master Nov 27, 2018
@brunoabinader brunoabinader deleted the transform-cleanup branch November 27, 2018 19:38

EXPECT_EQ((std::vector<UnwrappedTileID>{
{ 2, 1, 2 }, { 2, 1, 1 }, { 2, 2, 2 }, { 2, 2, 1 }, { 2, 3, 2 }
{ 2, 1, 1 }, { 2, 2, 1 }, { 2, 1, 2 }, { 2, 2, 2 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of results returned by tile cover is important. It is supposed to radiate out from the center. Is there a reason that the order and number of tiles is changing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asheemmamoowala yes - previously, the bearing (angle) was set in the transform object, which receives bearing in radians. The value, however, is 5.0, which I assume it is supposed to indicate a value in degrees. The updated code fixes this typo and has the bearing value set via CameraOptions, which now properly receives degree values for both bearing and pitch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants