iphone - CGPoint 等价于整数?

标签 iphone c objective-c core-graphics

干杯,

我喜欢在 C 中严格输入。因此,如果我特别需要整数,我不想存储 float 的二维 vector 。是否有 Apple 提供的 CGPoint 将数据存储为整数?

我已经实现了我的类型 Vector2i 及其配套函数 Vector2iMake() à la CGPoint,但我内心深处的某些东西尖叫着 Apple 已经在那里了。


更新解释。

我需要一个数据类型来存储棋盘游戏中的坐标。这些绝对是整数。如果我要实现基于图 block 的回合制策略或基于图 block 的 RPG,情况也是如此。

最佳答案

(直接回答问题...)

我不知道“NSIntegerPoint”,但制作一个并不难:

struct NSIntegerPoint {
   NSInteger x;
   NSInteger y;
};

还有像这样的东西:

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

关于iphone - CGPoint 等价于整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2613066/

相关文章:

iphone - facebook样本出现异常

iphone - (retain, nonatomic) 和 (nonatomic, retain) 有什么区别?

iphone - 使用 Sharekit 与 facebook 共享时出现应用程序响应错误

c - execvp 没有读取整个 argv[]?

ios - UIPickerView 显示但不加载数据

objective-c - OS X : How to correctly bridge release pointer with __bridge_transfer

ios - UITableView - 破坏性的 UIContextualAction 不重新加载数据

c - 如何对二维数组使用memset?

c - 使用读/写锁时操作系统崩溃

ios - 单个应用允许多少个基于区域的 UILocalNotification