Documentation ¶
Index ¶
- func Freq[T comparable](g Dense[T]) map[T]int
- type Dense
- func BytesFromStrings(s []string) Dense[byte]
- func FromStringsFunc[T any](s []string, parse func(string) ([]T, error)) (Dense[T], error)
- func Make[T any](h, w int) Dense[T]
- func Map[S, T any](g Dense[S], tf func(S) T) Dense[T]
- func MapOrError[S, T any](g Dense[S], tf func(S) (T, error)) (Dense[T], error)
- func RunesFromStrings(s []string) Dense[rune]
- func (g Dense[T]) All(yield func(image.Point, T) bool)
- func (g Dense[T]) Area() int
- func (g Dense[T]) At(p image.Point) T
- func (g Dense[T]) Bounds() image.Rectangle
- func (g Dense[T]) Clone() Dense[T]
- func (g Dense[T]) Fill(v T)
- func (g Dense[T]) FillRect(r image.Rectangle, v T)
- func (g Dense[T]) FlipH() Dense[T]
- func (g Dense[T]) FlipV() Dense[T]
- func (g Dense[T]) Map(f func(T) T)
- func (g Dense[T]) MapRect(r image.Rectangle, f func(T) T)
- func (g Dense[T]) Resize(r image.Rectangle) Dense[T]
- func (g Dense[T]) RotateACW() Dense[T]
- func (g Dense[T]) RotateCW() Dense[T]
- func (g Dense[T]) Size() (h, w int)
- func (g Dense[T]) String() string
- func (g Dense[T]) ToRGBA(cf func(T) color.Color) *image.RGBA
- func (g Dense[T]) ToSparse() Sparse[T]
- func (g Dense[T]) Transpose() Dense[T]
- type Sparse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Freq ¶
func Freq[T comparable](g Dense[T]) map[T]int
Freq produces a summary of the number of different values in a grid.
Types ¶
type Dense ¶
type Dense[T any] [][]T
Dense is a dense grid - a "2D array" generic type.
func BytesFromStrings ¶
BytesFromStrings produces a byte grid from a slice of strings.
func FromStringsFunc ¶
FromStringsFunc produces a grid from a slice of source strings s, containing data for one row per element, and a function for parsing each string into a `[]T` row. Uneven length rows are backfilled on the right with the zero value for T, to make all rows equal ength.
func Make ¶
Make makes a dense grid of width w and height h.
(If you want a sparse grid, use `make(Sparse[T])`.)
func MapOrError ¶
MapOrError converts a Dense[S] into a Dense[T] by using a transformation function tf. On the first error returned by tf, MapOrError returns an error.
func RunesFromStrings ¶
RunesFromStrings produces a byte grid from a slice of strings.
func (Dense[T]) Map ¶
func (g Dense[T]) Map(f func(T) T)
Map applies a transformation function to each element in the grid in-place.
func (Dense[T]) Resize ¶
Resize returns a new grid that is r.Dx * r.Dy in size, containing values from g. Resize can be used for producing subgrids and supergrids.
func (Dense[T]) RotateACW ¶
RotateACW returns a new grid with entries rotated anticlockwise by 90 degrees.
func (Dense[T]) RotateCW ¶
RotateCW returns a new grid with entries rotated clockwise by 90 degrees.
func (Dense[T]) Size ¶
Size returns the width and height of the Dense. If the height is zero the width will also be zero.
func (Dense[T]) ToRGBA ¶
ToRGBA converts a dense grid into an RGBA image using a colouring function.
type Sparse ¶
Sparse is a sparse grid - a map from points in 2D to values.
func MapToSparse ¶
MapToSparse converts a Dense[S] into a Sparse[T] by using a transformation function tf, which should also report if the element should be kept.
func (Sparse[T]) Bounds ¶
Bounds returns a rectangle containing all points in the sparse grid. It operates in O(len(g)) time.