Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Testing overlapsWithRect
- // Not Overlapping by one pixel
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(101, 101, 100, 100)];
- if ([Rect_1 overlapsWithRect:Rect_2])return 0;
- // Corners overlapping/touching by one pixel
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 100, 100)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(100, 100, 100, 100)];
- if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
- // Rotate Both by 45 (Should not Overlap Anymore)
- [Rect_1 rotate:45];
- [Rect_2 rotate:45];
- if ([Rect_1 overlapsWithRect:Rect_2]) return 00;
- // Sides overlapping/touching
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 200, 200)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(0, 200, 200, 200)];
- if(![Rect_1 overlapsWithRect:Rect_2])return 0;
- // One totally inside another
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 300, 300)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(100, 100, 100, 100)];
- if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
- //Overlap with 2 corners
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 0, 300, 300)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(150, 50, 200, 200)];
- if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
- // Overlap but corners not inside each other
- Rect_1 = [[PERectangle alloc] initWithRect:CGRectMake(0, 50, 300, 100)];
- Rect_2 = [[PERectangle alloc] initWithRect:CGRectMake(50, 0, 100, 300)];
- if (![Rect_1 overlapsWithRect:Rect_2]) return 0;
Add Comment
Please, Sign In to add comment