diff --git a/include/cinolib/bresenham.cpp b/include/cinolib/bresenham.cpp index 7caa4ca0..3f2bf123 100644 --- a/include/cinolib/bresenham.cpp +++ b/include/cinolib/bresenham.cpp @@ -34,6 +34,7 @@ * Italy * *********************************************************************************/ #include +#include namespace cinolib { @@ -43,16 +44,24 @@ std::vector> bresenham_line(int x0, int y0, int x1, int y1) { std::vector> line; - bool steep = std::abs(y1 - y0) > std::abs(x1 - x0); - if (steep) { std::swap(x0,y0); std::swap(x1,y1); } + bool steep = std::abs(y1-y0) > std::abs(x1-x0); + if(steep) + { + std::swap(x0,y0); + std::swap(x1,y1); + } - bool reverse = (x0 > x1); - if (reverse) { std::swap(x0,x1); std::swap(y0,y1); } + bool reverse = (x0>x1); + if(reverse) + { + std::swap(x0,x1); + std::swap(y0,y1); + } int delta_x = x1 - x0; - int delta_y = std::abs(y1 - y0); - int error = delta_x / 2; - int y_step = (y0 < y1) ? 1 : -1; + int delta_y = std::abs(y1-y0); + int error = delta_x/2; + int y_step = (y0> bresenham_line(int x0, int y0, int x1, int y1) line.push_back(steep ? std::make_pair(y,x) : std::make_pair(x,y)); error -= delta_y; - if (error < 0) + if(error < 0) { y += y_step; error += delta_x; } } - if (reverse) std::reverse(line.begin(), line.end()); + if(reverse) std::reverse(line.begin(), line.end()); return line; } @@ -84,7 +93,7 @@ std::vector> bresenham_circle(int cx, int cy, int radius) int diag_inc = 10 - 4*radius; int right_inc = 6; - while(x <= y) + while(x<=y) { circle.push_back(std::make_pair( x+cx, y+cy)); circle.push_back(std::make_pair( x+cx, -y+cy)); @@ -95,7 +104,7 @@ std::vector> bresenham_circle(int cx, int cy, int radius) circle.push_back(std::make_pair(-y+cx, x+cy)); circle.push_back(std::make_pair(-y+cx, -x+cy)); - if (g>=0) + if(g>=0) { g += diag_inc; diag_inc += 8;