chrisdill / raylib-cs

C# bindings for raylib, a simple and easy-to-use library to learn videogames programming

Home Page:http://www.raylib.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Replace Raylib.Rectangle with System.Rectangle

MrScautHD opened this issue · comments

Before submitting a new issue, please verify and check:

  • The issue is specific to Raylib-cs and not raylib
  • I checked there is no similar issue already reported
  • My code has no errors or misuse of Raylib-cs

Issue description

Hello!
What you think about by removing the Rectangle struct, because C# has already a own class for it.

Let me know what you think about it, i can do the PR for it :)

PS: It has exact the same functions (even a few more)

Using an existing class sounds good however System.Drawing is not cross platform.
https://learn.microsoft.com/en-us/dotnet/api/system.drawing?view=net-7.0

Read this text:

Some types in the System.Drawing namespace rely on GDI+, which is not supported in Windows services and ASP.NET Core and ASP.NET apps. These types are in the System.Drawing.Common NuGet package and include System.Drawing.Bitmap and System.Drawing.Font. However, primitive types in the namespace, such as System.Drawing.Color, System.Drawing.Size, System.Drawing.Point, and System.Drawing.Rectangle, can be used in any application.

primitive types in the namespace, such as System.Drawing.Color, System.Drawing.Size, System.Drawing.Point, and System.Drawing.Rectangle, can be used in any application.

The types could be used but it means users need to be aware of what features of System.Drawing they can safely use. I would rather try to have features of the library work the same across platforms as best I can.

well ok! Btw do you have dc?

I think even Vector2 should get replaced with Size... but what ever it is your lib :/

I saw, you need to impliment a special LIB for using the other stuff.

If you give me the ok, i can do it! :)

Not sure what you are asking. By special lib do you mean System.Numerics?

I like it!

The types could be used but it means users need to be aware of what features of System.Drawing they can safely use. I would rather try to have features of the library work the same across platforms as best I can.

If you want the features that not cross platform supported you need to go on Nuget and Download it, so i think it is fine then to use size, Rec...

Could possibly get it to work with the types but I don't see enough benefit to taking on the dependency at this stage. I might reconsider in the future when making other breaking changes but for now I think the focus should be making the current types easier to use.

Could possibly get it to work with the types but I don't see enough benefit to taking on the dependency at this stage. I might reconsider in the future when making other breaking changes but for now I think the focus should be making the current types easier to use.

I mean, using Vector2 for a int Size is very bad...

What do you mean exactly? Vector2 is used to match the same type raylib uses...

well, ok...

but does they get casted then to int?

(so is it really working as a float?)

I vote against this, sorry - the original RL has floats for Rectangle, and we should keep as close to upstream as possible.

That said, there is RectangleF, which can even take a Vector4 as input, and doing an implicit conversion to the current Rectangle shouldn't cause any issues.

I vote against this, sorry - the original RL has floats for Rectangle, and we should keep as close to upstream as possible.

That said, there is RectangleF, which can even take a Vector4 as input, and doing an implicit conversion to the current Rectangle shouldn't cause any issues.

I agree, I think System.Drawing.RectangleF would be the ideal alternative to Raylib_cs.Rectangle. I personally would prefer it as well. The main issue I can potentially see being problematic is the naming mismatch.

Also worth noting that is has a handy implicit operator so you can pass System.Drawing.Rectangle into a method with param type RectangleF and it should work just fine.

but does they get casted then to int?

(so is it really working as a float?)

When calling DrawRectanglePro the rect coordinates are used to set vertex positions (as floats) so floating values are the most sensible approach.

https://github.com/raysan5/raylib/blob/32b54be5cbd9eb77fc36a4c044dce69c5640a26a/src/rshapes.c#L798-L808

but does they get casted then to int?
(so is it really working as a float?)

When calling DrawRectanglePro the rect coordinates are used to set vertex positions (as floats) so floating values are the most sensible approach.

https://github.com/raysan5/raylib/blob/32b54be5cbd9eb77fc36a4c044dce69c5640a26a/src/rshapes.c#L798-L808

To be fair, int to float is implicit, a float can represent any int - it's the other way you need to worry about.

So lets do a vote

Who is for it that reacts with 👍

If you not for it react with 👎

Well you guys won then!