I have a grid on which users can draw rectangles (actually rooms in a house). Because rooms cannot cross each other, I try to check for conflicts before drawing the second room. So far I managed to check if the ‘to-point’ of the second rectangle is inside the first rectangle (=> return false). But the code has to ‘return: false’ also when the boundaries of the room cross another room.
I have set up an example page here
To try it, click anywhere in the grid and click somewhere else to create the first room. Then click outside this box and move the cursor to see the problem…
In the source code I have marked the concerning code (starts on line 175).
Thanks in advance!
You return false in the anonymous function called by the each statement 🙂 the checkConflict function always return true ! Look :
This is easy to fix but I give you the updated code because your tests are not correct too ( you want to test if you are INSIDE the box, your previous code would always return false ) So this is probably something like this (you have to improve this code because it won’t work perfectly either) :
EDIT:
I wrote the correct code. I thought it would be easier but, a promise is a promise… There are probably ways to refactor the code but the headache is enough for now 😀
I made a JSFiddle so you can see the result : http://jsfiddle.net/T4ta9/2/