add






add, sub, mul, divpt, raddp, rsubp, rmul, rdiv, rshift,
inset, rcanon, eqpt, eqrect, ptinrect, rectinrect,
rectXrect, rectclip, Dx, Dy, Pt, Rect, Rpt − arithmetic on
points and rectangles


#include <libc.h>
#include <libg.h>

     Point       add(Point p, Point q)

     Point     sub(Point p, Point q)

     Point     mul(Point p, int a)

     Point     divpt(Point p, int a)

     Rectangle raddp(Rectangle r, Point p)

     Rectangle rsubp(Rectangle r, Point p)

     Rectangle rmul(Rectangle r, int a)

     Rectangle rdiv(Rectangle r, int a)

     Rectangle rshift(Rectangle r, int a)

     Rectangle inset(Rectangle r, int n)

     Rectangle rcanon(Rectangle r)

     int  eqpt(Point p, Point q)

     int  eqrect(Rectangle r, Rectangle s)

     int  ptinrect(Point p, Rectangle r)

     int  rectinrect(Rectangle r, Rectangle s)

     int  rectXrect(Rectangle r, Rectangle s)

     int  rectclip(Rectangle *rp, Rectangle b)

     int  Dx(Rectangle r);

     int  Dy(Rectangle r);

     Point     Pt(int x, int y)

     Rectangle Rect(int x0, int y0, int x1, int y1)

     Rectangle Rpt(Point p, Point q)











                             ‐2‐


The functions Rect and Rpt construct geometrical data types
from their components.  These are implemented as functions.
(Under Plan 9 these are implemented as macros.)

     Add returns the Point sum of its arguments: .x+Pt(p Sub
returns the Point difference of its arguments: .x‐Pt(p Mul
returns the Point .x*Pt(p Divpt returns the Point .x/Pt(p

     Raddp returns the Rectangle .min,Rect(add(r .max,add(r
rsubp returns the Rectangle .min,Rpt(sub(r .max,sub(r Rmul
returns the Rectangle .min,Rpt(mul(r .max,mul(r Rdiv returns
the Rectangle .min,Rpt(div(r .max,div(r

     Rshift returns the rectangle r with all coordinates
either left‐shifted or right‐shifted by depending on whether
a is positive or negative, respectively.

     Inset returns the Rectangle .min.x+Rect(r

     Rcanon returns a rectangle with the same extent as
canonicalized so that min.x <= and min.y <=

     Eqpt compares its argument Points and returns 0 if
unequal, 1 if equal.  Eqrect does the same for its argument
Rectangles.

     Ptinrect returns 1 if p is a point within and 0
otherwise.

     Rectinrect returns 1 if all the pixels in r are also in
and 0 otherwise.

     RectXrect returns 1 if r and s share any point, and 0
otherwise.

     Rectclip clips in place the Rectangle pointed to by rp
so that it is completely contained within The return value
is 1 if any part of is within Otherwise, the return value is
0 and is unchanged.

     The functions Dx and Dy give the width (delta x) and
height (delta y) of a Rectangle.  They are implemented as
macros.