Amazon.com Widgets Exercise 8.7 (Comments welcome)
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 23, 2014, 06:53:08 PM
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
|-+ Programming in Objective-C, 4th edition
| |-+ Exercises
| | |-+ Chapter 8
| | | |-+ Exercise 8.7 (Comments welcome)
Pages: [1] Go Down
Print
Author Topic: Exercise 8.7 (Comments welcome) (Read 463 times)
apexmutt
Newbie
*
Posts: 12


Email




on: February 20, 2012, 04:26:50 PM

Just looking for complaints, comments, criticism, etc...

Code: (Objective-C)
-(Rectangle *) intersect:(Rectangle *)aRect
{
    double nonOriginX, nonOriginY, nonOriginWidth, nonOriginHeight;
    Rectangle *interRect = [[Rectangle alloc] init];
    XYpoint *initXY =[[XYpoint alloc] init];
   
    [interRect setOrigin: initXY];
   
    if(origin.x > aRect.origin.x)
    {
        interRect.origin.x = origin.x;
        nonOriginX = aRect.origin.x;
        nonOriginWidth = aRect.width;
    }
    else
    {
        interRect.origin.x = aRect.origin.x;
        nonOriginX = origin.x;
        nonOriginWidth = width;
    }
   
    if(origin.y > aRect.origin.y)
    {
        interRect.origin.y = origin.y;
        nonOriginY = aRect.origin.y;
        nonOriginHeight = aRect.height;
    }
    else
    {
        interRect.origin.y = aRect.origin.y;
        nonOriginY = origin.y;
        nonOriginHeight = height;
    }
   
   
    //Test to see if an intersect exists and if so, calculate width/height and return Rectangle object
   
    if (nonOriginX + nonOriginWidth > interRect.origin.x && nonOriginY + nonOriginHeight > interRect.origin.y)
    {
        interRect.width = (nonOriginX + nonOriginWidth) - interRect.origin.x;
        interRect.height = (nonOriginY + nonOriginHeight) - interRect.origin.y;
        return interRect;
    }
    else
    {
        interRect.height = 0;
        interRect.width = 0;
        interRect.origin.x = 0;
        interRect.origin.y = 0;
       
        return interRect;
    }}
@end
Last Edit: February 20, 2012, 04:28:30 PM by apexmutt 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.