Simplify AreaMeta and move vision blocking algorithm into a dedicated class #4577
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.
Identify the Bug or Feature request
First part of #4506
Description of the Change
This change is mainly for the complexity & organization aspects of #4506. There is a very small performance improvement in complex cases due to
AreaTree
constructor changes, but there are no big wins - only ~300ms was saved over the ~30s test case referenced in the issue. Another PR will include performance improvements, but would add too much noise to include here.AreaTree
, etc.This is the bulk of the PR. The quartet of
AreaTree
,AreaContainer
,AreaIsland
, andAreaOcean
have been condensed intoAreaTree
with nodes represented by the very plainAreaTree.Node
. The main mutually-recursive algorithmAreaTree.getContainerAt(Point2D)
has been replaced by the iterativeAreaTree.locate(Coordinate)
, which additionally returns more context to better supportVisionBlockingAccumulator
.AreaTree
construction is simplified and more performant due to using JTS'Polygonizer
which associates islands with child oceans for us. It also plays well with the new representation ofAreaMeta
as a list ofCoordinate
vertices forming a ring, which is sufficient for all uses ofAreaMeta
.VisionBlockingAccumulator
A small refactoring in
VisionBlockingAccumulator
unifies a common case across all VBL types where blocking needs to be added for the boundaries of a container and its children. Hill VBL and Pit VBL already had this case factored out for islands, but now Wall VBL and Cover VBL have the same case factored out for oceans. Also included is a newadd(TopologyType, AreaTree)
method so that we dont need to call distinct public methods for each type (helpsFogUtil
out a bit).FogUtil
The final change is pretty trivlal: the visibility sweep algorithm (
FogUtil.calculateVisibleArea()
and related) has been moved out ofFogUtil
into a dedicatedVisibilityProblem
class that doesn't depend so heavily on static methods. A future PR will further refine this with some algorithmic improvements.Possible Drawbacks
Should be none.
Documentation Notes
N/A
Release Notes
This change is