MCPcopy Index your code
hub / github.com/buger/goterm / drawLine

Function drawLine

plot.go:292–329  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

290//
291// http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
292func 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}

Callers 1

DrawLineMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…