Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ (2) — Plan9 1st Edition

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

graphics(2)

ADD(2)

NAME

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

SYNOPSIS

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

Pointadd(Point p, Point q)

Pointsub(Point p, Point q)

Pointmul(Point p, int a)

Pointdiv(Point p, int a)

Rectangleraddp(Rectangle r, Point p)

Rectanglersubp(Rectangle r, Point p)

Rectanglermul(Rectangle r, int a)

Rectanglerdiv(Rectangle r, int a)

Rectanglershift(Rectangle r, int a)

Rectangleinset(Rectangle r, int n)

Rectanglercanon(Rectangle r)

inteqpt(Point p, Point q)

inteqrect(Rectangle r, Rectangle s)

intptinrect(Point p, Rectangle r)

intrectinrect(Rectangle r, Rectangle s)

intrectXrect(Rectangle r, Rectangle s)

intrectclip(Rectangle ∗rp, Rectangle b)

intDx(Rectangle r)

intDy(Rectangle r)

PointPt(int x, int y)

RectangleRect(int x0, int y0, int x1, int y1)

RectangleRpt(Point p, Point q)

DESCRIPTION

The functions Pt, ­Rect and ­Rpt construct geometrical data types from their components.  These are implemented as macros. 

­Add returns the Point sum of its arguments: Pt(p.x+q.x, p.y+q.y).  ­Sub returns the Point difference of its arguments: Pt(p.x-q.x, p.y-q.y).  ­Mul returns the Point Pt(p.x∗a, p.y∗a).  ­Div returns the Point Pt(p.x/a, p.y/a). 

­Raddp returns the Rectangle Rect(add(r.min, p), add(r.max, p)); ­rsubp returns the Rectangle Rpt(sub(r.min, p), sub(r.max, p)).  ­Rmul returns the Rectangle Rpt(mul(r.min,a), mul(r.max,a)); ­Rdiv returns the Rectangle Rpt(div(r.min,a), div(r.max,a)). 

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

­Inset returns the Rectangle Rect(r.min.x+n, r.min.y+n, r.max.x-n, r.max.y-n). 

­Rcanon returns a rectangle with the same extent as r, canonicalized so that ­min.x ≤ max.x, and ­min.y ≤ max.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 r, and 0 otherwise.

­Rectinrect returns 1 if all the pixels in ­r are also in s, 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 b. The return value is 1 if any part of ∗rp is within b. Otherwise, the return value is 0 and ∗rp is unchanged. 

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

SOURCE

­/sys/src/libg

SEE ALSO

graphics(2)

Plan 9  —  April 04, 1995

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026