vec

package
v0.0.0-...-aa75ebd Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var I2Directions = [...]I2[int]{
	{-1, 0},
	{1, 0},
	{0, -1},
	{0, 1},
}
View Source
var I2DirectionsWithDiagonals = [...]I2[int]{
	{-1, 0},
	{1, 0},
	{0, -1},
	{0, 1},

	{-1, -1},
	{-1, 1},
	{1, -1},
	{1, 1},
}
View Source
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

View Source
var I3Directions = [...]I3[int]{
	{-1, 0, 0},
	{1, 0, 0},
	{0, -1, 0},
	{0, 1, 0},
	{0, 0, -1},
	{0, 0, 1},
}
View Source
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},
}
View Source
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

func (g *Grid[T]) Bounds() (xMin int, yMin int, xMax int, yMax int)

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]) Clone

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

Clone returns a copy of this Grid. Elements are shallow copied

func (*Grid[T]) Contains

func (g *Grid[T]) Contains(v I2[int]) bool

Contains returns whether the element at the given coords is non-zero

func (*Grid[T]) ContainsInts

func (g *Grid[T]) ContainsInts(x, y int) bool

ContainsInts returns whether the element at the given coords is non-zero Provided for convenience when not using I2

func (*Grid[T]) Count

func (g *Grid[T]) Count(t T) int

Count returns the count of a given element in the grid, compared using ==

func (*Grid[T]) CountNotZero

func (g *Grid[T]) CountNotZero() int

CountNotZero returns the number of non-zero elements in the grid, compared using ==

func (*Grid[T]) Counts

func (g *Grid[T]) Counts() map[T]int

Counts returns the number of each distinct value of T in the grid

func (*Grid[T]) Format

func (g *Grid[T]) Format(f fmt.State, _ rune)

func (*Grid[T]) Get

func (g *Grid[T]) Get(v I2[int]) (t T)

Get returns the element at the given coords

func (*Grid[T]) GetInts

func (g *Grid[T]) GetInts(x, y int) T

GetInts returns the element at the given coords Provided for convenience when not using I2

func (*Grid[T]) NonZeroBounds

func (g *Grid[T]) NonZeroBounds() (xMin int, yMin int, xMax int, yMax int)

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

func (g *Grid[T]) PrettyPrint(valueWidth int, flipX, flipY bool) string

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

func (g *Grid[T]) Resize(xMin, yMin, xMax, yMax int) *Grid[T]

Resize returns a copy of the Grid resized to the specified size. Any elements outside the new size will be lost

func (*Grid[T]) Set

func (g *Grid[T]) Set(v I2[int], t T) T

Set the element at the given coords, returning the old element

func (*Grid[T]) SetIfZero

func (g *Grid[T]) SetIfZero(v I2[int], t T) bool

SetIfZero sets the element at the given coords if it is currently zero, returning whether the element was zero

func (*Grid[T]) SetIfZeroInts

func (g *Grid[T]) SetIfZeroInts(x, y int, t T) bool

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

func (*Grid[T]) SetInts

func (g *Grid[T]) SetInts(x, y int, t T) T

SetInts sets the element at the given coords, returning the old element Provided for convenience when not using I2

type I2

type I2[T constraints.Integer] struct {
	X, Y T
}

func (I2[T]) Abs

func (i I2[T]) Abs() I2[T]

func (I2[T]) Add

func (i I2[T]) Add(j I2[T]) I2[T]

func (I2[T]) EuclideanDist

func (i I2[T]) EuclideanDist(j I2[T]) float64

func (I2[T]) EuclideanDist2

func (i I2[T]) EuclideanDist2(j I2[T]) int64

func (I2[T]) ManhattanDist

func (i I2[T]) ManhattanDist(j I2[T]) int64

func (I2[T]) MaxComponent

func (i I2[T]) MaxComponent() T

func (I2[T]) MinComponent

func (i I2[T]) MinComponent() T

func (I2[T]) Mul

func (i I2[T]) Mul(c T) I2[T]

func (I2[T]) Sign

func (i I2[T]) Sign() I2[int]

func (I2[T]) Sub

func (i I2[T]) Sub(j I2[T]) I2[T]

func (I2[T]) WithZ

func (i I2[T]) WithZ(z T) I3[T]

type I2Set

type I2Set[T constraints.Integer] map[I2[T]]struct{}

func (I2Set[T]) Add

func (s I2Set[T]) Add(v I2[T]) bool

Add the given vector to the set, returning if the vector was not present before

func (I2Set[T]) AddInts

func (s I2Set[T]) AddInts(x, y T) bool

func (I2Set[T]) Contains

func (s I2Set[T]) Contains(v I2[T]) bool

func (I2Set[T]) ContainsInts

func (s I2Set[T]) ContainsInts(x, y T) bool

func (I2Set[T]) Remove

func (s I2Set[T]) Remove(v I2[T]) bool

Remove the given vector from the set, returning if it was present

func (I2Set[T]) RemoveInts

func (s I2Set[T]) RemoveInts(x, y T) bool

type I3

type I3[T constraints.Integer] struct {
	X, Y, Z T
}

func (I3[T]) Abs

func (i I3[T]) Abs() I3[T]

func (I3[T]) Add

func (i I3[T]) Add(j I3[T]) I3[T]

func (I3[T]) EuclideanDist

func (i I3[T]) EuclideanDist(j I3[T]) float64

func (I3[T]) EuclideanDist2

func (i I3[T]) EuclideanDist2(j I3[T]) int64

func (I3[T]) ManhattanDist

func (i I3[T]) ManhattanDist(j I3[T]) int64

func (I3[T]) MaxComponent

func (i I3[T]) MaxComponent() T

func (I3[T]) MinComponent

func (i I3[T]) MinComponent() T

func (I3[T]) Mul

func (i I3[T]) Mul(c T) I3[T]

func (I3[T]) Sign

func (i I3[T]) Sign() I3[int]

func (I3[T]) Sub

func (i I3[T]) Sub(j I3[T]) I3[T]

func (I3[T]) XY

func (i I3[T]) XY() I2[T]

type I3Set

type I3Set[T constraints.Integer] map[I3[T]]struct{}

func (I3Set[T]) Add

func (s I3Set[T]) Add(v I3[T]) bool

Add the given vector to the set, returning if the vector was not present before

func (I3Set[T]) AddInts

func (s I3Set[T]) AddInts(x, y, z T) bool

func (I3Set[T]) Contains

func (s I3Set[T]) Contains(v I3[T]) bool

func (I3Set[T]) ContainsInts

func (s I3Set[T]) ContainsInts(x, y, z T) bool

func (I3Set[T]) Remove

func (s I3Set[T]) Remove(v I3[T]) bool

Remove the given vector from the set, returning if it was present

func (I3Set[T]) RemoveInts

func (s I3Set[T]) RemoveInts(x, y, z T) bool

Jump to

Keyboard shortcuts

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