[SOLVED] Why is constructor for Rectangle using Points?

I have a question that might be a bit silly, but why is the constructor for Rectangle class taking Point for size and location, rather than Vector2?

This is not a big issue, but rather inconvenient, considering that e.g. mouse position or positions for drawing strings etc. are Vector2.

Of course if I want to draw a string at the same position as a rectangle, or draw a rectangle at mouse position, I can use the ToVector2 or ToPoint methods to convert, but I am wondering as to why this would be a thing? I guess I just can’t see the POINT ba-dum-tssss!

2 Likes

Rectangle coordinates are integers instead of floats, so it makes sense that it takes Point (an x and y integer) instead of Vector2 (x and y floats). Rectangle is defined with integers because that’s how it is in XNA. They made that decision and now we’re stuck with it for compatibility reasons, even though in some cases it makes more sense to support a rectangle defined with floats.

1 Like

+1 for the pun :slight_smile: :wink:

2 Likes

Thanks a lot for the reply. Yeah, your explanation with floats and ints makes perfect sense, but as I thought in the end it boils down to “this is how it was in XNA”. It’s alright though, it really is a minor issue.

Anyways, good to know! Solved!

1 Like