SHARE
TWEET

Untitled

a guest Nov 14th, 2019 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Point
  2. {
  3.     int x, y;
  4. };
  5.  
  6. // Returns true if two rectangles (l1, r1) and (l2, r2) overlap
  7. bool doOverlap(Point l1, Point r1, Point l2, Point r2)
  8. {
  9.     // If one rectangle is on left side of other
  10.     if (l1.x > r2.x || l2.x > r1.x)
  11.         return false;
  12.  
  13.     // If one rectangle is above other
  14.     if (l1.y < r2.y || l2.y < r1.y)
  15.         return false;
  16.  
  17.     return true;
  18. }
  19.  
  20. /* Driver program to test above function */
  21. int main()
  22. {
  23.     Point l1 = {0, 10}, r1 = {10, 0};
  24.     Point l2 = {5, 5}, r2 = {15, 0};
  25.     if (doOverlap(l1, r1, l2, r2))
  26.         printf("Rectangles Overlap");
  27.     else
  28.         printf("Rectangles Don't Overlap");
  29.     return 0;
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top