X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Frect.h;fp=src%2Frect.h;h=78c5a708665200477645b6f6f9df3f954553aca2;hp=018844696b5ef289280f7ed6f778deb59345216f;hb=f0b6c9b6b95fde134927c395afbfbbbc057868e6;hpb=6c0dfe752994312ee58d307b383948bfeb2d6e2e diff --git a/src/rect.h b/src/rect.h index 0188446..78c5a70 100644 --- a/src/rect.h +++ b/src/rect.h @@ -38,6 +38,11 @@ namespace IPDF if (y > other.y + other.h) return false; return true; } + + inline bool Contains(const TRect& other) const + { + return PointIn(other.x, other.y) && PointIn(other.x + other.w, other.y + other.h); + } template TRect Convert() const {return TRect(B(x), B(y), B(w), B(h));} @@ -49,6 +54,31 @@ namespace IPDF h = T(equ.h); return *this; } + + // Clips "other" to "this" + inline TRect Clip(const TRect& other) const + { + TRect clipped = other; + if (clipped.x < x) + { + clipped.w += clipped.x - x; + clipped.x = x; + } + if (clipped.y < y) + { + clipped.h += clipped.y - y; + clipped.y = 0; + } + if (clipped.x + clipped.w > x + w) + { + clipped.w += ((x + w) - (clipped.x + clipped.w)); + } + if (clipped.y + clipped.h > y + h) + { + clipped.h += ((y + h) - (clipped.y + clipped.h)); + } + return clipped; + } };