ADDPT(3)

πŸ“¦ version 0_git20260208, in alpine 3.24, arch rolling, nixos 26.05, nixpkgs unstable

✨ NAME ✨

bestie, this page is the whole point-and-rectangle math friend group: addpt, subpt, mulpt, divpt, rectaddpt, rectsubpt, insetrect, canonrect, eqpt, eqrect, ptinrect, rectinrect, rectXrect, rectclip, combinerect, Dx, Dy, Pt, Rect, Rpt β€” all doing arithmetic on points and rectangles. this is the addpt(3) manual, and yes she's iconic πŸ’…


πŸ“š SYNOPSIS πŸ“š

#include <u.h>
#include <libc.h>
#include <draw.h>

Point     addpt(Point p, Point q)

Point     subpt(Point p, Point q)

Point     mulpt(Point p, int a)

Point     divpt(Point p, int a)

Rectangle rectaddpt(Rectangle r, Point p)

Rectangle rectsubpt(Rectangle r, Point p)

Rectangle insetrect(Rectangle r, int n)

Rectangle canonrect(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)

void      combinerect(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)

πŸ’– DESCRIPTION πŸ’–

okay so first up: Pt, Rect, and Rpt are the constructors. they build the geometrical data types out of their components, periodt ✨

  • addpt returns the Point sum of its arguments: Pt(p.x+q.x, p.y+q.y).
  • subpt returns the Point difference of its arguments: Pt(p.x-q.x, p.y-q.y).
  • mulpt returns the Point Pt(p.x*a, p.y*a).
  • divpt returns the Point Pt(p.x/a, p.y/a).
  • rectaddpt returns the Rectangle Rect(add(r.min, p), add(r.max, p));
  • rectsubpt returns the Rectangle Rpt(sub(r.min, p), sub(r.max, p)).
  • insetrect returns the Rectangle Rect(r.min.x+n, r.min.y+n, r.max.x-n, r.max.y-n).
  • canonrect returns a rectangle with the same extent as r, canonicalized so that min.x ≀ max.x, and min.y ≀ max.y. it's giving "make it make sense" energy 🫢
  • 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. no cap, that "unchanged" part matters 😭
  • combinerect overwrites *rp with the smallest rectangle sufficient to cover all the pixels of *rp and b.
  • Dx and Dy give the width (Ξ”x) and height (Ξ”y) of a Rectangle. they are implemented as macros. lowkey cute, highkey useful πŸ’…

🌸 SOURCE 🌸

/src/libdraw


πŸ¦‹ SEE ALSO πŸ¦‹

graphics(3)


okay love u bye πŸ‘‘ this is ADDPT(3) signing off β€” source: /src/libdraw πŸ’– (no separate date/version stamp on this page, just the manual name, slay) 🌈