Socket
Socket
Sign inDemoInstall

github.com/anaseto/grid

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/anaseto/grid

Package grid provides a generic two-dimensional matrix slice type. The package provides utilities for iterating such grids, as well as manipulating positions and ranges. The API is inspired by the standard Go slice builtin functions and the image standard package.


Version published

Readme

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

Last updated on 22 Dec 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc