0

So basically im doing this for my minecraft spigot plugin (java). I know there are already some land claim plugins but i would like to make my own. For this claim plugin i'd like to know how to get if a point (minecraft block) is inside a region (rectangle). i know how to check if a point is inside a rectangle, the main problem is how to check as quickly as possible when there are like lets say 10.000 rectangles.

What would be the most efficient way to check 10.000 or even 100.000 without having to manually loop through all of them and check every single rectangle?

2 Answers2

0

Is there a way to add a logical test when the rectangles get generated in a way that checks if they hold that point? In that case you could set a boolean to true if they contain that point when generated, and then when checking for that minecraft block the region (rectangle) replies with true or false.

This way you run the loops or checks when generating the rectangles, but when running the game the replies should happen very fast, just check if true or false for bool ContainsPoint.

Joacopaz
  • 76
  • 4
0

If your rectangles are uniformly placed neighbors of each other in a big rectangle, then finding which rectangle contains point is easy:

width = (maxX-minX)/num_rectangles_x;
height = same but for y
idx = floor( (x - minX)/width );
idy = floor( (y - minY)/height );
id_square = idx + idy*num_rectangles_x;

If your rectangles are randomly placed, then you should use a spatial acceleration structure like octree. Then check if point is in root, then check if point is in one of its nodes, repeat until you find a leaf that includes the point. 10000 tests per 10milliseconds should be reachable on cpu. 1 million tests per 10ms should be ok for a gpu. But you may need to implement a sparse version of the octree and a space filling curve order for leaf nodes to have better caching, to reach those performance levels.

huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97