Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #7517 - asymmetrical cameraForBounds #7518

Merged
merged 5 commits into from
Oct 31, 2018
Merged

Fix #7517 - asymmetrical cameraForBounds #7518

merged 5 commits into from
Oct 31, 2018

Conversation

mike-marcacci
Copy link
Contributor

@mike-marcacci mike-marcacci commented Oct 30, 2018

The _cameraForBoxAndBearing method had several shortcomings that caused cameraForBounds to return incorrect values when padding or offset are asymmetrical. Additionally, because the documented return value is a CameraOptions object, we can't rely on the offset property which was leaked through in the previous implementation.

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • manually test the debug page

@mike-marcacci
Copy link
Contributor Author

The existing test was incorrect given my understanding of how the method should work based on documentation. I fixed the test and added more to explicitly test these scenarios.

@mike-marcacci
Copy link
Contributor Author

mike-marcacci commented Oct 31, 2018

I added a debug file to test the behavior visually. I also used it as a fiddle:

@mike-marcacci
Copy link
Contributor Author

Linter now passes. Ready for review 👍

Copy link
Member

@mourner mourner left a comment

Choose a reason for hiding this comment

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

Apart from minor nitpicks this looks like a well thought-out PR — thanks for taking on this!

src/ui/camera.js Outdated

// Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
const paddingOffset = [(options.padding.left - options.padding.right) / 2, (options.padding.top - options.padding.bottom) / 2];
const offsetAtInitialZoom = Point.convert([options.offset[0] + paddingOffset[0], options.offset[1] + paddingOffset[1]]);
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: let's avoid temporary arrays here by using new Point(x, y) instead of Point.convert([x, y]), and maybe declaring separate paddingOffsetX and paddingOffsetY variables since we don't really need it being in an array.

Copy link
Member

Choose a reason for hiding this comment

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

Also, options.offset is of PointLike type so this code will break if you pass e.g. offset: new Point(10, 10) instead of offset: [10, 10]. So let's bring back the const offset = Point.convert(options.offset) line and use that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great points! It looks like the previous implementation was also accessing array indices directly, so I added a test to make sure PointLike objects work.

@mourner mourner merged commit ea9fbee into mapbox:master Oct 31, 2018
@mourner
Copy link
Member

mourner commented Oct 31, 2018

Awesome, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants