1. ## Algorithm Help

Problem: I have coordinates of of two side of the rectangles-

Suppose I have coordinates of 5000 boxes. Like this-
Code:
```         (    x1,    y1)    (    x2,    y2)
(0.0000,0.0000)    (0.3412,0.4175)
(0.7445,0.0000)    (1.0000,0.6553)
(0.7445,0.6553)    (1.0000,1.0000)
(0.0000,0.6553)    (0.7445,1.0000)
(0.3412,0.0000)    (0.7445,0.4175)
(0.3412,0.4175)    (0.7445,0.6553)
(0.0000,0.4175)    (0.3412,0.6553) ...etc```
These coordinates subdivide an unit squre like this -

I want to calculate the number of nearest rectangles for each of the boxes using c++.

Example

For rectangle# 7 the nearest boxes are- 4,1,6 and 2
(If they share only corner they are not consider as nearest boxes, So rectangle 5 & 3 are not nearest of rectangle 7)

Can anyone help me how can I write the algorithm for this problem?

2. If two boxes are touching, they must be along the same vertical or horizontal line:
Code:
```.        |-----
|     |
|  C  |
|     |
----|-----
| A  |
|    |
----|
|
|----
|    |
------| D  |
|      |    |
|   B  |    |
|      |----
|      |
------|
|```
A and D do not touch at all. A and C only touch at the corners. B and D touch at more than just corners. The kinds of comparisons you'd make to separate the cases are obvious.