Can we overload the Point object in C # so that it supports doubling?
You can just use PointF
. All System.Drawing
support floating point operations. Why not use them? Otherwise, if you really want to use double
and pass them to entire drawing functions, you will need to create your own structure. Something like this:
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 stripped down implementation, if you look at the original metadata Point
(going down to the definition) you can see all the overrides and operators you need to implement.
Also, as a point of interest, you may notice that it Point
can implicitly convert to PointF
, but not vice versa. This is not supported due to the potential loss of precision. If I were you, I would revisit the design as it seems to go against the best practices of API designers.
a source to share