Code archives/Algorithms/Rectangle/Box overlap code (Boolean way)
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This algo, when taken out of the function *should* be faster then the standard blitz method to do the same job *evil grin*. A few notes onit; Coord1 (Source and Dest) should be top-left Coord2 (Source and Dest) should be bottom-right Not tested with coords that are negative! Will return only <zero> or <another number> The point in a rect version of this is here!. | |||||
;Coded by Stephen Greener ;Shagwana@sublimegames.com ;Returns 0 if no overlap else <any> other number if it does! ;The source and dest boxs need to be sorted so that coord 1 are top-left and coords 2 are bottom-right. Function RectOverlap(iSourceXPos1,iSourceYPos1,iSourceXPos2,iSourceYPos2,iDestXPos1,iDestYPos1,iDestXPos2,iDestYPos2) Return ((((iDestXPos2-iSourceXPos1) Xor (iDestXPos1-iSourceXPos2)) And ((iDestYPos1-iSourceYPos2) Xor (iDestYPos2-iSourceYPos1))) And $80000000) End Function ;Should beat the blitz method too, but might do strange things on negative coords. |
Comments
None.
Code Archives Forum