#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;
	}

	// 文楚�紗
	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<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);
};