Documentation
¶
Index ¶
- Variables
- func SMatrix(m *Matrix[byte]) string
- type Coord
- type Matrix
- func (m *Matrix[T]) At(x, y int) T
- func (m *Matrix[T]) AtCoord(c Coord) T
- func (m *Matrix[T]) Clone() *Matrix[T]
- func (m *Matrix[T]) Coords() iter.Seq[Coord]
- func (m *Matrix[T]) Copy(src *Matrix[T]) error
- func (m *Matrix[T]) Count(value T) int
- func (m *Matrix[T]) Fill(value T)
- func (m *Matrix[T]) Find(value T) (Coord, bool)
- func (m *Matrix[T]) In(x, y int) bool
- func (m *Matrix[T]) InCoord(c Coord) bool
- func (m *Matrix[T]) SetAt(x, y int, value T)
- func (m *Matrix[T]) SetAtCoord(c Coord, value T)
- func (m *Matrix[T]) String() string
- type Vec
- type XY
Constants ¶
This section is empty.
Variables ¶
var ( Left = Vec{X: -1, Y: 0} Right = Vec{X: 1, Y: 0} Up = Vec{X: 0, Y: -1} Down = Vec{X: 0, Y: 1} UpLeft = Up.Add(Left) UpRight = Up.Add(Right) DownLeft = Down.Add(Left) DownRight = Down.Add(Right) )
var ErrInconsistentGeometry = fmt.Errorf("inconsistent geometry")
Functions ¶
Types ¶
type Matrix ¶
type Matrix[T comparable] struct { Data []T Size Vec }
func NewFromReader ¶
NewFromReader reads lines from the Reader and builds a new Matrix[byte] where each line is a row of the matrix, starting from the top. Each line must be of the same length, else an error will be returned.
func (*Matrix[T]) At ¶
At returns the value present at a coordinate. It's the responsibility of the user to check that the coordinate exists within the Matrix with In.
func (*Matrix[T]) AtCoord ¶
AtCoord returns the value present at a coordinate. It's the responsibility of the user to check that the coordinate exists within the Matrix with InCoord.
func (*Matrix[T]) Coords ¶
Coords will return an iterator over all the coordinates that exist in the matrix.
func (*Matrix[T]) Copy ¶
Copy copies data from a matrix into the current matrix. If geometries are different, an error will be returned.
func (*Matrix[T]) Fill ¶
func (m *Matrix[T]) Fill(value T)
Fill will fill the matrix with a given value.
func (*Matrix[T]) Find ¶
Find searches for a value in the Matrix and returns a coordinate of the first match and a boolean indicating if the value was found.
func (*Matrix[T]) SetAt ¶
SetAt sets the value present at a coordinate. It's the responsibility of the user to check that the coordinate exists within the Matrix with In.
func (*Matrix[T]) SetAtCoord ¶
SetAtCoord sets the value present at a coordinate. It's the responsibility of the user to check that the coordinate exists within the Matrix with InCoord.