You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
1.6 KiB
C++

#pragma once
#include <iostream>
#include <vector>
#include <set>
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;
}
// 文楚<E69687>
Vector2d operator + (const Vector2d& v) const
{
return Vector2d(x + v.x, y + v.y);
}
// 文楚<E69687>
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;
}
//<2F>楚議庁
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; //<2F>殆海業
};
class VectorToRaster
{
public:
VectorToRaster(void);
~VectorToRaster(void);
void GetRasterLine(vector<int> ptsRow,vector<int> ptsCol,vector<int>& rowList,vector<int>& colList);
set<vector<int> > GetRasterLineEx(vector<int> ptsRow,vector<int> ptsCol,int row_max,int col_max,int tolerance=1);
private:
void RasterLine(std::pair<Vector2d, Vector2d> line, std::vector<Vector2d>& linePointList);
void ExtendGrid(int cx,int cy,int x_max,int y_max,int tolerance,set<vector<int> >& resultSet);
};