#pragma once #include #include #include using namespace std; const double EPSILON = 0.000001; struct GridPoint { int row; int col; }; struct Vector2d { public: Vector2d() { //EPSILON = dEPSILON; } Vector2d(double dx, double dy) { x = dx; y = dy; //EPSILON = dEPSILON; } // 矢量赋值 void set(double dx, double dy) { x = dx; y = dy; } // 矢量相加 Vector2d operator + (const Vector2d& v) const { return Vector2d(x + v.x, y + v.y); } // 矢量相减 Vector2d operator - (const Vector2d& v) const { return Vector2d(x - v.x, y - v.y); } //矢量数乘 Vector2d Scalar(double c) const { return Vector2d(c*x, c*y); } // 矢量点积 double Dot(const Vector2d& v) const { return x * v.x + y * v.y; } //向量的模 double Mod() const { return sqrt(x * x + y * y); } bool Equel(const Vector2d& v) const { if (abs(x - v.x) < EPSILON && abs(y - v.y) < EPSILON) { return true; } return false; } double x, y; //double EPSILON; //像素长度 }; class VectorToRaster { public: VectorToRaster(void); ~VectorToRaster(void); void GetRasterLine(vector ptsRow,vector ptsCol,vector& rowList,vector& colList); set > GetRasterLineEx(vector ptsRow,vector ptsCol,int row_max,int col_max,int tolerance=1); private: void RasterLine(std::pair line, std::vector& linePointList); void ExtendGrid(int cx,int cy,int x_max,int y_max,int tolerance,set >& resultSet); };