spatial

package
v0.0.0-...-807e10e Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 4 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 Shape, val T)

func (*Bucket[T]) Check

func (b *Bucket[T]) Check(colSet *CollisionSet[T], shape Shape)

func (*Bucket[T]) Clear

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

func (*Bucket[T]) Collides

func (b *Bucket[T]) Collides(shape Shape) bool

func (*Bucket[T]) FindClosest

func (b *Bucket[T]) FindClosest(shape Shape) (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 Shape, val T)

func (*Hashmap[T]) BroadCheck

func (h *Hashmap[T]) BroadCheck(colSet CollisionSet[T], rect glm.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 Shape)

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(rect glm.Rect) bool

Returns true if the rect collides with anything in the hashmap

func (*Hashmap[T]) FindClosest

func (h *Hashmap[T]) FindClosest(rect glm.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 glm.Vec2, val T)

func (*PointBucket[T]) Clear

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

func (*PointBucket[T]) Length

func (b *PointBucket[T]) Length() int

func (*PointBucket[T]) Remove

func (b *PointBucket[T]) Remove(point glm.Vec2, val T)

func (*PointBucket[T]) RemoveCollides

func (b *PointBucket[T]) RemoveCollides(bounds glm.Rect)

Remove every point that collides with the bucket

func (*PointBucket[T]) RemoveIndex

func (b *PointBucket[T]) RemoveIndex(idx int)

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 glm.Vec2, val T)

func (*Pointmap[T]) AllIndexesInside

func (h *Pointmap[T]) AllIndexesInside(rect glm.Rect) iter.Seq[Index]

Iterates through all buckets inside the rectangle

func (*Pointmap[T]) BroadCheck

func (h *Pointmap[T]) BroadCheck(list []T, bounds glm.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 glm.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 glm.Rect) []T

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

func (*Pointmap[T]) Remove

func (h *Pointmap[T]) Remove(pos glm.Vec2, val T)

func (*Pointmap[T]) RemoveCollides

func (h *Pointmap[T]) RemoveCollides(bounds glm.Rect)

Remove every point that collides with the supplied bounds

type PositionHasher

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

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

func NewPositionHasher

func NewPositionHasher(size [2]int) PositionHasher

func (*PositionHasher) IndexToRect

func (h *PositionHasher) IndexToRect(index Index) glm.Rect

func (*PositionHasher) PositionToIndex

func (h *PositionHasher) PositionToIndex(pos glm.Vec2) Index

type Shape

type Shape struct {
	Type    ShapeType
	Bounds  glm.Rect    // The bounding AABB
	Vectors [4]glm.Vec2 // Vector data which is stored differently depending on the shape type
}

func AABB

func AABB(rect glm.Rect) Shape

func Rect

func Rect(r glm.Rect, mat glm.Mat4) Shape

func (Shape) Intersects

func (s Shape) Intersects(s2 Shape) bool

type ShapeType

type ShapeType uint8
const (
	ShapeAABB ShapeType = iota // A rectangle, not rotated nor scaled
	ShapeRect                  // Can be rotated or scaled

)

TODO: Tagged Union?

Jump to

Keyboard shortcuts

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