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);		/* create a new point */

  point addpt(point p1, point p2);	/* add p1 and p2 */
  point subpt(point p1, point p2);	/* subtract p2 from p1 */
  point mulpt(point p, int i);		/* multiply p by i */
  point divpt(point p, int i);		/* divide p by i */
  point midpt(point p1, point p2);	/* find the midpoint */
  int   equalpt(point p1, point p2);	/* does p1 equal p2? */
  int   ptinr(point p, rect r);		/* is p within 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.

To create a new point, call the function pt(x,y).

The function addpt adds the corresponding co-ordinates of its arguments together, hence returning pt(p1.x+p2.x, p1.y+p2.y).

The subpt function subtracts the co-ordinates, producing pt(p1.x-p2.x, p1.y-p2.y).

The mulpt function returns the point pt(p.x*a, p.y*a).

Similarly, divpt returns the point pt(p.x/a, p.y/a).

The mid-point of two points can be found using midpt.

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

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