grid

package
v0.0.0-...-bc1935d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Up    = Index{0, -1}
	Down  = Index{0, 1}
	Left  = Index{-1, 0}
	Right = Index{1, 0}
)

Functions

func Print

func Print[T rune | byte](g Grid[T])

func PrintFunc

func PrintFunc[T any](g Grid[T], f func(T) rune)

Types

type Grid

type Grid[T any] [][]T

func FromGridSize

func FromGridSize[T, O any](other Grid[O]) Grid[T]

func NewGridSize

func NewGridSize[T any](cols, rows int) Grid[T]

func (Grid[T]) Cells

func (g Grid[T]) Cells() []T

Cells of the grid in row-major order.

func (Grid[T]) Fill

func (g Grid[T]) Fill(t T)

func (Grid[T]) FilterValid

func (g Grid[T]) FilterValid(idxs []Index) []Index

func (Grid[T]) Get

func (g Grid[T]) Get(i Index) T

Get returns the value at i if i is within the bounds of the grid, otherwise the zero value for T. To test if i is valid use Lookup instead.

func (Grid[T]) IndexedCells

func (g Grid[T]) IndexedCells() []IndexedCell[T]

Cells of the grid in row-major order.

func (Grid[T]) IndexedCellsByColumn

func (g Grid[T]) IndexedCellsByColumn() []IndexedCell[T]

Cells of the grid in column-major order.

func (Grid[T]) Indexes

func (g Grid[T]) Indexes() []Index

func (Grid[T]) LenCols

func (g Grid[T]) LenCols() int

func (Grid[T]) Lookup

func (g Grid[T]) Lookup(i Index) (T, bool)

func (Grid[T]) Set

func (g Grid[T]) Set(i Index, t T)

func (Grid[T]) Transpose

func (g Grid[T]) Transpose() Grid[T]

type Index

type Index struct{ X, Y int }

func Adjacent

func Adjacent(i Index) []Index

func AdjacentNoDiagonal

func AdjacentNoDiagonal(i Index) []Index

func FlipDir

func FlipDir(dir Index) Index

func I

func I(x, y int) Index

func (Index) Add

func (i Index) Add(i2 Index) Index

func (Index) Sub

func (i Index) Sub(i2 Index) Index

type IndexedCell

type IndexedCell[T any] struct {
	Idx   Index
	Value T
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL