henesyinit from p9fce6d0435 years agoHistory
159 lines · 2.0 KB · C
RawDownload
#include <u.h>#include <libg.h> /* These routines are NOT portable, but they are fast. */ Pointadd(Point a, Point b){	a.x += b.x;	a.y += b.y;	return a;} Pointsub(Point a, Point b){	a.x -= b.x;	a.y -= b.y;	return a;} Rectangleinset(Rectangle r, int n){	r.min.x += n;	r.min.y += n;	r.max.x -= n;	r.max.y -= n;	return r;} Pointdiv(Point a, int b){	a.x /= b;	a.y /= b;	return a;} Pointmul(Point a, int b){	a.x *= b;	a.y *= b;	return a;} Rectanglersubp(Rectangle r, Point p){	r.min.x -= p.x;	r.min.y -= p.y;	r.max.x -= p.x;	r.max.y -= p.y;	return r;} Rectangleraddp(Rectangle r, Point p){	r.min.x += p.x;	r.min.y += p.y;	r.max.x += p.x;	r.max.y += p.y;	return r;} Rectanglermul(Rectangle r, int a){	if (a != 1) {		r.min.x *= a;		r.min.y *= a;		r.max.x *= a;		r.max.y *= a;	}	return r;} Rectanglerdiv(Rectangle r, int a){	if (a != 1) {		r.min.x /= a;		r.min.y /= a;		r.max.x /= a;		r.max.y /= a;	}	return r;} Rectanglershift(Rectangle r, int a){	if (a > 0) {		r.min.x <<= a;		r.min.y <<= a;		r.max.x <<= a;		r.max.y <<= a;	}	else if (a < 0) {		a = -a;		r.min.x >>= a;		r.min.y >>= a;		r.max.x >>= a;		r.max.y >>= a;	}	return r;} inteqpt(Point p, Point q){	return p.x==q.x && p.y==q.y;} inteqrect(Rectangle r, Rectangle s){	return r.min.x==s.min.x && r.max.x==s.max.x &&	       r.min.y==s.min.y && r.max.y==s.max.y;} intrectXrect(Rectangle r, Rectangle s){	return r.min.x<s.max.x && s.min.x<r.max.x &&	       r.min.y<s.max.y && s.min.y<r.max.y;} intrectinrect(Rectangle r, Rectangle s){	return s.min.x<=r.min.x && r.max.x<=s.max.x && s.min.y<=r.min.y && r.max.y<=s.max.y;} intptinrect(Point p, Rectangle r){	return p.x>=r.min.x && p.x<r.max.x &&	       p.y>=r.min.y && p.y<r.max.y;} Rectanglercanon(Rectangle r){	int t;	if (r.max.x < r.min.x) {		t = r.min.x;		r.min.x = r.max.x;		r.max.x = t;	}	if (r.max.y < r.min.y) {		t = r.min.y;		r.min.y = r.max.y;		r.max.y = t;	}	return r;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t