Пример #1
0
bool Rectangle::isIntersection(const Rectangle& other) const
{
    Point lowerRightCorner = getLowerRightCorner();
    Point otherLowerRightCorner = other.getLowerRightCorner();

    return (other.upperLeftCorner.x < lowerRightCorner.x && other.upperLeftCorner.y < lowerRightCorner.y)
           && (otherLowerRightCorner.x > upperLeftCorner.x && otherLowerRightCorner.y > upperLeftCorner.y);
}
Пример #2
0
Rectangle Rectangle::combine(const Rectangle& other) const
{
    Point lowerRightCorner = getLowerRightCorner();
    Point otherLowerRightCorner = other.getLowerRightCorner();

    int x1 = std::min(upperLeftCorner.x, other.upperLeftCorner.x);
    int y1 = std::min(upperLeftCorner.y, other.upperLeftCorner.y);
    int x2 = std::max(lowerRightCorner.x, otherLowerRightCorner.x);
    int y2 = std::max(lowerRightCorner.y, otherLowerRightCorner.y);

    return Rectangle::fromCoordinates(x1, y1, x2, y2);
}
Пример #3
0
Rectangle Rectangle::intersect(const Rectangle& other) const
{
    if (isIntersection(other)) {
        Point lowerRightCorner = getLowerRightCorner();
        Point otherLowerRightCorner = other.getLowerRightCorner();

        int x1 = std::max(upperLeftCorner.x, other.upperLeftCorner.x);
        int y1 = std::max(upperLeftCorner.y, other.upperLeftCorner.y);
        int x2 = std::min(lowerRightCorner.x, otherLowerRightCorner.x);
        int y2 = std::min(lowerRightCorner.y, otherLowerRightCorner.y);

        return Rectangle::fromCoordinates(x1, y1, x2, y2);
    } else {
        return Rectangle::ZERO;
    }
}
Пример #4
0
LayoutRect ContainerNode::boundingBox() const
{
    FloatPoint upperLeft, lowerRight;
    bool foundUpperLeft = getUpperLeftCorner(upperLeft);
    bool foundLowerRight = getLowerRightCorner(lowerRight);
    
    // If we've found one corner, but not the other,
    // then we should just return a point at the corner that we did find.
    if (foundUpperLeft != foundLowerRight) {
        if (foundUpperLeft)
            lowerRight = upperLeft;
        else
            upperLeft = lowerRight;
    } 

    return enclosingLayoutRect(FloatRect(upperLeft, lowerRight.expandedTo(upperLeft) - upperLeft));
}