You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GridExtent.withResolution is unclear and could use reworking because it amplifies a core issue with GridExtent. The issue is that extent and cell sizes are represented as Double while cols and rows are represented as Integer:
A GridExtent can be specified as having an extent and a specific number of cols and rows. This is fine, because we divide a double by an int and get a double cell size in each dimension
A GridExtent can be specified as an extent and a CellSize. This is less fine, because we take a double and divide by a double to get a...double for cols and rows. But cols and rows are ints! So how to we choose what the right answer is for cols and rows in the type conversion?
A bit of a contrived example based on our current implementation:
Note: The starting cell size CellSize(5, 5) doesn't affect the withResolution operation so it's not pictured.
We've cut off something like 25% of our extent without changing our extent to match because the requested CellSize does not cleanly divide at or near an integer boundary, as the initial CellSize of (5,5) does. If cols and rows could be Double, we'd get ~1.4286. Before the require() in @echeipesch 's #2886, the constructors of GridExtent allowed this as well.
The goal of this additional require check was to see where this issue cropped up. So far, its been thrown at the boundaries of floating point math, but in the case of withResolution, it exposed a mismatch in the rounding function used -- a bug.
Even with the fix applied where withResolution doesn't throw due to the bug, users are still capable of calling withResolution with a CellSize that constructs a GridExtent that doesn't align well with integer boundaries. As future work, we propose refactoring the current withResolution method into two methods:
withResolution(cellSize: CellSize, threshold: Double) throws IllegalArgumentException: This method would keep the existing behavior by constructing a GridExtent as long as the requested CellSize is within threshold of a valid integer boundary, otherwise throw.
withApproxResolution(cellSize: CellSize): This method would return a new GridExtent with the CellSize closest to the requested CellSize that gives an integer boundary.
This issue is to replace the existing withResolution with the two methods described in the prev paragraph. It remains unclear what the best threshold value would be.
The text was updated successfully, but these errors were encountered:
GridExtent.withResolution is unclear and could use reworking because it amplifies a core issue with GridExtent. The issue is that extent and cell sizes are represented as Double while cols and rows are represented as Integer:
A bit of a contrived example based on our current implementation:
In picture form, we're requesting:
Note: The starting cell size
CellSize(5, 5)
doesn't affect thewithResolution
operation so it's not pictured.We've cut off something like 25% of our extent without changing our extent to match because the requested CellSize does not cleanly divide at or near an integer boundary, as the initial
CellSize
of (5,5) does. If cols and rows could be Double, we'd get~1.4286
. Before therequire()
in @echeipesch 's #2886, the constructors of GridExtent allowed this as well.The goal of this additional require check was to see where this issue cropped up. So far, its been thrown at the boundaries of floating point math, but in the case of withResolution, it exposed a mismatch in the rounding function used -- a bug.
Even with the fix applied where
withResolution
doesn't throw due to the bug, users are still capable of callingwithResolution
with a CellSize that constructs aGridExtent
that doesn't align well with integer boundaries. As future work, we propose refactoring the currentwithResolution
method into two methods:withResolution(cellSize: CellSize, threshold: Double) throws IllegalArgumentException
: This method would keep the existing behavior by constructing aGridExtent
as long as the requestedCellSize
is withinthreshold
of a valid integer boundary, otherwise throw.withApproxResolution(cellSize: CellSize)
: This method would return a newGridExtent
with theCellSize
closest to the requestedCellSize
that gives an integer boundary.This issue is to replace the existing
withResolution
with the two methods described in the prev paragraph. It remains unclear what the bestthreshold
value would be.The text was updated successfully, but these errors were encountered: