primitives

package
v0.0.0-...-c1f540c Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Pi     = 3.141592653589793
	Pi2    = 2 * Pi
	HalfPi = 0.5 * Pi
	InvPi2 = 1.0 / Pi2
)

Variables

View Source
var CORNER_NEIGHBORS = []IntPoint{
	{-1, -1},
	{0, -1},
	{1, -1},
	{-1, 0},
	{1, 0},
	{-1, 1},
	{0, 1},
	{1, 1},
}
View Source
var EDGE_NEIGHBORS = []IntPoint{
	{0, -1},
	{-1, 0},
	{1, 0},
	{0, 1},
}

Functions

This section is empty.

Types

type BlockGrid

type BlockGrid struct {
	Blocks, Corners IntPoint
	X, Y            []int
}

func NewBlockGrid

func NewBlockGrid(size IntPoint) *BlockGrid

func (*BlockGrid) Block

func (b *BlockGrid) Block(atX, atY int) IntRect

func (*BlockGrid) BlockPoint

func (b *BlockGrid) BlockPoint(at IntPoint) IntRect

func (*BlockGrid) Corner

func (b *BlockGrid) Corner(atX, atY int) IntPoint

type BlockMap

type BlockMap struct {
	Pixels             IntPoint
	Primary, Secondary *BlockGrid
}

func NewBlockMap

func NewBlockMap(width, height, maxBlockSize int) *BlockMap

type BooleanMatrix

type BooleanMatrix struct {
	sync.RWMutex
	Width, Height int
	Cells         []bool
}

func NewBooleanMatrix

func NewBooleanMatrix(width, height int) *BooleanMatrix

func NewBooleanMatrixFromBooleanMatrix

func NewBooleanMatrixFromBooleanMatrix(other *BooleanMatrix) *BooleanMatrix

func NewBooleanMatrixFromPoint

func NewBooleanMatrixFromPoint(size IntPoint) *BooleanMatrix

func (*BooleanMatrix) BlockPoint

func (m *BooleanMatrix) BlockPoint(blockX, blockY, blockSize int) (int, int)

func (*BooleanMatrix) Get

func (m *BooleanMatrix) Get(x, y int) bool

func (*BooleanMatrix) GetPoint

func (m *BooleanMatrix) GetPoint(at IntPoint) bool

func (*BooleanMatrix) GetPointWithFallback

func (m *BooleanMatrix) GetPointWithFallback(at IntPoint, fallback bool) bool

func (*BooleanMatrix) GetWithFallback

func (m *BooleanMatrix) GetWithFallback(x, y int, fallback bool) bool

func (*BooleanMatrix) Invert

func (m *BooleanMatrix) Invert()

func (*BooleanMatrix) Merge

func (m *BooleanMatrix) Merge(other *BooleanMatrix) error

func (*BooleanMatrix) Set

func (m *BooleanMatrix) Set(x, y int, value bool)

func (*BooleanMatrix) SetPoint

func (m *BooleanMatrix) SetPoint(at IntPoint, value bool)

func (*BooleanMatrix) Size

func (m *BooleanMatrix) Size() IntPoint

type CircularArray

type CircularArray struct {
	// contains filtered or unexported fields
}

func NewCircularArray

func NewCircularArray(capacity int) *CircularArray

type CircularList

type CircularList[V any] struct {
	// contains filtered or unexported fields
}

func NewCircularList

func NewCircularList[V any]() *CircularList[V]

func (*CircularList[V]) Add

func (l *CircularList[V]) Add(item V) error

func (*CircularList[V]) AddAt

func (l *CircularList[V]) AddAt(index int, item V) error

func (*CircularList[V]) Get

func (l *CircularList[V]) Get(index int) (V, error)

func (*CircularList[V]) Iterator

func (l *CircularList[V]) Iterator() ListIterator[V]

func (*CircularList[V]) Remove

func (l *CircularList[V]) Remove(index int) error

func (*CircularList[V]) Size

func (l *CircularList[V]) Size() int

type Element

type Element[V any] struct {

	// The value stored with this element.
	Value any
	// contains filtered or unexported fields
}

Element is an element of a linked list.

func (*Element[V]) Next

func (e *Element[V]) Next() *Element[V]

