grid

package
v0.0.0-...-225857b Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ray

func Ray(ray geom.Segment) iter.Seq[Index]

Ray casts a ray over a grid returning an iterator over all the grid cells the ray touches.

The ray is assumed to be in the grid's coordinate system. Rows correspond to Y position and columns correspond to X position.

Types

type Bools

type Bools struct {
	Rows int
	Cols int
	// contains filtered or unexported fields
}

Bools is a 2D grid of values, one per cell. The values are assumed to be dense (all present). Bools is guaranteed to be plain old data if T is also plain old data.

func NewBools

func NewBools(rows, cols int) *Bools

NewBools returns a new 2D grid of booleans with the provided number of rows and columns.

func (*Bools) All

func (b *Bools) All() iter.Seq2[Index, bool]

All returns an iterator over all entries in the grid.

func (*Bools) At

func (b *Bools) At(idx Index) bool

At returns the value at the provided row and column in the grid.

func (*Bools) Set

func (b *Bools) Set(idx Index, value bool)

Set sets the value at the provided row and column.

func (*Bools) SetAll

func (d *Bools) SetAll(value bool)

SetAll sets the value of every tile in the grid.

type Dense

type Dense[T any] struct {
	Data []T
	Rows int
	Cols int
}

Dense is a 2D grid of values, one per cell. The values are assumed to be dense (all present). Dense is guaranteed to be plain old data if T is also plain old data.

func New

func New[T any](rows, cols int) *Dense[T]

New returns a new 2D grid of values with the provided number of rows and columns.

func (*Dense[T]) All

func (d *Dense[T]) All() iter.Seq2[Index, T]

All returns an iterator over all entries in the grid.

func (*Dense[T]) At

func (d *Dense[T]) At(idx Index) T

At returns the value at the provided row and column in the grid.

func (*Dense[T]) Set

func (d *Dense[T]) Set(idx Index, t T)

Set sets the value at the provided row and column.

func (*Dense[T]) SetAll

func (d *Dense[T]) SetAll(value T)

SetAll sets the value of every cell in the grid.

type Index

type Index struct {
	Row, Col int
}

Index is an index into a grid.

func Idx

func Idx(row, col int) Index

Idx is a convenience function for creating an Index.

func (Index) AABB

func (i Index) AABB(dim geom.Dimensions) geom.AABB

AABB returns the AABB for the grid cell given the dimension of each cell.

func (Index) Max

func (i Index) Max(dim geom.Dimensions) geom.Point

Max returns the maximum point in the cell given the cell dimenions.

func (Index) Min

func (i Index) Min(dim geom.Dimensions) geom.Point

Min returns the minimum point in the cell given the cell dimenions.

Jump to

Keyboard shortcuts

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