views:

113

answers:

1

Is there an appropriate structure provided in the Apple foundation kits to represent discrete coordinate systems? I know I can just use the integral component of NSPoint and by convention keep it discrete, or even define my own.

However if there is one already which is typed correctly I would prefer that and avoid implicit / explicit type nastiness.

+5  A: 

I'm not aware of one that serves your exact needs. You could certainly use CGPoint or NSPoint, but since you know the values will be discrete integers, why waste the precision on a non-existent fractional part? In addition, repeated casts to integer values would get old quickly. You'd be much better served to create your own typedef using integer types, like so:

typedef struct _DiscretePoint {
    NSInteger x;
    NSInteger y;
} DiscretePoint;

You could also use int32_t instead of NSInteger if you know the values will never exceed the 32-bit range — this will conserve some space in 64-bit mode. (See this SO question for details about NSInteger, etc.)

Quinn Taylor
Yes, I agree, there is really no appropriate structure that comes with the standard API's - I looked through places where it would make sense (such as raster image/device dimension methods, etc) and found they generally just used points or dual width/height parameters or accessors, or just use CGSize/CGPoint and floats everywhere.
groundhog