• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Confused about floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confused about floats


  • Subject: Re: Confused about floats
  • From: Amy Heavey <email@hidden>
  • Date: Tue, 5 Oct 2010 18:18:08 +0100

Got it working, Part of my issue seemed to be my logic.

300 is the bounds of my target image, and I have planned it so images fit inside this, so x would end up being 300. In a stupid moment, I set the if statement to run if x>300, which initially it wouldn't be as it would actually equal 300. However, I didn't spot my mistake as the NSLog inside the if statement appeared in the debugger so I thought it was running the rest of the code inside the if statement. I changed it to > 299 and voila it worked. I did also have to (is the term cast?) the 299 to a float.

I'm googling Fast Enumeration, but I'm compiling for 10.5,

So I'm left with the following which works as intended:

//select all images for kit
NSArray* kitImages = [kit valueForKeyPath:@"kitItems.kitItemProduct.productImage"];

//set coordinates to x,y -> 0,0 to start
float x = 0;
float y = 75;
//for each image
NSEnumerator *imageLoop = [kitImages objectEnumerator];
NSString *imgPath;

while ((imgPath = [imageLoop nextObject])) {
NSImage *img = [[NSImage alloc]initWithContentsOfFile:imgPath];


		//apply image to view
		[targetImage lockFocus];

[img drawInRect:NSMakeRect(x,y,75,75) fromRect:NSMakeRect(20,20,150,150) operation:NSCompositeCopy fraction: 1];

//set new coordinates
x = x+75;

//if coordinates are too wide, start new row - if x>300, reset x to 0 and add 100 to y
if( x > (float)299 ){

x = x-300;
y = y+75;
NSLog(@"x is greater than 300");

}

}
.....
//cleanup
[bmpImageRep release];
[img release];
[kitLogoImg release];
[targetImage release];



Thanks for everyones help.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Confused about floats
      • From: Matt Neuburg <email@hidden>
    • Re: Confused about floats
      • From: Scott Ribe <email@hidden>
References: 
 >Re: Confused about floats (From: Matt Neuburg <email@hidden>)

  • Prev by Date: Re: JDBC from Cocoa or the like
  • Next by Date: Re: Confused about floats
  • Previous by thread: Re: Confused about floats
  • Next by thread: Re: Confused about floats
  • Index(es):
    • Date
    • Thread