0

Clipper takes integer input but I want to pass floating values without losing the precision. Clipper struct for Integer and double value.

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) {}
};

why it is not taking the double value as an input.

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
4

1 回答 1

3

Clipper 只使用整数点类型

IntPoint 结构用于表示 Clipper Library 中的所有顶点。故意选择整数存储类型以保持数值稳健性。(该库的早期版本使用浮点坐标,但很明显浮点不精确总会导致偶尔出现错误。)[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 以返回到您的坐标系。

于 2019-10-14T10:02:06.163 回答