Overlap Performance (Minimal)#27
Open
AmityWilder wants to merge 3 commits into
Open
Conversation
Author
|
Related to #7, but hopefully more agreeable due to only involving the reordering of conditions; not duplicating elements into temporary containers or using potentially faulty bounding boxes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
While this does not improve the overall algorithm of identifying what is overlapping what, it improves the overlap performance significantly through just one change that doesn't rely on structure implementations or hardware expectations.
The current implementation iterates over every selected element, checks against each unselected element, and then WITHIN each of those iterations, if there isn't an intersection, it iterates over every unselected element, again, within the "every unselected element" loop, to check a condition that gets cancelled out if an upcoming element is intersecting. This transforms a roughly$O(n^2)$ operation into an $O(n^3)$ operation that can be avoided by simply keeping track of whether there was an intersection at all and performing the "no intersections" branch all in one go.
The proposed solution does this: keeping track of whether a selected element is intersecting any unselected element and only performing the extra checks, once per selected element, if there are no intersections.