是否可以为裁剪器路径提供浮动值

Is that possible to give floating values to the clipper Paths

Clipper 采用整数输入,但我想传递浮点值而不丢失精度。 整数和双精度值的 Clipper 结构。

struct IntPoint {
  cInt X;
  cInt Y;
#ifdef use_xyz
  cInt Z;
  IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {};
#else
  IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {};
#endif

  friend inline bool operator== (const IntPoint& a, const IntPoint& b)
  {
    return a.X == b.X && a.Y == b.Y;
  }
  friend inline bool operator!= (const IntPoint& a, const IntPoint& b)
  {
    return a.X != b.X  || a.Y != b.Y; 
  }
};

struct DoublePoint
{
  double X;
  double Y;
  DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
  DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
};

为什么不将双精度值作为输入。

Paths Polygon(2);
Polygon[0] << IntPoint(10, 10) << IntPoint(60, 10) << IntPoint(30, 100) ;
Polygon[1] << IntPoint(20, 20) << IntPoint(50, 20) << IntPoint(30, 80)  ; //it Works



Paths Line(1);
    line[0] << DoublePoint(40.2, 10.2) << DoublePoint(56.5, 85.45); //Not works

Clipper 仅使用 integer point types

The IntPoint structure is used to represent all vertices in the Clipper Library. An integer storage type has been deliberately chosen to preserve numerical robustness. (Early versions of the library used floating point coordinates, but it became apparent that floating point imprecision would always cause occasional errors.) [src]

但是,您可以根据需要的系数缩放输入坐标。

所以与其想要这个(它不存在)

line[0] << DoublePoint(40.2, 10.2) << DoublePoint(56.5, 85.45); //Not works

您可以缩放 100。

line[0] << IntPoint(4020, 1020) << IntPoint(5650, 8545); //works

请记住将输出坐标缩放 0.01 以返回到您的坐标系。