[bb] Rectangle/Box overlap code (Boolean way) by Shagwana [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Rectangle/Box overlap code (Boolean way)
Author : Shagwana
Posted : 1+ years ago

Description : 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 <a href="http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=118" target="_blank">here</a>!.


Code :
Code (blitzbasic) Select
;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...