TinyChan

Topic: The many ways of overlapping rectangle/rectangle collision detection.

+Anonymous A1.5 year ago #64,928

function rectRect(ax,ay,aw,ah,bx,by,bw,bh){
  return ax<=bx+bw&&ax+aw>=bx&&ay<=by+bh&&ay+ah>=by;
}

function rectRect(x0,y0,x1,y1,x2,y2,x3,y3){
  return x0<=x3&&x1>=x2&&y0<=y3&&y1>=y2;
}

const{min,max}=Math;
function rectRect(...p){
  for(let i of[0,1,4,5])[p[i],p[i+2]]=[min(p[i],p[i+2]),max(p[i],p[i+2])];
  const[x0,y0,x1,y1,x2,y2,x3,y3]=p;
  return x0<=x3&&x1>=x2&&y0<=y3&&y1>=y2;
} 

const{min,max}=Math;
function rectRect(x0,y0,x1,y1,x2,y2,x3,y3){
  return max(0,min(x1,x3)-max(x0,x2))>0&&max(0,min(y1,y3)-max(y0,y2))>0;
} 

function rectRect(x0,y0,x1,y1,x2,y2,x3,y3){
  return!(x0>=x3||x2>=x1||y0>=y3||y2>=y1);
}

+Anonymous B1.5 year ago, 3 hours later[T] [B] #651,445

Wasting all your time redoing the same old shit from decades ago without trying out anything new.

+Dachan-da1.5 year ago, 13 hours later, 16 hours after the original post[T] [B] #651,464

maths not a toy bud, grow up and leave

Start a new topic to continue this conversation.
Or browse the latest topics.

:

You are required to fill in a captcha for your first 5 posts. Sorry, but this is required to stop people from posting while drunk. Please be responsible and don't drink and post!
If you receive this often, consider not clearing your cookies.



Please familiarise yourself with the rules and markup syntax before posting.