I have a function that works perfectly for detecting whether or not r1 overlaps with r2:boolean overlaps( Rectangle r1, Rectangle r2 ) {    return r1.x < r2.x + r2.width && r1.x + r1.width > r2.x &&        r1.y < r2.y + r2.height && r1.y + r1.height > r2.y;}But now I would like to add a minimum threshold so that it would return true if r1 overlaps r2 by at least a given length.Here's what I have so far but haven't had any luck:boolean overlaps( Rectangle r1, Rectangle r2, float threshold ) {    return r1.x < r2.x + r2.width && r1.x + r1.width > r2.x + threshold &&        r1.y < r2.y + r2.height && r1.y + r1.height > r2.y + threshold;}
Adding a minimum rectangle overlap threshold
algorithms;geometry
I find it easier to read the expression if you can use named rectangle edges (Left, Top, etc. There may be slight performance advantages also). With that in mind, this code should work:boolean overlaps( Rectangle r1, Rectangle r2, float threshold  ) {    return r1.Left < (r2.Right - threshold) && r1.Right > (r2.Left + threshold) &&        r1.Bottom < (r2.Top - threshold) && r1.Top > (r2.Bottom + threshold);}