Fix clipping with exact coordinates #144
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #143
This fixes the coordinate clipping issue with the values I tested (as shown in the example below), but I'm not sure if it could cause other issues and I don't think it solves it for all values.
There are two approximation issues at play here. One is in
_match_latitude
and_match_longitude
and causesclip(layer; top=56.0).top
to return the wrong coordinate. My fix there is a bit ugly as I'm not sure what's going in those functions. It is sufficient to fix the issues when clipping withtop
andleft
in my example, but not withbottom
andright
.The 2nd approximation issue occurs in
clip
itself, for instance withclip(layer; bottom=64.0
. Here the index returned by_match_latitude
is correct, but subtracting the stride returns 63.9999999999999. I usedisapprox
andround
to fix it when trying to clip with natural numbers (which should be the most common case to encounter this bug) but I didn't see how to fix it for all coordinates that would be exactly on the boundary without callingisapprox
on all of them.The full example: