Next: 1.2 NSSize Up: 1 Points, Sizes and Previous: 1 Points, Sizes and

1.1 NSPoint

A NSPoint is defined as a struct with two members, the x and y coordinate of the point:
typedef struct _NSPoint
{
  float x;
  float y;
} NSPoint;
So, to access the x and y coordinates of a NSPoint called myPoint, you just do as in myPoint.x and myPoint.y. Please note that the coordinates of a NSPoint are floats; so, they might be negative and/or fractionary.

To create a point with given x and y coordinates, you can use the function (macro) NSMakePoint (), as in the following example:

NSPoint testPoint;

testPoint = NSMakePoint (10, 20);
NSLog (@"x coordinate: %f", testPoint.x); // 10
NSLog (@"y coordinate: %f", testPoint.y); // 20

It might be worth quoting the (predefined) constant NSZeroPoint, which is a point with zero x coordinate and zero y coordinate.



2008-01-16