views:

61

answers:

3

I am drawing some graphs using the Point object and I want to set it so it supports doubles as its parameters. I am working on Visual C#, WindowsConsoleApplication

Thank you.

+1  A: 

The built-in Point structure uses int, and PointF uses float, but you can make your own that uses double.

Matthew Flaschen
And translate it back to the built-in Point when needed.
Steven
Nitpick: it's a structure, not a class. It's also mutable, which IMO the OP should avoid if he creates his own...
Jon Skeet
Thanks @Jon, fixed now.
Matthew Flaschen
+5  A: 

You can just use PointF. All System.Drawing support floating point operations. Why not use those? Otherwise, if you really want to use doubles and pass them to integer drawing functions, you will need to create your own structure. Something to this effect:

struct MyPoint {
 public double X{get;set;}
 public double Y{get;set;}

 public MyPoint(double x, double y) {
   X = x;
   Y = y;
 }

 public implicit operator Point() {
  return new Point(X, Y);
 }
}

This is a very truncated implementation, if you have a look at the source metadata of Point (by going to definition), you will see all the overrides and operators you need to implement.

Also, as a point of interest, you might notice that Point can implicitly convert to PointF, but not the other way around. This is not supported due to potential loss of precision. If I were you, I would rethink the design, as it seems to go against API designers' best use practices.

Igor Zevaka
A: 

No, it is not possible to overload point object.

Point is basically structure so it is not supporting overloading.

It is better you create your own class behaves same as point.

Hope this will help!

Jinal Desai - LIVE