Open timrobertson100 opened 7 years ago
Good catch! I'll look into it. Conceptually this method should give you a non-present result for any pixel which is not part of a hexagon so I'll try to implement it like this.
Is this still an issue? The current documentation reads:
@return Maybe with a Hexagon if it is present
Implying that there won't be a result if there is no Hexagon at the specified coordinates.
I'm gonna check, but I don't recall making changes to the code.
This is an enhancement request.
The current implementation of
getByPixelCoordinate()
provides the nearest hexagon when called with a pixel which lies outside thegrid
but within the distance of one hexagon. It is therefore an approximation. This makes good sense for many applications whereby a user is clicking a screen pixel, and some tolerance is acceptable. There are certain use cases however, such as the binning of points into hexagons which require a guarantee that the coordinate lies within the hexagon.While this behaviour remains, a workaround for this scenario is proposed as:
flatTop
you need to increase by 2 hexagons left and right to achieve 1 complete hexagon.flat topped
hexagons with a buffer of 4 hexagons horizontally (2 left, 2 right) and 2 vertically, theoffsetX
is1.5*hexWidth
, and theoffsetY
is1*hexHeight
before callinggetByPixelCoordinate(x,y)
As a quick fix I suggest adding a sentence in the Javadoc for the method as follows: