# How to get the set of points included in the rectangle faster?

+1 vote
Making a game, pseudo-agar.io. jsfiddle.net/Strukov/cr0m6q57

There is a set of points (map.eats) - this is the player's food, there can be a large number, and the more of them, the greater the lag. (For example, on line 66 put 100,000).
The point is that the timer moves and draws the map with many points. For each point, the drawing function is called, although hidden points are not actually drawn, the iteration time is lost.

I want to change the algorithm so that only visible points get into the drawing loop.

Any suggestions for implementation?

I thought of doing this:- Sort the array by X like this:map.eats.sort( (a,b)=>{if(a.x < b.x) return -1; if(a.x > b.x) return 1; return 0;} );- Add a collection of references to the same points, and sort them by Yfor(let eat of map.eats){map.eatsReverse.push(eat);}map.eatsReverse.reverse( (a,b)=>{if(a.x > b.x) return -1; if(a.x < b.x) return 1; return 0;} );- Get visibility area- By binary search, find points included in visibility by X- Remove points not visible by Y- DrawTill now, I stumbled on the binary search.
by