Rect.Contains(new Vector2(Rect.xMax, Rect.yMax)) returns false?

I’m not sure if I misunderstood something, but consider this test:

Rect tstRct = new Rect(1, 1, 3, 4);
Debug.Log("Test rect (x, y, xMax, yMax): " + tstRct.xMin + ", " + tstRct.yMin + ", " + tstRct.xMax + ", " + tstRct.yMax);
Vector2 tstVec0 = new Vector2(0, 0);
Vector2 tstVec1 = new Vector2(1, 1);
Vector2 tstVec2 = new Vector2(2, 2);
Vector3 tstVec3 = new Vector2(3, 3);
Vector3 tstVec4 = new Vector2(4, 4);
Vector3 tstVec5 = new Vector2(3, 5);
Debug.Log("Vec0 in Rect: " + tstRct.Contains(tstVec0));
Debug.Log("Vec1 in Rect: " + tstRct.Contains(tstVec1));
Debug.Log("Vec2 in Rect: " + tstRct.Contains(tstVec2));
Debug.Log("Vec3 in Rect: " + tstRct.Contains(tstVec3));
Debug.Log("Vec4 in Rect: " + tstRct.Contains(tstVec4));
Debug.Log("Vec5 in Rect: " + tstRct.Contains(tstVec5));
Debug.Log("Vec contains Vector2(xMax, yMax): " + tstRct.Contains(new Vector2(tstRct.xMax, tstRct.yMax)));

The last line is testing if a rectangle contains it’s own (xMax, yMax) in it. Shouldn’t it return true? Since it is its maximum values afterall… Instead I get these results in Unity debug log:

Test rect (x, y, xMax, yMax): 1, 1, 4, 5
Vec0 in Rect: False
Vec1 in Rect: True
Vec2 in Rect: True
Vec3 in Rect: True
Vec4 in Rect: False
Vec5 in Rect: False
Vec contains Vector2(xMax, yMax): False

To make it easier to think about. Here is a graphical representation of the rectangle with a few extra markings:

Each square represents a pixel and coordinates are marked on the sides. Green area represents area of the rectangle and red numbers within the grid correspond numbers in Vector2 objects used by the test (0-5). Red square marks the coordinates of (xMax, yMax). I guess my question is… Why are xMax and yMax values outside the rectangle? Shouldn’t xMax in this case be 3 and yMax 4? If it’s like this by design, could someone help me understand why?

1187118--46332--$RectMaxValues.png

my random thoughts:
i guess the max and min values mark the “borders”.
The implementation for contains seems to be like
value >min value=min and value <=max
i dont know why though.
i guess it’s because the values are floats(ValueX(3.999999) is still inside Xmax(4.0)).

yeah min value is inside, max value is outside

My initial thought was that max and min methods might return the “borders” too, but min seems to be within the rectangle (at 1,1 in this test) but max isn’t (it’s at 4,5 instead of 3,4).

As you said, implementation for contains seems not to be (value >= min value <= max)
but it doesn’t seem to be (value > min value < max) either
rather, it seems to be (value >= min value <= max - 1) which is ok considering I think it’s the max values that are off by 1.

Why the inconsistency between min and max methods?

I don’t believe it’s about being float either. Float precision shouldn’t be inaccurate to the point of being a whole 1.0f off. My conclusion so far is that min and max methods are just inconsistent, but why? They are both methods that are supposed to serve somewhat similar purpose. I still think I might be missing something here, but I’d just like to know what that is.

I’m not sure if this is a bug or a “feature” but I’ve reported this through “Help > Report a Bug” menu in Unity. Hope there’ll be a fix for consistency in the future.