# [ ADV Performance Tunning ] Witch rectangle has the Point ?

Page 1 of 1

## 0 Replies - 4019 Views - Last Post: 02 September 2012 - 09:02 AM

### #1 Ziden

• New D.I.C Head

Reputation: 0
• Posts: 1
• Joined: 02-September 12

# [ ADV Performance Tunning ] Witch rectangle has the Point ?

Posted 02 September 2012 - 09:02 AM

Hello there. Im new to this forums, this is my first post

Im searching for a way to solve a performance issue i have. Its pretty much like a challenge, and its pretty much simple in terms of 'how it works'.

I have a very huge list of awt.Rectangles, and i need to implement 2 simple methods for it. This it works, on the simplest way:

```private List<Zone> set = new ArrayList<Zone>();

public List<Rectangle> getApplicableZones(Point point) {
List<Rectangle> zones = new ArrayList<Rectangle>();
for(Rectangle z : set) {
if(z.contains(point))
}
return zones;
}

public List<Rectange> getIntersections(Rectangle rect) {
List<Rectangle > list = new ArrayList<Rectangle>();
for(Rectangle z : set) {
if(z.intersects(rect))
}
return list;
}
```

But this is not really efficient since i have around 4k Rectangles and its taking too long to process.
Ive tryed to implement a binary tree indexed by X and Y , it got a lil bit better but still not working.

There are some rules to make it simpler:
- You will never have 2 regions close to each other (having one max X = one minimum X)
- Rectangles perimeters NEVER overlaps.
- You will have at most 2 rectangles in a point, you will never have 3 rectangles in the same spot.

This is an image of something it would visually looks like: (attached)

This is for a very big game server im tunning, just cant tell the game

Does anyone would know how to tune this up ? I would really apreciate this help Credits involved in code comments.

Thanks alot for the attention !

Ops, forgot the attachment, there it goes. Sorry for that.

#### Attached image(s)

Is This A Good Question/Topic? 0

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}