好吧,如果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);
}
}
平等代码最初从here。
ToPoint()
方法可让您将其转换为Point
对象,但当然精度会被截断。
是的,先生是多么愚蠢的是,didnt检查的PointF! – 2011-03-20 04:07:30
请参阅http://stackoverflow.com/a/5221407/380384以了解结构的正确'GetHashCode()'。 – ja72 2014-09-16 23:10:25