好吧,如果float
精度足够,那么您可以使用PointF
struct:
var point = new PointF(3.5f, 7.9f);
如果你真的需要,你可以定义你自己的PointD
结构:
public struct PointD {
public double X;
public double Y;
public PointD(double x, double y) {
X = x;
Y = y;
}
public Point ToPoint() {
return new Point((int)X, (int)Y);
}
public override bool Equals(object obj) {
return obj is PointD && this == (PointD)obj;
}
public override int GetHashCode() {
return X.GetHashCode() ^ Y.GetHashCode();
}
public static bool operator ==(PointD a, PointD b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(PointD a, PointD b) {
return !(a == b);
}
}
平等代码最初来自这里。
该ToPoint()
方法允许您将其转换为Point
对象,但当然精度会被截断。