-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
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. |
I added a debug file to test the behavior visually. I also used it as a fiddle: |
Linter now passes. Ready for review 👍 |
There was a problem hiding this 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]]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Awesome, thank you! |
The
_cameraForBoxAndBearing
method had several shortcomings that causedcameraForBounds
to return incorrect values whenpadding
oroffset
are asymmetrical. Additionally, because the documented return value is aCameraOptions
object, we can't rely on theoffset
property which was leaked through in the previous implementation.Launch Checklist