rectclip.c 571 B

12345678910111213141516171819202122232425
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. int
  5. rectclip(Rectangle *rp, Rectangle b) /* first by reference, second by value */
  6. {
  7. Rectangle *bp = &b;
  8. /*
  9. * Expand rectXrect() in line for speed
  10. */
  11. if((rp->min.x<bp->max.x && bp->min.x<rp->max.x &&
  12. rp->min.y<bp->max.y && bp->min.y<rp->max.y)==0)
  13. return 0;
  14. /* They must overlap */
  15. if(rp->min.x < bp->min.x)
  16. rp->min.x = bp->min.x;
  17. if(rp->min.y < bp->min.y)
  18. rp->min.y = bp->min.y;
  19. if(rp->max.x > bp->max.x)
  20. rp->max.x = bp->max.x;
  21. if(rp->max.y > bp->max.y)
  22. rp->max.y = bp->max.y;
  23. return 1;
  24. }