Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Should we include simpler casts between Vector structs and built-in C# structs?  (Read 5578 times)

0 Members and 1 Guest are viewing this topic.

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Given the one-to-one nature of the Vector classes and some built-in C# structs (e.g. Vector2f, SizeF, PointF), I think it would be sensible to include explicit casts to those classes. We could also consider extension methods (e.g. "ToVector2f") to make conversion from those structs to Vectors simpler. Thoughts?

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
That would create dependency for System.Drawing which is generally useless unless you are working with Winforms or WPF application.

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
My biggest issue with doing something like this is the question of where do we stop doing this? Because if we add vectors it also makes sense then to do rects and colors. There may even be more that I'm not thinking of at the moment (what about keyboard keys and mouse buttons?). And then there is the problem of lots of these CLR structures being duplicated for GDI+ and WPF.

System.Windows.Point
System.Drawing.Point
System.Drawing.PointF
System.Drawing.Rectangle
System.Windows.Rect
System.Drawing.Size
System.Windows.Size
System.Windows.Media.Color
System.Drawing.Color

Quote
I think it would be sensible to include explicit casts to those classes

Definitely would need to be explicit.

Quote
That would create dependency for System.Drawing which is generally useless unless you are working with Winforms or WPF application.

That is another thing, so instead of SFML.NET only depending on the core System.dll we would now be depending on multiple dependencies. That I'm sure 90% of the users don't use... to add to that fact: if we did this and added a dependency for System.Windows (WPF structures) then we will break the library on Mono and will also have to upgrade the framework we compile against (.NET 2.0 doesn't have WPF).

To be honest, these conversions to me really sound like a job for an extension library to SFML.NET (such as here) and not something we should include in the core. I mean, if we added support for these conversions - should SFML now support conversions from say GLM?
« Last Edit: March 09, 2015, 02:17:03 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Oof. Didn't realize this would cause an incompatibility with Mono... my familiarity with Mono doesn't extend far past the basics. That alone is probably a good enough argument to sink this ship, given that it would have a much greater effect on the library's users than a little added syntactic sugar. I can just as easily create a small, personal addendum to the SFML.Net code and compile my own copy from now on - especially since I'm doing that already for the explicit conversion between Vectors while you guys are finishing up the next release.

neckbeard

  • Newbie
  • *
  • Posts: 2
    • View Profile
My biggest issue with doing something like this is the question of where do we stop doing this? Because if we add vectors it also makes sense then to do rects and colors. There may even be more that I'm not thinking of at the moment (what about keyboard keys and mouse buttons?). And then there is the problem of lots of these CLR structures being duplicated for GDI+ and WPF.

Could limit to casts/conversions of internal SFML data classes. For an example the SFML mouse position is a Vector2i but all of the SFML Sprite/World positions are Vector2f.  Working between the two requires a bit of finagling.  Don't mind a bit of extra coding but.. simplicity wins out over verbosity. :)
« Last Edit: March 16, 2015, 03:57:06 pm by neckbeard »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
That's totally intended. Your world space does not have to match 1:1 to the window pixels (i.e. when you zoom in), as such you should use the mapPixelToCoords or mapCoordsToPixel functions.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Could limit to casts/conversions of internal SFML data classes. For an example the SFML mouse position is a Vector2i but all of the SFML Sprite/World positions are Vector2f.  Working between the two requires a bit of finagling.  Don't mind a bit of extra coding but.. simplicity wins out over verbosity. :)

As already said in the recent request thread and bug tracker issue this already exists.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Conduit

  • Newbie
  • *
  • Posts: 30
    • View Profile
Yeah - Vector conversion has been present in the source for a while now, apparently (see my post/bug ticket, linked above), but wasn't available unless you compiled the library yourself. The recent upload of v2.2 should include it, I believe - try downloading the new files, and check the SFML.System namespace. The casts must be explicit, but they're definitely working.
« Last Edit: March 16, 2015, 05:10:10 pm by Conduit »