There is an image container with height 5000px and width 5000px.
And there are also N images (in form of rectangle) randomly placed in this container. Each of these images has 4 properties, positionX, positionY (they are the coordinates of where the upper left corner of the image is in the container), height and width.
The question is, what is the most efficient way to check if there are any of these images overlapping with each other in the container? I am going to write the function with either C# or JavaScript.
I was thinking to use an 5000 x 5000 array (int) with starting value 0, then put these images one by one in the array (add 1 to all the elements in the array where image is). If there are any elements in the array turns to 2, return false.
It doesn't seem that efficient by this way.