Documentation ¶
Index ¶
- Constants
- Variables
- type Grid
- func (g *Grid[T]) Bounds() (xMin int, yMin int, xMax int, yMax int)
- func (g *Grid[T]) Clone() *Grid[T]
- func (g *Grid[T]) Contains(v I2[int]) bool
- func (g *Grid[T]) ContainsInts(x, y int) bool
- func (g *Grid[T]) Count(t T) int
- func (g *Grid[T]) CountNotZero() int
- func (g *Grid[T]) Counts() map[T]int
- func (g *Grid[T]) Format(f fmt.State, _ rune)
- func (g *Grid[T]) Get(v I2[int]) (t T)
- func (g *Grid[T]) GetInts(x, y int) T
- func (g *Grid[T]) NonZeroBounds() (xMin int, yMin int, xMax int, yMax int)
- func (g *Grid[T]) PrettyPrint(valueWidth int, flipX, flipY bool) string
- func (g *Grid[T]) Resize(xMin, yMin, xMax, yMax int) *Grid[T]
- func (g *Grid[T]) Set(v I2[int], t T) T
- func (g *Grid[T]) SetIfZero(v I2[int], t T) bool
- func (g *Grid[T]) SetIfZeroInts(x, y int, t T) bool
- func (g *Grid[T]) SetInts(x, y int, t T) T
- type I2
- func (i I2[T]) Abs() I2[T]
- func (i I2[T]) Add(j I2[T]) I2[T]
- func (i I2[T]) EuclideanDist(j I2[T]) float64
- func (i I2[T]) EuclideanDist2(j I2[T]) int64
- func (i I2[T]) ManhattanDist(j I2[T]) int64
- func (i I2[T]) MaxComponent() T
- func (i I2[T]) MinComponent() T
- func (i I2[T]) Mul(c T) I2[T]
- func (i I2[T]) Sign() I2[int]
- func (i I2[T]) Sub(j I2[T]) I2[T]
- func (i I2[T]) WithZ(z T) I3[T]
- type I2Set
- type I3
- func (i I3[T]) Abs() I3[T]
- func (i I3[T]) Add(j I3[T]) I3[T]
- func (i I3[T]) EuclideanDist(j I3[T]) float64
- func (i I3[T]) EuclideanDist2(j I3[T]) int64
- func (i I3[T]) ManhattanDist(j I3[T]) int64
- func (i I3[T]) MaxComponent() T
- func (i I3[T]) MinComponent() T
- func (i I3[T]) Mul(c T) I3[T]
- func (i I3[T]) Sign() I3[int]
- func (i I3[T]) Sub(j I3[T]) I3[T]
- func (i I3[T]) XY() I2[T]
- type I3Set
Constants ¶
const ( // NegX is the index of the vector with X=-1 in I2Directions, // I2DirectionsWithDiagonals, I3Directions & I3DirectionsWithDiagonals NegX = 0 // PosX is the index of the vector with X=1 in I2Directions, // I2DirectionsWithDiagonals, I3Directions & I3DirectionsWithDiagonals PosX = 1 // NegY is the index of the vector with Y=-1 in I2Directions, // I2DirectionsWithDiagonals, I3Directions & I3DirectionsWithDiagonals NegY = 2 // PosY is the index of the vector with Y=1 in I2Directions, // I2DirectionsWithDiagonals, I3Directions & I3DirectionsWithDiagonals PosY = 3 // NegZ is the index of the vector with Z=-1 in I3Directions // & I3DirectionsWithDiagonals NegZ = 4 // PosZ is the index of the vector with Z=1 in I3Directions // & I3DirectionsWithDiagonals PosZ = 5 )
Variables ¶
var I2Directions = [...]I2[int]{
{-1, 0},
{1, 0},
{0, -1},
{0, 1},
}
var I2DirectionsWithDiagonals = [...]I2[int]{
{-1, 0},
{1, 0},
{0, -1},
{0, 1},
{-1, -1},
{-1, 1},
{1, -1},
{1, 1},
}
var I2Opposites = [...]int{
1,
0,
3,
2,
7,
6,
5,
4,
}
I2Opposites contains the index of the opposite direction for each index in I2Directions & I2DirectionsWithDiagonals
var I3Directions = [...]I3[int]{
{-1, 0, 0},
{1, 0, 0},
{0, -1, 0},
{0, 1, 0},
{0, 0, -1},
{0, 0, 1},
}
var I3DirectionsWithDiagonals = [...]I3[int]{
{-1, 0, 0},
{1, 0, 0},
{0, -1, 0},
{0, 1, 0},
{0, 0, -1},
{0, 0, 1},
{-1, -1, -1},
{-1, -1, 0},
{-1, -1, 1},
{-1, 0, -1},
{-1, 0, 1},
{-1, 1, -1},
{-1, 1, 0},
{-1, 1, 1},
{0, -1, -1},
{0, -1, 1},
{0, 1, -1},
{0, 1, 1},
{1, -1, -1},
{1, -1, 0},
{1, -1, 1},
{1, 0, -1},
{1, 0, 1},
{1, 1, -1},
{1, 1, 0},
{1, 1, 1},
}
var I3Opposites = [...]int{
1,
0,
3,
2,
5,
4,
25,
24,
23,
22,
21,
20,
19,
18,
17,
16,
15,
14,
13,
12,
11,
10,
9,
8,
7,
6,
}
I3Opposites contains the index of the opposite direction for each index in I3Directions & I3DirectionsWithDiagonals
Functions ¶
This section is empty.
Types ¶
type Grid ¶
type Grid[T comparable] struct { // contains filtered or unexported fields }
func NewGrid ¶
func NewGrid[T comparable](xMin, yMin, xMax, yMax int) *Grid[T]
NewGrid returns a Grid initially sized to hold xMin <= x <= xMax & yMin <= y <= yMax. It will automatically grow as needed
func (*Grid[T]) Bounds ¶
Bounds returns the grid's xMin, yMin, xMax, yMax, which is likely to be slightly larger than the actual bounds containing non-zero values.
Can be used with NewGrid to make a new grid with the same size as this grid:
vec.NewGrid[T](grid.Bounds())
func (*Grid[T]) ContainsInts ¶
ContainsInts returns whether the element at the given coords is non-zero Provided for convenience when not using I2
func (*Grid[T]) CountNotZero ¶
CountNotZero returns the number of non-zero elements in the grid, compared using ==
func (*Grid[T]) GetInts ¶
GetInts returns the element at the given coords Provided for convenience when not using I2
func (*Grid[T]) NonZeroBounds ¶
NonZeroBounds returns the min x, min y, max x & max y with non-zero elements. If there are no non-zero elements, zeroes are returned.
func (*Grid[T]) PrettyPrint ¶
PrettyPrint returns a pretty printed string representing the grid
Each element will be padded to valueWidth characters wide. If the value is already wider than this, it will be truncated and the last character replaced with !. Setting width to zero will just print non-zero elements, and setting width to one on a Grid[uint8] will automatically interpret the bytes as characters (any characters < 32 will be replaced to avoid printing control characters)
By default, the bottom left is (minX, minY)
func (*Grid[T]) Resize ¶
Resize returns a copy of the Grid resized to the specified size. Any elements outside the new size will be lost
func (*Grid[T]) SetIfZero ¶
SetIfZero sets the element at the given coords if it is currently zero, returning whether the element was zero
func (*Grid[T]) SetIfZeroInts ¶
SetIfZeroInts sets the element at the given coords if it is currently zero, returning whether the element was zero Provided for convenience when not using I2
type I2 ¶
type I2[T constraints.Integer] struct { X, Y T }
func (I2[T]) EuclideanDist ¶
func (I2[T]) EuclideanDist2 ¶
func (I2[T]) ManhattanDist ¶
func (I2[T]) MaxComponent ¶
func (i I2[T]) MaxComponent() T
func (I2[T]) MinComponent ¶
func (i I2[T]) MinComponent() T
type I2Set ¶
type I2Set[T constraints.Integer] map[I2[T]]struct{}
func (I2Set[T]) Add ¶
Add the given vector to the set, returning if the vector was not present before
func (I2Set[T]) ContainsInts ¶
func (I2Set[T]) RemoveInts ¶
type I3 ¶
type I3[T constraints.Integer] struct { X, Y, Z T }
func (I3[T]) EuclideanDist ¶
func (I3[T]) EuclideanDist2 ¶
func (I3[T]) ManhattanDist ¶
func (I3[T]) MaxComponent ¶
func (i I3[T]) MaxComponent() T
func (I3[T]) MinComponent ¶
func (i I3[T]) MinComponent() T
type I3Set ¶
type I3Set[T constraints.Integer] map[I3[T]]struct{}
func (I3Set[T]) Add ¶
Add the given vector to the set, returning if the vector was not present before