Monogame: Why Rectangle and Point don't accept flaot

Created on 4 Oct 2016  路  7Comments  路  Source: MonoGame/MonoGame

Hi
I'm a young french developer and I have an ideas why the Rectangle and the Point don't accept the float value. the float value is better ;)

If you want I code the class
If you don't accept I have an question I can create this class for my project ?

Your work is good continue ;)

Feature Request

Most helpful comment

Hihi, I know this has been untouched for a month but -

Honestly I'd like to see a RectangleF. Maybe not for sprites, but for GUI/HUD positioning it would be fantastic in the case of setting up windows for multiple aspect ratios/resolutions.

I like to normalize my GUI so it treats the entire screen as (0, 0) to (1, 1), allowing me to properly anchor/resize windows based on the virtual (and/or physical) screen size. The problem is that I can't just use Rectangle since all my windows' dimensions/positions are 0 < value < 1.

It's not a huge problem for me to build my own RectangleF and just carry it with me, but it'd be nice to have it included in the MonoGame library.

All 7 comments

It has come up before in XNA... why is there no RectangleF like type which works with Vector2?

I've seen other engines and extensions on MonoGame have added their own implementations of RectangleF. So adding our own risks the possibility of conflicts that would require some fixes by the user.

Should we consider it?

Is there a better name than RectangleF that matches better with Vector2?

I'm not familiar with how MonoGame handles Rectangles under the hood, but should you really add another class? Is adding a Rectangle(float x, float y, float width, float height) overload to the Rectangle constructor possible? Or is there some specific code there that requires/limits the usage to int only?

@energyuser Well, since all properties on Rectangle are ints, it doesn't really make sense to have a Rectangle(float x, float y, float width, float height) constructor, if all you're doing is casting the floats to int. I've personally never had the need for a RectangleF structure, as I always cast floats to int when using Rectangles or simply avoid float altogether when positioning sprites. Not sure why SpriteBatch works with both float and int depending on the overload, but that's how Microsoft implemented it.

@tomspilman To be honest, if users have created their own Rectanglef, they shouldnt have done so in the library's namespace. And if they didn't they can just change their Rectanglef functions to extension methods if monogame releases Rectanglef.

Hihi, I know this has been untouched for a month but -

Honestly I'd like to see a RectangleF. Maybe not for sprites, but for GUI/HUD positioning it would be fantastic in the case of setting up windows for multiple aspect ratios/resolutions.

I like to normalize my GUI so it treats the entire screen as (0, 0) to (1, 1), allowing me to properly anchor/resize windows based on the virtual (and/or physical) screen size. The problem is that I can't just use Rectangle since all my windows' dimensions/positions are 0 < value < 1.

It's not a huge problem for me to build my own RectangleF and just carry it with me, but it'd be nice to have it included in the MonoGame library.

You can always use BoundingBox, I guess?

If you use MonoGame.Extended, you have access to RectangleF.

Was this page helpful?
0 / 5 - 0 ratings