rectclip.c 556 B

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