void PageBoundary::drawClipped ( Canvas* c, Coord l, Coord b, Coord r, Coord t, Graphic* gs ) { Coord x0, y0, x1, y1, x2, y2; BoxObj clipBox(l, b, r, t); transform(0, 0, x0, y0, gs); transform(border, pageheight, x1, y1, gs); transform(pagewidth, border, x2, y2, gs); BoxObj lbox(x0, y0, x1, y1); BoxObj bbox(x0, y0, x2, y2); transform(pagewidth - border, 0, x0, y0, gs); transform(0, pageheight - border, x1, y1, gs); transform(pagewidth, pageheight, x2, y2, gs); BoxObj rbox(x0, y0, x2, y2); BoxObj tbox(x1, y1, x2, y2); update(gs); if (lbox.Intersects(clipBox)) { pFillRect(c, 0, 0, border, pageheight); } if (bbox.Intersects(clipBox)) { pFillRect(c, 0, 0, pagewidth, border); } if (rbox.Intersects(clipBox)) { pFillRect(c, pagewidth - border, 0, pagewidth, pageheight); } if (tbox.Intersects(clipBox)) { pFillRect(c, 0, pageheight - border, pagewidth, pageheight); } }
boolean BoxObj::Intersects (LineObj& l) { Coord x1 = min(l._p1._x, l._p2._x); Coord x2 = max(l._p1._x, l._p2._x); Coord y1 = min(l._p1._y, l._p2._y); Coord y2 = max(l._p1._y, l._p2._y); BoxObj lbox(x1, y1, x2, y2); boolean intersects = false; if (Intersects(lbox)) { intersects = Contains(l._p1) || Contains(l._p2); if (!intersects) { LineObj l0 (_left, _bottom, _right, _bottom); LineObj l1 (_right, _bottom, _right, _top); LineObj l2 (_right, _top, _left, _top); LineObj l3 (_left, _top, _left, _bottom); intersects = l.Intersects(l0) || l.Intersects(l1) || l.Intersects(l2) || l.Intersects(l3); } } return intersects; }