aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/rectclip.c
blob: 2228628b8d09085e59913dae69fcf7b5bde55621 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <u.h>
#include <libc.h>
#include <draw.h>

int
rectclip(Rectangle *rp, Rectangle b)		/* first by reference, second by value */
{
	Rectangle *bp = &b;
	/*
	 * Expand rectXrect() in line for speed
	 */
	if((rp->min.x<bp->max.x && bp->min.x<rp->max.x &&
	    rp->min.y<bp->max.y && bp->min.y<rp->max.y)==0)
		return 0;
	/* They must overlap */
	if(rp->min.x < bp->min.x)
		rp->min.x = bp->min.x;
	if(rp->min.y < bp->min.y)
		rp->min.y = bp->min.y;
	if(rp->max.x > bp->max.x)
		rp->max.x = bp->max.x;
	if(rp->max.y > bp->max.y)
		rp->max.y = bp->max.y;
	return 1;
}