Socket
Book a DemoInstallSign in
Socket

codeberg.org/anaseto/grid

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codeberg.org/anaseto/grid

Go Modules
Version
v0.2.0
Version published
Created
Source

Grid

pkg.go.dev godocs.io

The grid module and package provide a generic implementation of a two-dimensional matrix slice type. The API is inspired both by the standard Go slice builtin functions and the image standard package.

It makes no assumptions on the type of the cells, and provides optimized generic methods for grid iteration and manipulation.

Here's a simple example of usage:

// Create a new 10x10 grid of runes.
gd := grid.NewGrid[rune](10, 10)
// Fill the whole grid with dots.
gd.Fill('.')
// Define a range (3,3)-(7,7).
rg := grid.NewRange(3, 3, 7, 7)
// Define a slice of the grid using the range.
rectangle := gd.Slice(rg)
// Fill the rectangle with #.
rectangle.Fill('#')
// Print the grid.
it := gd.Iterator()
max := gd.Size()
for it.Next() {
	fmt.Printf("%c", it.V())
	if it.P().X == max.X-1 {
		fmt.Print("\n")
	}
}
// Output:
// ..........
// ..........
// ..........
// ...####...
// ...####...
// ...####...
// ...####...
// ..........
// ..........
// ..........

See the documentation for more examples.

FAQs

Package last updated on 22 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts