From fbf90504b837b6e982b6b508e7491a47896ced1b Mon Sep 17 00:00:00 2001 From: Timon Ringwald Date: Thu, 1 Oct 2020 15:54:08 +0200 Subject: [PATCH] fixed panic in Set method --- buffer.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/buffer.go b/buffer.go index 6425b0d..6b83501 100644 --- a/buffer.go +++ b/buffer.go @@ -30,9 +30,17 @@ func NewBuffer(width, height int) *Buffer { } } +func (b *Buffer) x(x int) int { + return limit(x, 0, b.width-1) +} + +func (b *Buffer) y(y int) int { + return limit(y, 0, b.height-1) +} + // Set sets the rune at position (x,y) to c func (b *Buffer) Set(x, y int, c rune) { - b.data[y][x] = c + b.data[b.y(y)][b.x(x)] = c } // Get returns the rune at position (x,y)