Algorithm for drawing line between two points http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
(x0, y0, x1, y1 int, plot func(int, int))
| 290 | // |
| 291 | // http://en.wikipedia.org/wiki/Bresenham's_line_algorithm |
| 292 | func drawLine(x0, y0, x1, y1 int, plot func(int, int)) { |
| 293 | dx := x1 - x0 |
| 294 | if dx < 0 { |
| 295 | dx = -dx |
| 296 | } |
| 297 | dy := y1 - y0 |
| 298 | if dy < 0 { |
| 299 | dy = -dy |
| 300 | } |
| 301 | var sx, sy int |
| 302 | if x0 < x1 { |
| 303 | sx = 1 |
| 304 | } else { |
| 305 | sx = -1 |
| 306 | } |
| 307 | if y0 < y1 { |
| 308 | sy = 1 |
| 309 | } else { |
| 310 | sy = -1 |
| 311 | } |
| 312 | err := dx - dy |
| 313 | |
| 314 | for { |
| 315 | plot(x0, y0) |
| 316 | if x0 == x1 && y0 == y1 { |
| 317 | break |
| 318 | } |
| 319 | e2 := 2 * err |
| 320 | if e2 > -dy { |
| 321 | err -= dy |
| 322 | x0 += sx |
| 323 | } |
| 324 | if e2 < dx { |
| 325 | err += dx |
| 326 | y0 += sy |
| 327 | } |
| 328 | } |
| 329 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…