Next returns the next list element or nil.

func (*Element[V]) Prev

func (e *Element[V]) Prev() *Element[V]

Prev returns the previous list element or nil.

type FloatAngle

type FloatAngle float64

func AngleAdd

func AngleAdd(start, delta float64) FloatAngle

func AtanFromFloatPointVector

func AtanFromFloatPointVector(vector FloatPoint) FloatAngle

func AtanFromIntPointVector

func AtanFromIntPointVector(vector IntPoint) FloatAngle

func AtanFromIntPoints

func AtanFromIntPoints(center, point IntPoint) FloatAngle

func BucketCenter

func BucketCenter(bucket, resolution int) FloatAngle

func (FloatAngle) Complementary

func (f FloatAngle) Complementary() FloatAngle

func (FloatAngle) Difference

func (f FloatAngle) Difference(second FloatAngle) FloatAngle

func (FloatAngle) Distance

func (f FloatAngle) Distance(second FloatAngle) float64

func (FloatAngle) FromOrientation

func (f FloatAngle) FromOrientation() FloatAngle

func (FloatAngle) Opposite

func (f FloatAngle) Opposite() FloatAngle

func (FloatAngle) Quantize

func (f FloatAngle) Quantize(resolution int) int

func (FloatAngle) ToOrientation

func (f FloatAngle) ToOrientation() FloatAngle

func (FloatAngle) ToVector

func (f FloatAngle) ToVector() FloatPoint

type FloatPoint

type FloatPoint struct {
	X, Y float64
}

func ZeroFloatPoint

func ZeroFloatPoint() FloatPoint

func (FloatPoint) Multiply

func (f FloatPoint) Multiply(factor float64) FloatPoint

func (FloatPoint) Round

func (f FloatPoint) Round() IntPoint

type FloatPointMatrix

type FloatPointMatrix struct {
	Width, Height int
	Vectors       []float64
}

func NewFloatPointMatrix

func NewFloatPointMatrix(width, height int) *FloatPointMatrix

func NewFloatPointMatrixFromPoint

func NewFloatPointMatrixFromPoint(size IntPoint) *FloatPointMatrix

func (*FloatPointMatrix) Add

func (m *FloatPointMatrix) Add(x, y int, px, py float64)

func (*FloatPointMatrix) AddFloatPoint

func (m *FloatPointMatrix) AddFloatPoint(x, y int, point FloatPoint)

func (*FloatPointMatrix) AddPoint

func (m *FloatPointMatrix) AddPoint(at IntPoint, point FloatPoint)

func (*FloatPointMatrix) Get

func (m *FloatPointMatrix) Get(x, y int) FloatPoint

func (*FloatPointMatrix) GetPoint

func (m *FloatPointMatrix) GetPoint(at IntPoint) FloatPoint

func (*FloatPointMatrix) Set

func (m *FloatPointMatrix) Set(x, y int, px, py float64)

func (*FloatPointMatrix) SetFloatPoint

func (m *FloatPointMatrix) SetFloatPoint(x, y int, point FloatPoint)

func (*FloatPointMatrix) SetPoint

func (m *FloatPointMatrix) SetPoint(at IntPoint, point FloatPoint)

func (*FloatPointMatrix) Size

func (m *FloatPointMatrix) Size() IntPoint

type GenericList

type GenericList[V any] struct {
	// contains filtered or unexported fields
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func NewGenericList

func NewGenericList[V any]() *GenericList[V]

New returns an initialized list.

func (*GenericList[V]) Back

func (l *GenericList[V]) Back() *Element[V]

Back returns the last element of list l or nil if the list is empty.

func (*GenericList[V]) Contains

func (l *GenericList[V]) Contains(value interface{}) (bool, *Element[V])

func (*GenericList[V]) Front

func (l *GenericList[V]) Front() *Element[V]

Front returns the first element of list l or nil if the list is empty.

func (*GenericList[V]) Init

func (l *GenericList[V]) Init() *GenericList[V]

Init initializes or clears list l.

func (*GenericList[V]) InsertAfter

func (l *GenericList[V]) InsertAfter(v any, mark *Element[V]) *Element[V]

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*GenericList[V]) InsertBefore

