Amazon.com Widgets Ex. 8.6: containsPoint one-line solution
Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2013, 03:23:12 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 8
| | | |-+  Ex. 8.6: containsPoint one-line solution
Pages: [1]   Go Down
Print
Author Topic: Ex. 8.6: containsPoint one-line solution  (Read 583 times)
Jemcik
Newbie
*
Posts: 22



Email




« on: November 19, 2011, 03:48:04 PM »

Code: (Objective-C)
-(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:
Code: (Objective-C)
#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;
}
« Last Edit: November 19, 2011, 03:57:48 PM by Jemcik » Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.