CG/NSPoint-like integer tuple type?
Is there an appropriate structure provided in the Apple foundation kits to represent discrete coordinate systems? I know I can just use the integral co开发者_如何学运维mponent 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.
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.)
精彩评论