// Determines what portion of rect, if any, is unoccluded (not occluded by region). If // the resulting unoccluded region is not rectangular, we return a rect containing it. static inline IntRect rectSubtractRegion(const IntRect& rect, const Region& region) { Region rectRegion(rect); Region intersectRegion(intersect(region, rectRegion)); if (intersectRegion.isEmpty()) return rect; rectRegion.subtract(intersectRegion); IntRect boundsRect = rectRegion.bounds(); return boundsRect; }
// Determines what portion of rect, if any, is visible (not occluded by region). If // the resulting visible region is not rectangular, we just return the original rect. static IntRect rectSubtractRegion(const Region& region, const IntRect& rect) { Region rectRegion(rect); Region intersectRegion(intersect(region, rectRegion)); if (intersectRegion.isEmpty()) return rect; // Test if intersectRegion = rectRegion, if so return empty rect. rectRegion.subtract(intersectRegion); IntRect boundsRect = rectRegion.bounds(); if (boundsRect.isEmpty()) return boundsRect; // Test if rectRegion is still a rectangle. If it is, it will be identical to its bounds. Region boundsRegion(boundsRect); boundsRegion.subtract(rectRegion); if (boundsRegion.isEmpty()) return boundsRect; return rect; }