spatial

package
v0.0.0-...-f383209 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bucket

type Bucket[T comparable] struct {
	List []BucketItem[T]
}

func NewBucket

func NewBucket[T comparable]() *Bucket[T]

func (*Bucket[T]) Add

func (b *Bucket[T]) Add(shape phy2.Rect, val T)

func (*Bucket[T]) Check

func (b *Bucket[T]) Check(colSet *CollisionSet[T], shape phy2.Rect)

func (*Bucket[T]) Clear

func (b *Bucket[T]) Clear()

func (*Bucket[T]) Collides

func (b *Bucket[T]) Collides(shape phy2.Rect) bool

func (*Bucket[T]) FindClosest

func (b *Bucket[T]) FindClosest(shape phy2.Rect) (BucketItem[T], bool)

func (*Bucket[T]) Remove

func (b *Bucket[T]) Remove(val T)

type BucketItem

type BucketItem[T comparable] struct {
	// contains filtered or unexported fields
}

type CollisionSet

type CollisionSet[T comparable] struct {
	List []T
}

func NewCollisionSet

func NewCollisionSet[T comparable](cap int) *CollisionSet[T]

func (*CollisionSet[T]) Add

func (s *CollisionSet[T]) Add(t T)

func (*CollisionSet[T]) Clear

func (s *CollisionSet[T]) Clear()

type Hashmap

type Hashmap[T comparable] struct {
	PositionHasher

	Bucket *arrayMap[Bucket[T]]
	// contains filtered or unexported fields
}

-------------------------------------------------------------------------------- TODO: rename? ColliderMap?

func NewHashmap

func NewHashmap[T comparable](chunksize [2]int, startingSize int) *Hashmap[T]

func (*Hashmap[T]) Add

func (h *Hashmap[T]) Add(shape phy2.Rect, val T)

func (*Hashmap[T]) BroadCheck

func (h *Hashmap[T]) BroadCheck(colSet CollisionSet[T], shape phy2.Rect)

Adds the collisions directly into your collision set. This one doesnt' do any narrow phase detection. It returns all objects that collide with the same chunk

func (*Hashmap[T]) Check

func (h *Hashmap[T]) Check(colSet *CollisionSet[T], shape phy2.Rect)

Finds collisions and adds them directly into your collision set

func (*Hashmap[T]) Clear

func (h *Hashmap[T]) Clear()

func (*Hashmap[T]) Collides

func (h *Hashmap[T]) Collides(shape phy2.Rect) bool

func (*Hashmap[T]) FindClosest

func (h *Hashmap[T]) FindClosest(shape phy2.Rect) (T, bool)

func (*Hashmap[T]) GetBucket

func (h *Hashmap[T]) GetBucket(index Index) *Bucket[T]

func (*Hashmap[T]) Remove

func (h *Hashmap[T]) Remove(val T)

Warning: This is a relatively slow operation

type Index

type Index struct {
	X, Y int
}

type PointBucket

type PointBucket[T comparable] struct {
	List []PointBucketItem[T]
}

func NewPointBucket

func NewPointBucket[T comparable]() *PointBucket[T]

func (*PointBucket[T]) Add

func (b *PointBucket[T]) Add(point phy2.Vec, val T)

func (*PointBucket[T]) Clear

func (b *PointBucket[T]) Clear()

type PointBucketItem

type PointBucketItem[T comparable] struct {
	// contains filtered or unexported fields
}

type Pointmap

type Pointmap[T comparable] struct {
	PositionHasher

	Bucket *arrayMap[PointBucket[T]]
	// contains filtered or unexported fields
}

TODO: rename? ColliderMap?

func NewPointmap

func NewPointmap[T comparable](chunksize [2]int, startingSize int) *Pointmap[T]

func (*Pointmap[T]) Add

func (h *Pointmap[T]) Add(pos phy2.Vec, val T)

func (*Pointmap[T]) BroadCheck

func (h *Pointmap[T]) BroadCheck(list []T, bounds phy2.Rect) []T

TODO: Right now this does a broad phased check Adds the collisions directly into your collision list. Items are deduplicated by nature of them only existing once in this Pointmap. (ie if you add multiple of the same thing, you might get multiple out)

func (*Pointmap[T]) Clear

func (h *Pointmap[T]) Clear()

func (*Pointmap[T]) Collides

func (h *Pointmap[T]) Collides(bounds phy2.Rect) bool

TODO: This only does a broadphase check. no narrow phase Returns true if the bounds collides with anything

func (*Pointmap[T]) GetBucket

func (h *Pointmap[T]) GetBucket(index Index) *PointBucket[T]

func (*Pointmap[T]) NarrowCheck

func (h *Pointmap[T]) NarrowCheck(list []T, bounds phy2.Rect) []T

TODO: I think I'd rather the default for this be called "Check" then have the other be called CheckBroad or something

type PositionHasher

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

--------------------------------------------------------------------------------

func NewPositionHasher

func NewPositionHasher(size [2]int) PositionHasher

func (*PositionHasher) PositionToIndex

func (h *PositionHasher) PositionToIndex(pos phy2.Vec) Index

Jump to

Keyboard shortcuts

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