16 Rect(int x, int y, int bx, int by)
28 Rpt(Point min, Point max)
38 addpt(Point a, Point b)
46 subpt(Point a, Point b)
54 insetrect(Rectangle r, int n)
80 rectsubpt(Rectangle r, Point p)
90 rectaddpt(Rectangle r, Point p)
100 eqpt(Point p, Point q)
102 return p.x==q.x && p.y==q.y;
106 eqrect(Rectangle r, Rectangle s)
108 return r.min.x==s.min.x && r.max.x==s.max.x &&
109 r.min.y==s.min.y && r.max.y==s.max.y;
113 rectXrect(Rectangle r, Rectangle s)
115 return r.min.x<s.max.x && s.min.x<r.max.x &&
116 r.min.y<s.max.y && s.min.y<r.max.y;
120 rectinrect(Rectangle r, Rectangle s)
122 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;
126 ptinrect(Point p, Rectangle r)
128 return p.x>=r.min.x && p.x<r.max.x &&
129 p.y>=r.min.y && p.y<r.max.y;
133 canonrect(Rectangle r)
136 if (r.max.x < r.min.x) {
141 if (r.max.y < r.min.y) {
150 combinerect(Rectangle *r1, Rectangle r2)
152 if(r1->min.x > r2.min.x)
153 r1->min.x = r2.min.x;
154 if(r1->min.y > r2.min.y)
155 r1->min.y = r2.min.y;
156 if(r1->max.x < r2.max.x)
157 r1->max.x = r2.max.x;
158 if(r1->max.y < r2.max.y)
159 r1->max.y = r2.max.y;
170 int log2[] = { -1, 0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4, -1, -1, -1, -1, -1, -1, -1, 4 /* BUG */, -1, -1, -1, -1, -1, -1, -1, 5 };
173 setalpha(u32int color, uchar alpha)
175 int red, green, blue;
177 red = (color >> 3*8) & 0xFF;
178 green = (color >> 2*8) & 0xFF;
179 blue = (color >> 1*8) & 0xFF;
180 /* ignore incoming alpha */
181 red = (red * alpha)/255;
182 green = (green * alpha)/255;
183 blue = (blue * alpha)/255;
184 return (red<<3*8) | (green<<2*8) | (blue<<1*8) | (alpha<<0*8);
194 r = va_arg(f->args, Rectangle);
195 return fmtprint(f, "%P %P", r.min, r.max);
203 p = va_arg(f->args, Point);
204 return fmtprint(f, "[%d %d]", p.x, p.y);