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

CollisionIndex stores boxes outside of grid range #5654

Closed
ChrisLoer opened this issue Nov 10, 2017 · 5 comments
Closed

CollisionIndex stores boxes outside of grid range #5654

ChrisLoer opened this issue Nov 10, 2017 · 5 comments
Assignees
Labels
bug 🐞 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage

Comments

@ChrisLoer
Copy link
Contributor

We only store collision boxes in a grid that covers the area of the viewport and a little bit of padding outside of it. When we run collision detection, we may place symbols that end up completely outside the range of that grid. These symbols will never detect any collisions, so they'll always get placed. This doesn't usually matter, because they're offscreen. However, if you pan the map to bring them onscreen, they'll be visible until the next placement occurs, which might then detect collisions and cause them to fade out.

In practice, this doesn't seem to be very disruptive -- placement usually happens quickly enough that by the time the too-densely-placed labels come on screen, they're already mostly faded out.

/cc @ansis @jfirebaugh @anandthakker

@ChrisLoer ChrisLoer added bug 🐞 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage labels Nov 10, 2017
@ChrisLoer ChrisLoer changed the title Symbols outside the range of the CollisionIndex always get placed CollisionIndex stores boxes outside of grid range Nov 10, 2017
@ChrisLoer
Copy link
Contributor Author

This is more correct but less performant than I thought on my first reading of the code. 😬

Items outside the grid range get added to the cells right along the edge of the grid. This makes the grid slower than it needs to be, but also prevents the problem I originally described. Essentially it makes the range of the grid infinite, but the performance gets worse the more things you place outside the defined range.

@ChrisLoer
Copy link
Contributor Author

This is more performant but less correct than I thought on my second reading of the code. 😬

It's true that we store boxes for items outside the grid range (which does slow queries along the edges down), but when we query entirely outside the grid range, we'll short circuit the query results to "false":

_query(x1: number, y1: number, x2: number, y2: number, hitTest: boolean) {
if (x2 < 0 || x1 > this.width || y2 < 0 || y1 > this.height) {
return hitTest ? false : [];
}

This means that collision detection still works for features that have any part of their geometry touching the grid, but not for features entirely outside the grid.

In practice, this doesn't seem to be very disruptive -- placement usually happens quickly enough that by the time the too-densely-placed labels come on screen, they're already mostly faded out.

It may not be terrible, but it was at least ugly enough to get reported as #6489.

@dagjomar
Copy link
Contributor

dagjomar commented Jun 6, 2018

Amy progress on this?

ChrisLoer added a commit that referenced this issue Jun 6, 2018
Fixes issue #5654, brings gl-js behavior in line with gl-native.
symbol-placement/line-overscaled functions as a regression test.
@ChrisLoer
Copy link
Contributor Author

@dagjomar I put together a PR at #6784, we should merge it soon. If you're interested, you might try checking out that branch to see if you get the behavior you'd expect after the changes.

ChrisLoer added a commit that referenced this issue Jun 9, 2018
Fixes issue #5654, brings gl-js behavior in line with gl-native.
symbol-placement/line-overscaled functions as a regression test.
ChrisLoer added a commit that referenced this issue Jun 13, 2018
Fixes issue #5654, brings gl-js behavior in line with gl-native.
symbol-placement/line-overscaled functions as a regression test.
ChrisLoer added a commit that referenced this issue Jun 13, 2018
Fixes issue #5654, brings gl-js behavior in line with gl-native.
symbol-placement/line-overscaled functions as a regression test.
@mourner
Copy link
Member

mourner commented Jul 25, 2018

This was fixed in #6784.

@mourner mourner closed this as completed Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 performance ⚡ Speed, stability, CPU usage, memory usage, or power usage
Projects
None yet
Development

No branches or pull requests

3 participants