Skip to content

Overlap performance#7

Open
AmityWilder wants to merge 3 commits intobsiever:masterfrom
AmityWilder:bsiever-collision-perf
Open

Overlap performance#7
AmityWilder wants to merge 3 commits intobsiever:masterfrom
AmityWilder:bsiever-collision-perf

Conversation

@AmityWilder
Copy link

(Copied from PR 4 on anadon's repo)

  • Copy element Sets to temporary arrays and ArrayLists, since they will be iterated over far more than they will be searched within the overlap method.
  • Implement a bounding box for the selection and remove any elements not overlapping the bounding box from the temporary unselected element ArrayList before any further checks.
    • Use swap-removal since order doesn't matter, making the removal worst case $O(1)$ instead of $O(n)$
  • Crunch the $O(n^3)$ section in the "else" case for simple intersections down to $O(n^2)$, since that part seems to just be checking against all elements per element per selected element--despite only involving the selected element and all other elements, not the selected element and all permutations of other elements.
    i.e.
for (Element sel : selected) {          // O(n)
  for (Element el : elementsArr) {      // O(n^2)
    if (intersecting) { ... }
    else {
      for (Element elm : elementsArr) { // O(n^3)
        if (sel ? elm) // no mention of `el`

$$\large\Downarrow$$

for (Element sel : selected) {       // O(n)
  for (Element el : elementsArr) {   // O(n^2)
    if (intersecting) { ... }
  }
  if (none intersected) {
    for (Element el : elementsArr) { // O(n^2)
      if (sel ? el) // ...

AmityWilder and others added 3 commits February 10, 2026 19:37
Touching and then moving would not update the "touching" status of elements that stopped being touched, until overlap() fails.
@AmityWilder AmityWilder changed the title Collision perf Overlap performance Feb 12, 2026
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.

1 participant