Distance between two rectangles in Developer Help
Maybe it's just because I'm tired... but I can't figure this out.
Say I have two rectangles, and I know the minimum x and y and the maximum x and y of each. How do I find the shortest distance between the two?
rect var x1;y1;x2;y2 proc/DistanceTo(rect/R2) // assume always that x1<=x2 and y1<=y2 // that can be handled in New() var/dx=max(x1,R2.x1)-min(x2,R2.x2) var/dy=max(y1,R2.y1)-min(y2,R2.y2) if(dx<0) return max(dy,0) if(dy<0) return dx return sqrt(dx*dx+dy*dy)