spatial

package
v0.0.0-...-d1276a2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package spatial contain types about accessing and storing spatial data.

Index

Constants

This section is empty.

Variables

View Source
var (
	N  = DiscretePos2D{0, 1}
	NE = DiscretePos2D{1, 1}
	E  = DiscretePos2D{1, 0}
	SE = DiscretePos2D{1, -1}
	S  = DiscretePos2D{0, -1}
	SW = DiscretePos2D{-1, -1}
	W  = DiscretePos2D{-1, 0}
	NW = DiscretePos2D{-1, 1}
)

Functions

This section is empty.

Types

type DiscreteMap2D

type DiscreteMap2D[T any] struct {
	Width  int
	Height int
	Data   [][]T
}

DiscreteMap2D can be used for storing 2d data with multiple dimensions in a integer coordinate system.

The origin is top left of the map.

func NewDiscreteMap2D

func NewDiscreteMap2D[T any](width, height, dimension int) DiscreteMap2D[T]

NewDiscreteMap2D creates a new DiscreteMap2D with given width, height and dimension

func NewDiscreteMap2DFromLines

func NewDiscreteMap2DFromLines[T any](dimension int, lines []string, transformFunc func(r rune, pos DiscretePos2D) T) DiscreteMap2D[T]

NewDiscreteMap2DFromLines creates DiscreteMap2D with width and height from the input lines it is assumed all linesare the same length first dimension is filled from lines in combination with the transformFunc data type.

func (*DiscreteMap2D[T]) GetDataIndex

func (d *DiscreteMap2D[T]) GetDataIndex(pos DiscretePos2D) int

GetDataIndex gets the index to read data in the DiscreteMap2D position x is used for width, y for height

func (*DiscreteMap2D[T]) GetValue

func (d *DiscreteMap2D[T]) GetValue(dim int, pos DiscretePos2D) T

GetValue the value of position in dimension. The positions x is width, y is height.

func (*DiscreteMap2D[T]) IsPositionInbounds

func (d *DiscreteMap2D[T]) IsPositionInbounds(p DiscretePos2D) bool

func (*DiscreteMap2D[T]) SetValue

func (d *DiscreteMap2D[T]) SetValue(dim int, pos DiscretePos2D, value T)

SetValue sets a value of a position in the dimension

func (DiscreteMap2D[T]) String

func (d DiscreteMap2D[T]) String() string

type DiscretePos2D

type DiscretePos2D struct {
	X int
	Y int
}

DiscretePos2D is used to access values in the DiscreteMap2D. The x values are used for width, y for height.

func GetAdjacentPositions

func GetAdjacentPositions(pos DiscretePos2D) []DiscretePos2D

GetAdjacentPositions returns the adjacent positions. in clockwise order starting from North

func GetBorderPositions

func GetBorderPositions(pos DiscretePos2D) []DiscretePos2D

GetBorderPositions returns the four bordering neighbour positions in order: x+1, x-1, y+1, y-1 East, West, North, South

func (DiscretePos2D) Add

Add returns the added result as a new position

Jump to

Keyboard shortcuts

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