fixed panic in Set method

This commit is contained in:
Timon Ringwald 2020-10-01 15:54:08 +02:00
parent 88a6a466bf
commit fbf90504b8

View File

@ -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 // Set sets the rune at position (x,y) to c
func (b *Buffer) Set(x, y int, c rune) { 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) // Get returns the rune at position (x,y)