在 Objective-C 中创建向量类
我决定使用严格的 Objective-C 为我的应用程序创建一个 Vector 类。我认为发生这种情况的方法是创建一个 Point2D 类,首先以 (x,y) 格式保存每个点,然后创建一个保存 2 个点的 Vector2D 类。
整个事情陷入困境的是我的 Vector2D 类。我试图找到一种方法来在我的 Vector2D 类的实例变量中保存 2 个对象(实际上是 2 个 Point2D 对象)。 我想到了 NSMutableArray 但我记得在这种情况下有很多问题,而且我不确定这是否是最有效的解决方案,因为我正在处理浮点数。
我想要的是通过 Objective-c 的 Vector 类提供某种指导,或者您对我的“任务”的提示/建议。 你会选择如何做这样的事情以及需要额外注意什么。
I decided to create a Vector Class for my app in strict objective-C. The way i thought this could happen is to create a Point2D class first holding each point in a (x,y) format and then create a Vector2D class holding 2 points.
Where the whole thing got stuck is in my Vector2D class. Im trying to find a way to hold 2 objects (actually 2 x Point2D objects) in an instance variable in my Vector2D class.
I thought of an NSMutableArray but i recall many problems in this situation, plus im not sure is the most efficient solution since im dealing with floats.
What i would like is some sort of guidance through a Vector class for objective-c or your tips/recommendations on my "quest".
How would you choose to do such a thing and also what would require extra attention.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
固定大小的 C 数组(在您的情况下为 2)在您的情况下应该是完全可以接受的。由于你的向量不会动态增长,我认为这应该可以正常工作:
C array of fixed size (2 in your case) should be perfectly acceptable in your situation. Since your vector does not grow dynamically, I think this should work just fine: