Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#45) Implemented realtime bounding box calculation. #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zerobandwidth
Copy link

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 to GeoJsonObject 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 each GeoJsonObject implementation which sets the object's geometry. This ensures that the value of the bbox class member is always up-to-date, even if the object's geometry changes over time. Since the base class's equals() method considered bbox 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 in GeoJsonObject. (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 the bbox member from all equals() methods. This would remove the need to keep bbox 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. 😊 😆

Made changes and added sufficient tests to not only verify the feature but also kill all Lint warnings in files that I modified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant