Clip Voronoi regions in cvt_archive_heatmap #356
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.
Description
The current cvt_archive_heatmap relies on faraway points to draw the polygons at the edges of the Voronoi diagram. Thus, if a user zooms out, they will see that the heatmap actually has polygons going beyond it, like below. In practice, we rarely notice this because the cvt_archive_heatmap sets the axis limits to be the bounds of the archive, so the outer regions are hidden.
However, there may be times when this behavior is undesirable, e.g., drawing two cvt archives next to each other. Thus, this PR makes it possible to clip the bounds of the Voronoi diagram, like so:
We accomplish this by taking each polygon and computing its intersection with the archive’s bounding box. Intersections are computed via the shapely library: https://shapely.readthedocs.io/ Furthermore, by using shapely, it is possible to clip to arbitrary shapes:
There are some tradeoffs to turning this feature on by default, namely:
clip=True
, I found that the runtime for 10,000 cells was still ~2.3 sec (much slower than the 0.6 sec in that PR, but still very fast).For these reasons, we will keep this feature turned off by default via the
clip
parameter tocvt_archive_heatmap
.Note that this PR introduces a dependency on shapely, and yet the feature we use shapely for will be turned off by default since
clip=False
. However, I believe this is acceptable because shapely is a well-supported library that is also lightweight (~2MB), so it will not be a burden to users.TODO
Questions
Status
CONTRIBUTING.md
yapf
pytest
pylint
HISTORY.md