struct Point
{
Point()
{
posx = 0;
posy = 0;
}
Point(int x, int y)
{
posx = x;
posy = y;
}
int posx;
int posy;
};

void bresenham(int x1, int y1, int x2, int y2, vector<Point>& path)
{
path.clear();
int dx = abs(x2 - x1);
int dy = abs(y2 - y1);

int inc_x = (x2 > x1) ? 1 : -1;
int inc_y = (y2 > y1) ? 1 : -1;

int eps = 0;

Point pos(x1, y1);
path.push_back(pos);

int x = x1;
int y = y1;
if(dx > dy)
{
for(x = x1; x != x2; x += inc_x)
eps += dy;
if((eps << 1) >= dx)
{
y += inc_y;
eps -= dx;
}
pos.posx = x;
pos.posy = y;
path.push_back(pos);
}
}
else
{
for(y = y1; y != y2; y+= inc_y)
{
eps += dx;
if((eps << 1) >= dy)
{
x += inc_x;
eps -= dy;
}
pos.posx = x;
pos.posy = y;
path.push_back(pos);
}
}

pos.posx = x;
pos.posy = y;

path.push_back(pos);
}

最新文章

  1. swift 的枚举、结构体、类
  2. Hadoop学习笔记—12.MapReduce中的常见算法
  3. [转]PowerDesigner设置集锦
  4. EF架构~基于EF数据层的实现
  5. ACM spiral grid
  6. Nginx学习记录
  7. [转]Hibernate不能自动建表解决办法及Hibernate不同数据库的连接及SQL方言
  8. Qt之事件系统
  9. 【转】一道SQL SERVER DateTime的试题
  10. Docker搭建MySQL服务
  11. Emoji表情符号兼容方案(适用ios,android,wp等平台)
  12. SNA社交网络算法
  13. asp.net textbox keyup事件触发后台的textchange事件
  14. android AsyncTask介绍 转载
  15. 第4章 同步控制 Synchronization ----死锁(DeadLock)
  16. django之快速分页
  17. this.$router.push、replace、go的区别
  18. Nginx 参数配置相关
  19. kali linux 64bit 2019.1a下启动bbqsql:No module named coros
  20. 51nod 1069 Nim游戏 + BZOJ 1022: [SHOI2008]小约翰的游戏John(Nim游戏和Anti-Nim游戏)

热门文章

  1. UVa LA 4254 - Processor 二分,贪心 难度: 1
  2. vuex-getter
  3. linux基本网络配置
  4. java中的线程问题是(四)——线程同步问题
  5. 【IDEA&amp;&amp;Eclipse】1、为何 IntelliJ IDEA 比 Eclipse 更适合于专业java开发者
  6. list的相关函数
  7. 清除微信小程序的缓存
  8. 官网下载MySQL最新版本的安装包
  9. contos防爆力破解密码
  10. spark on yarn运行产生jar包冲突问题