Get number of overlapping pixels PHP -


what shortest way number of overlapping pixels between 2 rectangles in php if have x,y coordinates , height/width? bit of best-practices question since i'm doing buggy/messy collection of if statements.

edit: trying fix @ moment:

echo overlapping(1,1,5,5,4,4,6,6).php_eol; echo overlapping(0,0,29,21,30,20,40,50).php_eol; function overlapping($x1,$y1,$w1,$h1,$x2,$y2,$w2,$h2){ $wover = abs($x1+($w1/2)  - ($x2+($w2/2))) - ($w1/2)+ ($w2/2); $hover = abs($y1+($h1/2)  - ($y2+($h2/2))) - ($h1/2)+ ($h2/2); return $wover*$hover; } 

echo overlapping(0,-1,10,20,30,20,40,50);  function overlapping($x1,$y1,$w1,$h1,$x2,$y2,$w2,$h2){  $wover = abs($x1+($w1/2)  - ($x2+($w2/2))) > ($w1/2)+ ($w2/2)?0:1;  $hover = abs($y1+($h1/2)  - ($y2+($h2/2))) > ($h1/2)+ ($h2/2)?0:1;  if($hover && $wover ){ return 'over';  } return 'not';  } 

http://sandbox.onlinephpfunctions.com/code/1ea506fd72f827965d7241d520789a833b34dff5


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -