Reputation: 6119
I'm using mapping in my application. So I have 2D point structures of int and double, which I need to manipulate. I have currently separated my solution into 2 projects/ assemblies. One has the core functionality. The other is for user interface. I'm currently using a WPF user interface. However I've tried to maximise the functionality of the core assembly, while trying to ensure that it will work with any C# user interface, e.g. forms, XNA a future API such as the Windows 8 Jupiter(Metro XAML) or on a Linux/ Mac Windows Phone etc.
I wish to manipulate these structures within my core functionality. I see that there are Point structures in System.Windows and System.Drawing. However I'm reluctant to use these as these seem to be tied to particular windows GUI APIs. Should I make my own structures even though this will be reimplementing much of the functionality from these existing structs? I see there is a maths class but no maths name-space with useful general purpose maths classes and structs.
Is the situation the same for 3d point structures?
Upvotes: 3
Views: 752
Reputation: 564861
Unfortunately, yes- the current Point (and Point3D) structures in the framework are tied to a particular platform.
Personally, I'd use the System.Windows
version of Point if you don't mind taking the dependency, as it's double precision (important for mapping) and fairly lightweight. There is also a Point3D if you decide you need a Z value.
If you don't want to take on the dependency, you'll have to roll your own.
That being said, at some point, if you want to support other platforms, you'll eventually have to create your own conversion routines anyways. XNA's point structures are all single-precision float, where WPF's are double precision, and GDI+ are mixed (sometimes integer values). As such, there is no single "right" way to manage a "coordinate" - and each framework has their own rules and structures - so converting will eventually be a requirement no matter what you choose.
Upvotes: 3