Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
| 1 |
package grid |
| 2 |
|
| 3 |
import ( |
| 4 |
. "github.com/badgerodon/collections" |
| 5 |
) |
| 6 |
|
| 7 |
type ( |
| 8 |
Grid struct { |
| 9 |
values []interface{} |
| 10 |
cols, rows int |
| 11 |
} |
| 12 |
) |
| 13 |
|
| 14 |
func New(cols, rows int) *Grid { |
| 15 |
return &Grid{ |
| 16 |
values: make([]interface{}, cols*rows), |
| 17 |
cols: cols, |
| 18 |
rows: rows, |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
func (this *Grid) Do(f func(p Point, value interface{})) { |
| 23 |
for x := 0; x < this.cols; x++ { |
| 24 |
for y := 0; y < this.rows; y++ { |
| 25 |
f(Point{x, y}, this.values[x*this.cols+y]) |
| 26 |
} |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
func (this *Grid) Get(p Point) interface{} { |
| 31 |
if p.X < 0 || p.Y < 0 || p.X >= this.cols || p.Y >= this.rows { |
| 32 |
return nil |
| 33 |
} |
| 34 |
v, _ := this.values[p.X*this.cols+p.Y] |
| 35 |
return v |
| 36 |
} |
| 37 |
|
| 38 |
func (this *Grid) Rows() int { |
| 39 |
return this.rows |
| 40 |
} |
| 41 |
|
| 42 |
func (this *Grid) Cols() int { |
| 43 |
return this.cols |
| 44 |
} |
| 45 |
|
| 46 |
func (this *Grid) Len() int { |
| 47 |
return this.rows * this.cols |
| 48 |
} |
| 49 |
|
| 50 |
func (this *Grid) Set(p Point, v interface{}) { |
| 51 |
|
| 52 |
} |