(#45) Implemented realtime bounding box calculation. #46
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.
This pull request includes changes to implement the proposal from issue #45 for real-time updates to each object's "bounding box". Along the way, it also adds a bit more unit test coverage to the existing classes.
Approach
An abstract
calculateBounds()
method has been added toGeoJsonObject
and implemented in each subclass. This method recalculates the bounding box around whatever coordinates are stored within the object. The method may be called explicitly, but it is also called by each method in eachGeoJsonObject
implementation which sets the object's geometry. This ensures that the value of thebbox
class member is always up-to-date, even if the object's geometry changes over time. Since the base class'sequals()
method consideredbbox
in its requirements for equality, this was necessary to ensure that practically equal objects were programmatically considered equal.For any geometric object that represents a single shape, the object recalculates its bounding box from scratch, each time it is modified. However, for any object that represents a list of shapes, or a list of points that define a shape, the object accumulates bounding box statistics with each additional member. This is an attempt to improve the overall performance of the realtime update mechanism as much as possible.
Consequences
There will likely be a slight performance hit because of the overhead of calculating this bounding box for each object. However every attempt has been made to minimize this in the algorithm used.
In order to prevent unintended rendering of the
bbox
member in JSON serializations, a@JsonIgnore
annotation has been added to the accessor/mutator for this field inGeoJsonObject
. (Without this annotation, once the bounding boxes were updated with non-null values, some previous unit tests began to fail.)Alternatives
As an alternative implementation, we could provide the
calculateBounds()
methods as a utility, but remove the consideration for thebbox
member from allequals()
methods. This would remove the need to keepbbox
updated in realtime.Testing
A set of jUnit tests has been added to meaningfully each of the
calculateBounds()
methods. All existing unit tests also pass.Disclaimer
"Derpy" in the second commit comment is me admonishing myself for not checking my work the first time. 😊 😆