void LayoutRect::uniteEvenIfEmpty(const LayoutRect& other) { LayoutPoint newLocation(std::min(x(), other.x()), std::min(y(), other.y())); LayoutPoint newMaxPoint(std::max(maxX(), other.maxX()), std::max(maxY(), other.maxY())); m_location = newLocation; m_size = newMaxPoint - newLocation; }
void LayoutRect::intersect(const LayoutRect& other) { LayoutPoint newLocation(std::max(x(), other.x()), std::max(y(), other.y())); LayoutPoint newMaxPoint(std::min(maxX(), other.maxX()), std::min(maxY(), other.maxY())); // Return a clean empty rectangle for non-intersecting cases. if (newLocation.x() >= newMaxPoint.x() || newLocation.y() >= newMaxPoint.y()) { newLocation = LayoutPoint(0, 0); newMaxPoint = LayoutPoint(0, 0); } m_location = newLocation; m_size = newMaxPoint - newLocation; }
bool LayoutRect::inclusiveIntersect(const LayoutRect& other) { LayoutPoint newLocation(std::max(x(), other.x()), std::max(y(), other.y())); LayoutPoint newMaxPoint(std::min(maxX(), other.maxX()), std::min(maxY(), other.maxY())); if (newLocation.x() > newMaxPoint.x() || newLocation.y() > newMaxPoint.y()) { *this = LayoutRect(); return false; } m_location = newLocation; m_size = newMaxPoint - newLocation; return true; }
void LayoutRect::uniteIfNonZero(const LayoutRect& other) { // Handle empty special cases first. if (!other.width() && !other.height()) return; if (!width() && !height()) { *this = other; return; } LayoutPoint newLocation(std::min(x(), other.x()), std::min(y(), other.y())); LayoutPoint newMaxPoint(std::max(maxX(), other.maxX()), std::max(maxY(), other.maxY())); m_location = newLocation; m_size = newMaxPoint - newLocation; }
void LayoutRect::unite(const LayoutRect& other) { // Handle empty special cases first. if (other.isEmpty()) return; if (isEmpty()) { *this = other; return; } LayoutPoint newLocation(std::min(x(), other.x()), std::min(y(), other.y())); LayoutPoint newMaxPoint(std::max(maxX(), other.maxX()), std::max(maxY(), other.maxY())); m_location = newLocation; m_size = newMaxPoint - newLocation; }