Пример #1
0
// static
Rect2f Rect2f::united( const Rect2f& r0, const Rect2f& r1 )
{
    assert( r0.isStandard() && r1.isStandard() );

    Vector2f r0Min = r0.leftBottom();
    Vector2f r0Max = r0.rightTop();
    Vector2f r1Min = r1.leftBottom();
    Vector2f r1Max = r1.rightTop();

    Vector2f unitedMin{ std::min( r0Min.x, r1Min.x ), std::min( r0Min.y, r1Min.y ) };
    Vector2f unitedMax{ std::max( r0Max.x, r1Max.x ), std::max( r0Max.y, r1Max.y ) };

    return Rect2f( unitedMin, unitedMax - unitedMin );
}
Пример #2
0
// static
bool Rect2f::intersect( const Rect2f& r0, const Rect2f& r1, Rect2f& intersection )
{
    assert( r0.isStandard() && r1.isStandard() );

    Vector2f minimum = libcgt::core::math::maximum( r0.minimum(), r1.minimum() );
    Vector2f maximum = libcgt::core::math::minimum( r0.maximum(), r1.maximum() );

    if( minimum.x < maximum.x &&
        minimum.y < maximum.y )
    {
        intersection.origin = minimum;
        intersection.size = maximum - minimum;
        return true;
    }
    return false;
}
Пример #3
0
Vector2f clamp( const Vector2f& v, const Rect2f& rect )
{
    assert( rect.isStandard() );
    return
    {
        clampToRangeInclusive( v.x, rect.left(), rect.right() ),
        clampToRangeInclusive( v.y, rect.bottom(), rect.top() )
    };
}