java - Two overlapping rectangles -
i'm having lot of trouble figuring out wrong code. actually, i'm having difficult time solving problem of 2 rectangles overlapping. following code should, theoretically, work following rectangles: rect1: (2.5, 4) width = 2.5, height = 43 rect2: (1.5, 5) width = 0.5, height = 3 keep in mind can't use rectangle class solve problem. i've done calculated x-values left , right edges , y-values top , bottom edges of both rectangles. i'm first considering -- , know not cover possible cases -- scenario in r2 within r1. note (x1, y1) , (x2, y2) signify centers of rectangles 1 , 2, respectively. right1 = x1 + w1/2; left1 = x1 - w1/2; bottom1 = y1 - h1/2; top1 = y1 + h1/2; right2 = x2 + w2/2; left2 = x2 - w2/2; bottom2 = y2 - h2/2; top2 = y2 + h2/2; overlap = ( (right2 < right1 && right2 > left1) && (bottom2 > bottom1 && bottom2 < top1) && (left2 > left1 && left2 < right1) && (top2 < top1 ...