Points

OBJECTS

  typedef struct Point  Point;

  struct Point {
    int x;	/* horizontal co-ordinate */
    int y;	/* vertical co-ordinate */
  };

FUNCTIONS

  Point pt(int x, int y);
  Point new_point(int x, int y);

  int   points_equal(Point p1, Point p2);
  int   point_in_rect(Point p, Rect r);

NOTES

A Point refers to a location in a drawing, which is a bitmap, window or control, using x and y coordinates.

The coordinate system has x increasing to the right and y increasing down. The top-left point of a drawing is always the point (0,0). The pixel corresponding to a point is below and to the right of its coordinates.

Important note: Points, when passed as function parameters, are generally passed by value on the stack. This means that modifying a point within a function will not change its co-ordinates outside that function. Points can thus be treated as numeric objects, like integers. (Were they to be passed by pointer, this would not be the case.) This differs somewhat from the way Java implicitly passes all objects by pointer, except for numbers.

To create a new point, call the function pt(x,y). This is a macro which actually calls new_point, but has a shorter name, for convenience.

The points_equal function compares two points and returns non-zero if they are equal, zero if they are not.

The point_in_rect function returns non-zero if the given point is within the given rectangle, zero otherwise.