[bug] getConstrainedPoint() returns inconsistent result

The doc for Rectangle::getConstrainedPoint() says:

Returns the nearest point to the specified point that lies within this rectangle.

but the following code shows that it is not the case if the point to be constrained is outside of the rectangle past its right edge or bottom edge.

    juce::Rectangle <int> rect (10, 10);

    const auto pointA = rect.getConstrainedPoint ({5, 20});
    const auto pointB = rect.getConstrainedPoint ({20, 5});

    /* these asserts are triggered because both contains() 
     return false instead of true */
    jassert (rect.contains (pointA));
    jassert (rect.contains (pointB));

The same happens if the rectangle is float instead of int

1 Like