Documentation
¶
Index ¶
- type Cell
- type Matrix
- func (m Matrix[T]) Adjacent(x, y int, wrap bool) []Cell[T]
- func (m Matrix[T]) Cartesian() bool
- func (m Matrix[T]) Clone() Matrix[T]
- func (m Matrix[T]) Column(x int) (col []T)
- func (m Matrix[T]) Copy(x, y int, n Matrix[T])
- func (m Matrix[T]) Equals(n Matrix[T]) bool
- func (m Matrix[T]) Fill(v T)
- func (m Matrix[T]) Fix(y int) int
- func (m Matrix[T]) Get(x, y int) T
- func (m Matrix[T]) Height() int
- func (m Matrix[T]) Hexagonal(x, y int, wrap bool) []Cell[T]
- func (m Matrix[T]) Moore(x, y int, wrap bool) []Cell[T]
- func (m Matrix[T]) Row(y int) []T
- func (m Matrix[T]) Set(x, y int, v T)
- func (m Matrix[T]) Slice() []T
- func (m Matrix[T]) Submatrix(x, y, w, h int) Matrix[T]
- func (m Matrix[T]) Swap(x, y, x1, y1 int)
- func (m Matrix[T]) VonNewmann(x, y int, wrap bool) []Cell[T]
- func (m Matrix[T]) Width() int
- type Neighbourhood
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matrix ¶
type Matrix[T comparable] struct { // contains filtered or unexported fields }
A Matrix is a 2-dimensional table stored as a 1-dimensional slice
func FromSlice ¶ added in v0.0.6
func FromSlice[T comparable](cols int, cart bool, sl []T) (m Matrix[T], ok bool)
FromSlice creates a new matrix with the content of the input slice. It requires the matrix `width` (cols) and the type of matrix. If the length of the input slice is not a multiple of the width the `ok` return boolean will be false.
func New ¶
func New[T comparable](w, h int, cart bool) Matrix[T]
New creates a new Matrix given width, height and if it should use cartesian coordinates (0 at the bottom)
func NewLike ¶ added in v0.0.5
func NewLike[T comparable](m Matrix[T]) Matrix[T]
NewLike creates a new matrix with the same dimensions as the input matrix
func (Matrix[T]) Adjacent ¶ added in v0.0.4
Adjacent returns a list of Cell(s) adjacent to the one at x,y. If wrap is true coordinates that are outside the Matrix boundary will wrap around. For example if x=0 return add rightmost cell, if y=top add bottom cell.
func (Matrix[T]) Cartesian ¶ added in v0.0.5
Cartesian return true for cartesian coordinates (0 at the bottom) and false for computer coordinates (0 at the top)
func (Matrix[T]) Clone ¶ added in v0.0.2
Clone creates a new matrix that is a copy of the input matrix
func (Matrix[T]) Column ¶ added in v0.0.9
Column returns the list of values for the specified column
func (Matrix[T]) Copy ¶ added in v0.0.7
Copy copies the matrix `n` into `m` starting at the coordinates `x,y`
func (Matrix[T]) Fill ¶ added in v0.0.3
func (m Matrix[T]) Fill(v T)
Fill sets all cells of the matrix to the specified value
func (Matrix[T]) Fix ¶
Fix converts the row number (y) from one coordinate system to the other (cartesian to computer or viceversa)
func (Matrix[T]) Hexagonal ¶ added in v0.0.8
Hexagonal returns a list of Cell(s) adjacent to the one at x,y, according to the Hexagonal neighbourhood rules emulated on a rectangular grid (left, top-left, top, right, bottom-right, bottom)
func (Matrix[T]) Moore ¶ added in v0.0.8
Moore returns a list of Cell(s) adjacent to the one at x,y, according to the Moore neighbourhood (from x-1, y-1 to x+1, y+1)
func (Matrix[T]) Slice ¶ added in v0.0.5
func (m Matrix[T]) Slice() []T
Slice return the backing slice for the Matrix
func (Matrix[T]) Submatrix ¶ added in v0.0.6
Creates a new matrix that is a subset of the input matrix
func (Matrix[T]) Swap ¶ added in v0.0.9
Swap changes the value for the cell at x,y with the one for the cell at x1, y1
func (Matrix[T]) VonNewmann ¶ added in v0.0.8
VonNewmann returns a list of Cell(s) adjacent to the one at x,y, according to the Von Newmann neighbourhood (above, below, left, righ)
type Neighbourhood ¶ added in v0.0.8
type Neighbourhood int
const ( MooreNeighbourhood Neighbourhood = iota VonNewmannNeighbourhood HexagonalNeighbourhood )