修复只有一条线的bug
							parent
							
								
									9b753769b1
								
							
						
					
					
						commit
						8d51a6f1f3
					
				| 
						 | 
					@ -26,13 +26,14 @@ void line(int x0, int y0, int x1, int y1, TGAImage& image, TGAColor color) {
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (steep) 
 | 
							if (steep) 
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			image.set(x, y, color);
 | 
								image.set(y, x, color);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			image.set(x, y, color);
 | 
								image.set(x, y, color);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		error2 += derror2;
 | 
							error2 += derror2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (error2 > dx) // 误差值,提供从当前位置到最佳直线的距离
 | 
							if (error2 > dx) // 误差值,提供从当前位置到最佳直线的距离
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			y += (y1 > y0 ? 1 : -1);
 | 
								y += (y1 > y0 ? 1 : -1);
 | 
				
			||||||
| 
						 | 
					@ -44,7 +45,13 @@ void line(int x0, int y0, int x1, int y1, TGAImage& image, TGAColor color) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char** argv) {
 | 
					int main(int argc, char** argv) {
 | 
				
			||||||
	TGAImage image(100, 100, TGAImage::RGB);
 | 
						TGAImage image(100, 100, TGAImage::RGB);
 | 
				
			||||||
	line(52, 41,90,70,image ,red);
 | 
						for (int i = 0; i < 1000000; i++)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							line(13, 20, 80, 40, image, white);
 | 
				
			||||||
 | 
							line(20, 13, 40, 80, image, red);
 | 
				
			||||||
 | 
							line(80, 40, 13, 20, image, red);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
 | 
						image.flip_vertically(); // i want to have the origin at the left bottom corner of the image
 | 
				
			||||||
	image.write_tga_file("output.tga");
 | 
						image.write_tga_file("output.tga");
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue