grid

package
v0.0.0-...-4fa68a7 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Directions

func Directions() iter.Seq[Direction]

func Enum

func Enum[T constraints.Integer](opts ...rune) func(rune) (T, error)

Enum return a function suitable to pass to Read, that accepts any of opts and turns it into its position in that list.

func Find

func Find[T comparable](g *Grid[T], v T) iter.Seq[Pos]

Types

type Direction

type Direction int
const (
	Up Direction = iota
	Right
	Down
	Left
)

func (Direction) Invert

func (d Direction) Invert() Direction

func (Direction) Move

func (d Direction) Move(p Pos) Pos

func (Direction) RotateLeft

func (d Direction) RotateLeft() Direction

func (Direction) RotateRight

func (d Direction) RotateRight() Direction

func (Direction) String

func (d Direction) String() string

type Grid

type Grid[T any] struct {
	W int
	H int
	G []T
}

func New

func New[T any](w, h int) *Grid[T]

func Read

func Read[T any](r io.Reader, fromRune func(rune) (T, error)) (*Grid[T], error)

func (*Grid[T]) All

func (g *Grid[T]) All() iter.Seq2[Pos, T]

func (*Grid[T]) At

func (g *Grid[T]) At(p Pos) T

func (*Grid[T]) Bounds

func (g *Grid[T]) Bounds() Rectangle

func (*Grid[T]) Clone

func (g *Grid[T]) Clone() *Grid[T]

func (*Grid[T]) Neigh4

func (g *Grid[T]) Neigh4(p Pos) iter.Seq2[Pos, T]

func (*Grid[T]) Pos

func (g *Grid[T]) Pos(i int) Pos

func (*Grid[T]) Rect

func (g *Grid[T]) Rect(r Rectangle) iter.Seq2[Pos, T]

func (*Grid[T]) Set

func (g *Grid[T]) Set(p Pos, v T)

func (*Grid[T]) String

func (g *Grid[T]) String() string

func (*Grid[T]) Valid

func (g *Grid[T]) Valid(p Pos) bool

type Pos

type Pos struct {
	Row int
	Col int
}

func (Pos) Add

func (p Pos) Add(δ Pos) Pos

func (Pos) Dist

func (p Pos) Dist(q Pos) int

func (Pos) Length

func (p Pos) Length() int

func (Pos) String

func (p Pos) String() string

func (Pos) Sub

func (p Pos) Sub(δ Pos) Pos

type Rectangle

type Rectangle struct {
	Min Pos
	Max Pos
}

func Rect

func Rect(rmin, cmin, rmax, cmax int) Rectangle

func (Rectangle) Add

func (r Rectangle) Add(p Pos) Rectangle

func (Rectangle) All

func (r Rectangle) All() iter.Seq[Pos]

func (Rectangle) Canon

func (r Rectangle) Canon() Rectangle

func (Rectangle) Contains

func (r Rectangle) Contains(p Pos) bool

func (Rectangle) Empty

func (r Rectangle) Empty() bool

func (Rectangle) Eq

func (r Rectangle) Eq(s Rectangle) bool

func (Rectangle) Height

func (r Rectangle) Height() int

func (Rectangle) Hull

func (r Rectangle) Hull(s Rectangle) Rectangle

func (Rectangle) In

func (r Rectangle) In(s Rectangle) bool

func (Rectangle) Inset

func (r Rectangle) Inset(n int) Rectangle

func (Rectangle) Intersect

func (r Rectangle) Intersect(s Rectangle) Rectangle

func (Rectangle) Overlaps

func (r Rectangle) Overlaps(s Rectangle) bool

func (Rectangle) Width

func (r Rectangle) Width() int

Jump to

Keyboard shortcuts

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