Guest User

Untitled

a guest
May 28th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. // Testing overlapsWithRect
  2. // Not Overlapping by one pixel
  3. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
  4. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(101, 101, 100, 100)];
  5. if ([Rect_1 overlapsWithRect:Rect_2])return 0;
  6.  
  7. // Corners overlapping/touching by one pixel
  8. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
  9. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(100, 100, 100, 100)];
  10. if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
  11.  
  12. // Rotate Both by 45 (Should not Overlap Anymore)
  13. [Rect_1 rotate:45];
  14. [Rect_2 rotate:45];
  15. if ([Rect_1 overlapsWithRect:Rect_2]) return 00;
  16.  
  17. // Sides overlapping/touching
  18. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 200, 200)];
  19. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(0, 200, 200, 200)];
  20. if(![Rect_1 overlapsWithRect:Rect_2])return 0;
  21.  
  22. // One totally inside another
  23. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 300, 300)];
  24. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(100, 100, 100, 100)];
  25. if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
  26.  
  27. //Overlap with 2 corners
  28. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 300, 300)];
  29. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(150, 50, 200, 200)];
  30. if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
  31.  
  32. // Overlap but corners not inside each other
  33. Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 50, 300, 100)];
  34. Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(50, 0, 100, 300)];
  35. if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
Add Comment
Please, Sign In to add comment