예제 #1
0
int	main()
{
	auto	tmp = make_unique<Compute>(make_unique<ConsoleTokeniser>(),
							make_unique<ConsoleOutput>(),
							make_unique<NPI>());
	assert(tmp && "ERROR CREATING OBJECT");
	tmp->setDebug();
	std::string	data("1 1 +\n");
	for (auto it = data.rbegin(); it != data.rend(); ++it)
		std::cin.putback(*it);
	tmp->computeLine();
};
예제 #2
0
파일: vision.cpp 프로젝트: eandoe/kerl
/**
 * This is some of the big money.  This method will dynamically allocate masks
 * for circles rendered in grid.
 *
 * @param radius - The radius of the raster circle to be generated and added.
 */
vision::rastercircle vision::initRMask(int radius) {
	vision::rastercircle t;
	std::vector<coord> temp;
	int size = 4;
//BEGIN Midpoint circle algorithm.
	int f = 1 - radius;
	int ddF_x = 1;
	int ddF_y = -2 * radius;
	int x = 0;
	int y = radius;
	//calculated the number of points recursively
	while(x < y) {
		// ddF_x == 2 * x + 1;
		// ddF_y == -2 * y;
		// f == x*x + y*y - radius*radius + 2*x - y + 1;
		if(f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x;
		if(x != y) {
			size += 8;
		}
		else {
			size += 4;
		}
	}
//END Midpoint circle algorithm.

	//Create the array of coordinates
	for (int i = 0; i < size+4; ++i) {
		vision::coord tempc;
		tempc.x = 0.0;
		tempc.y = 0.0;
		tempc.z = 0.0;
		temp.push_back(tempc);
	}
//BEGIN Midpoint circle algorithm.
	f = 1 - radius;
	ddF_x = 1;
	ddF_y = -2 * radius;
	x = 0;
	y = radius;

	temp[0].x 			= radius; 	temp[0].y 			= 0; 		// 0
	temp[size/4].x 		= 0; 		temp[size/4].y 		= -radius; 	// Pi/2
	temp[size/2].x 		= -radius; 	temp[size/2].y 		= 0; 		// Pi
	temp[3*size/4].x 	= 0;		temp[3*size/4].y 	= radius; 	// 3Pi/2

	int it1 = 1;
	int it2 = size/4-1;
	int it3 = size/4+1;
	int it4 = size/2-1;
	int it5 = size/2+1;
	int it6 = 3*size/4-1;
	int it7 = 3*size/4+1;
	int it8 = size-1;
	while(x < y)
	{
		// ddF_x == 2 * x + 1;
		// ddF_y == -2 * y;
		// f == x*x + y*y - radius*radius + 2*x - y + 1;
		if(f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x;
		// 0 to 45
		temp[it1].x 	= y; 	temp[it1].y 	= -x;
		// 90 to 45
		temp[it2].x 	= x; 	temp[it2].y 	= -y;
		// 90 to 135
		temp[it3].x 	= -x; 	temp[it3].y 	= -y;
		// 180 to 135
		temp[it4].x 	= -y; 	temp[it4].y 	= -x;
		// 180 to 225
		temp[it5].x 	= -y;	temp[it5].y 	= x;
		// 270 to 225
		temp[it6].x 	= -x; 	temp[it6].y 	= y;
		// 270 to 315
		temp[it7].x 	= x; 	temp[it7].y 	= y;
		// 360 to 315
		temp[it8].x 	= y;	temp[it8].y 	= x;

		it1++; it3++; it5++; it7++;
		it2--; it4--; it6--; it8--;
	}
//END Midpoint circle algorithm.
	int max = ceil(sqrt(pow((double)radius, 2.0)/2.0));
	for(int i = 0; i < 4; i++) {
		temp[size+i].x = (i == 1 || i == 2) ? -max : max;
		temp[size+i].y = (i == 0 || i == 1) ? -max : max;
	}
	t.setMask(temp);

	display& disp = gamemanager::getDisplay();
	disp.printRaster(t);

	std::vector<std::vector<vision::coord> > lines;
	for(int i = 0; i < size; i++) {
		lines.push_back(computeLine(temp[i].x, temp[i].y));
		disp.printLine(temp[i].x, temp[i].y, lines[i]);
	}
	for(int i = 1; i <= 4; i++) {
		lines.push_back(getDiag(i, radius));
		disp.printLine(temp[size+i-1].x, temp[size+i-1].y, lines[size+i-1]);
	}

	t.setLines(lines);
	radiusmask.insert(std::make_pair(radius, t));
	return t;
}