func (l *GenericList[V]) InsertBefore(v any, mark *Element[V]) *Element[V]

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*GenericList[V]) Len

func (l *GenericList[V]) Len() int

Len returns the number of elements of list l. The complexity is O(1).

func (*GenericList[V]) MoveAfter

func (l *GenericList[V]) MoveAfter(e, mark *Element[V])

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*GenericList[V]) MoveBefore

func (l *GenericList[V]) MoveBefore(e, mark *Element[V])

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*GenericList[V]) MoveToBack

func (l *GenericList[V]) MoveToBack(e *Element[V])

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*GenericList[V]) MoveToFront

func (l *GenericList[V]) MoveToFront(e *Element[V])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*GenericList[V]) PushBack

func (l *GenericList[V]) PushBack(v any) *Element[V]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*GenericList[V]) PushBackList

func (l *GenericList[V]) PushBackList(other *GenericList[V])

PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.

func (*GenericList[V]) PushFront

func (l *GenericList[V]) PushFront(v any) *Element[V]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*GenericList[V]) PushFrontList

func (l *GenericList[V]) PushFrontList(other *GenericList[V])

PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.

func (*GenericList[V]) Remove

func (l *GenericList[V]) Remove(e *Element[V]) any

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.

type HistogramCube

type HistogramCube struct {
	Width, Height, Bins int
	Counts              []int
}

func NewHistogramCube

func NewHistogramCube(width, height, bins int) *HistogramCube

func NewHistogramCubeFromPoint

func NewHistogramCubeFromPoint(size IntPoint, bins int) *HistogramCube

func (*HistogramCube) Add

func (h *HistogramCube) Add(x, y, z, value int)

func (*HistogramCube) AddPoint

func (h *HistogramCube) AddPoint(at IntPoint, z, value int)

func (*HistogramCube) Constrain

func (h *HistogramCube) Constrain(z int) int

func (*HistogramCube) Get

func (h *HistogramCube) Get(x, y, z int) int

func (*HistogramCube) GetPoint

func (h *HistogramCube) GetPoint(at IntPoint, z int) int

func (*HistogramCube) Increment

func (h *HistogramCube) Increment(x, y, z int)

func (*HistogramCube) IncrementPoint

func (h *HistogramCube) IncrementPoint(at IntPoint, z int)

func (*HistogramCube) Merge

func (histogram *HistogramCube) Merge(other *HistogramCube)

func (*HistogramCube) Set

func (h *HistogramCube) Set(x, y, z, value int)

func (*HistogramCube) SetPoint

func (h *HistogramCube) SetPoint(at IntPoint, z, value int)

func (*HistogramCube) Sum

func (h *HistogramCube) Sum(x, y int) int

func (*HistogramCube) SumPoint

func (h *HistogramCube) SumPoint(at IntPoint) int

type IntMatrix

type IntMatrix struct {
	sync.RWMutex
	Width, Height int
	// contains filtered or unexported fields
}

func NewIntMatrix

func NewIntMatrix(width, height int) *IntMatrix

func NewIntMatrixFromPoint

func NewIntMatrixFromPoint(size IntPoint) *IntMatrix

func (*IntMatrix) Get

func (m *IntMatrix) Get(x, y int) int

func (*IntMatrix) GetPoint

func (m *IntMatrix) GetPoint(at IntPoint) int

func (*IntMatrix) Set

func (m *IntMatrix) Set(x, y, value int)

func (*IntMatrix) Size

func (m *IntMatrix) Size() IntPoint

type IntPoint

type IntPoint struct {
	X, Y int
}

func ZeroIntPoint

func ZeroIntPoint() IntPoint

func (IntPoint) Area

func (p IntPoint) Area() int

func (IntPoint) CompareTo

func (p IntPoint) CompareTo(other IntPoint) int

func (IntPoint) Contains

func (p IntPoint) Contains(other IntPoint) bool

func (IntPoint) Equals

func (p IntPoint) Equals(obj interface{}) bool

func (IntPoint) Iterator

func (p IntPoint) Iterator() IntPointIterator

func (IntPoint) LengthSq

func (p IntPoint) LengthSq() int

func (IntPoint) LineTo

func (p IntPoint) LineTo(to IntPoint) []IntPoint

func (IntPoint) Minus

