Equivalent of CGPoint with integers?
Cheers,
I like strict typing in C. Therefore, I don't want to store a 2D vector of floats if I specifically ne开发者_StackOverflow中文版ed integers. Is there an Apple-provided equivalent of CGPoint
which stores data as integers?
I've implemented my type Vector2i
and its companion function Vector2iMake()
à la CGPoint, but something deep in me screams that Apple was there already.
Updating to explain.
I need a datatype that will store coordinates in a board game. These are most definitely integers. Same would be if I were to implement a tile-based turn based strategy, or a tile-based RPG.
(to directly answer the question...)
I am not aware of a "NSIntegerPoint", but it wouldn't be difficult to make one:
struct NSIntegerPoint {
NSInteger x;
NSInteger y;
};
Along with stuff like:
CG_INLINE NSIntegerPoint
NSIntegerPointMake(NSInteger x, NSInteger y)
{
NSIntegerPoint p; p.x = x; p.y = y; return p;
}
CG_INLINE bool
__NSIntegerPointEqualToPoint(NSIntegerPoint point1, NSIntegerPoint point2)
{
return point1.x == point2.x && point1.y == point2.y;
}
#define NSIntegerPointEqualToPoint __NSIntegerPointEqualToPoint
If you happen to be representing your game board as objects stored in non-sparse nested arrays, then you may want to consider subclassing NSIndexPath, or using it directly.
From the class reference:
The NSIndexPath class represents the path to a specific node in a tree of nested array collections. This path is known as an index path.
Each index in an index path represents the index into an array of children from one node in the tree to another, deeper, node.
According to iPhone Application Programming Guide, all provided points are float-based. And when you use them to work with the screen (eventually expecting integers), you should anyway use floats for independence from screen resolution and etc.
You could use int vectors?
http://developer.apple.com/mac/library/documentation/Performance/Conceptual/vecLib/Reference/reference.html#//apple_ref/doc/uid/TP40002498-CH1g-TPXREF103
精彩评论