/
byte_matrix.go
69 lines (59 loc) · 1.26 KB
/
byte_matrix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package encoder
type ByteMatrix struct {
bytes [][]int8
width int
height int
}
func NewByteMatrix(width, height int) *ByteMatrix {
bytes := make([][]int8, height)
for i := 0; i < height; i++ {
bytes[i] = make([]int8, width)
}
return &ByteMatrix{bytes, width, height}
}
func (this *ByteMatrix) GetHeight() int {
return this.height
}
func (this *ByteMatrix) GetWidth() int {
return this.width
}
func (this *ByteMatrix) Get(x, y int) int8 {
return this.bytes[y][x]
}
func (this *ByteMatrix) GetArray() [][]int8 {
return this.bytes
}
func (this *ByteMatrix) Set(x, y int, value int8) {
this.bytes[y][x] = value
}
func (this *ByteMatrix) SetBool(x, y int, value bool) {
if value {
this.bytes[y][x] = 1
} else {
this.bytes[y][x] = 0
}
}
func (this *ByteMatrix) Clear(value int8) {
for y := range this.bytes {
for x := range this.bytes[y] {
this.bytes[y][x] = value
}
}
}
func (this *ByteMatrix) String() string {
result := make([]byte, 0, 2*(this.width+1)*this.height)
for _, row := range this.bytes {
for _, b := range row {
switch b {
case 0:
result = append(result, " 0"...)
case 1:
result = append(result, " 1"...)
default:
result = append(result, " "...)
}
}
result = append(result, '\n')
}
return string(result)
}