-(BOOL) containsPoint: (XYPoint *) aPoint
{
return (aPoint.x >= origin.x && aPoint.x <= (origin.x + width) && aPoint.y >= origin.y && aPoint.y <= (origin.y + height) ? TRUE : FALSE);
}
Of course, if you want to check it, you will need to do something like this in
main.m:
#import <Foundation/Foundation.h>
#import "Rectangle.h"
int main (int argc, const char * argv[])
{
@autoreleasepool
{
Rectangle *rect = [Rectangle new];
[rect setWidth:30 setHeight:20];
[rect setOriginX:10 setOriginY:15];
XYPoint *point = [XYPoint new];
[point setX:15 setY:20];
if ([rect containsPoint:point])
printf("Rectangle encloses this point.");
else
printf("Rectangle does not enclose this point.");
}
return 0;
}