func (p IntPoint) Minus(other IntPoint) IntPoint

func (IntPoint) Negate

func (p IntPoint) Negate() IntPoint

func (IntPoint) Plus

func (p IntPoint) Plus(other IntPoint) IntPoint

func (IntPoint) ToFloat

func (p IntPoint) ToFloat() FloatPoint

type IntPointIterator

type IntPointIterator interface {
	HasNext() bool
	Next() IntPoint
}

type IntRange

type IntRange struct {
	Start, End int
}

func ZeroIntRange

func ZeroIntRange() IntRange

func (IntRange) Length

func (r IntRange) Length() int

type IntRect

type IntRect struct {
	X, Y, Width, Height int
}

func IntRectAround

func IntRectAround(x, y, radius int) IntRect

func IntRectAroundIntPoint

func IntRectAroundIntPoint(center IntPoint, radius int) IntRect

func IntRectBetween

func IntRectBetween(startX, startY, endX, endY int) IntRect

func IntRectBetweenIntPoint

func IntRectBetweenIntPoint(start, end IntPoint) IntRect

func IntRectFromPoint

func IntRectFromPoint(size IntPoint) IntRect

func (IntRect) Area

func (r IntRect) Area() int

func (IntRect) Bottom

func (r IntRect) Bottom() int

func (IntRect) Center

func (r IntRect) Center() IntPoint

func (IntRect) Intersect

func (r IntRect) Intersect(other IntRect) IntRect

func (IntRect) Iterator

func (p IntRect) Iterator() IntPointIterator

func (IntRect) Left

func (r IntRect) Left() int

func (IntRect) Move

func (r IntRect) Move(delta IntPoint) IntRect

func (IntRect) Right

func (r IntRect) Right() int

func (IntRect) Top

func (r IntRect) Top() int

type List

type List[V any] interface {
	Add(item V) error
	AddAt(index int, item V) error
	Get(index int) (V, error)
	Remove(index int) error
	Size() int
	Iterator() ListIterator[V]
}

type ListIterator

type ListIterator[V any] interface {
	HasNext() bool
	Next() (V, error)
}

type Matrix

type Matrix struct {
	sync.RWMutex
	Width, Height int
	Cells         []float64
}

func NewMatrix

func NewMatrix(width, height int) *Matrix

func NewMatrixFromPoint

func NewMatrixFromPoint(size IntPoint) *Matrix

func (*Matrix) Add

func (m *Matrix) Add(x, y int, value float64)

func (*Matrix) AddPoint

func (m *Matrix) AddPoint(at IntPoint, value float64)

func (*Matrix) CalculateOverlap

func (m *Matrix) CalculateOverlap(other *Matrix) *IntRect

CalculateOverlap calculates the overlapping area between two matrices and returns the overlapping area as a Rectangle.

func (*Matrix) Get

func (m *Matrix) Get(x, y int) float64

func (*Matrix) GetPoint

func (m *Matrix) GetPoint(at IntPoint) float64

func (*Matrix) Multiply

func (m *Matrix) Multiply(x, y int, value float64)

func (*Matrix) MultiplyPoint

func (m *Matrix) MultiplyPoint(at IntPoint, value float64)

func (*Matrix) Set

func (m *Matrix) Set(x, y int, value float64)

func (*Matrix) SetPoint

func (m *Matrix) SetPoint(at IntPoint, value float64)

func (*Matrix) Size

func (m *Matrix) Size() IntPoint

type ReversedList

type ReversedList[V any] struct {
	// contains filtered or unexported fields
}

func NewReversedList

func NewReversedList[V any](items List[V]) *ReversedList[V]

func (*ReversedList[V]) Add

func (l *ReversedList[V]) Add(item V) error

func (*ReversedList[V]) AddAt

func (l *ReversedList[V]) AddAt(index int, item V) error

func (*ReversedList[V]) Get

func (l *ReversedList[V]) Get(index int) (V, error)

func (*ReversedList[V]) Iterator

func (l *ReversedList[V]) Iterator() ListIterator[V]

func (*ReversedList[V]) Remove

func (l *ReversedList[V]) Remove(index int) error

func (*ReversedList[V]) Size

func (l *ReversedList[V]) Size() int

Jump to

Keyboard shortcuts

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