spatial

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2021 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 Globals

type Globals struct {
	Cap int
	// contains filtered or unexported fields
}

Globals stored data shared by all tree nodes

type MinHash

type MinHash struct {
	Nodes [][]Node
	// contains filtered or unexported fields
}

MinHash is for efficient spatial hasher, tuned to perfection is able to handle thousands of entities for cost of using ids and limited space, if you will be dealing with concentrated entity use this over

func NMinHash

func NMinHash(w, h int, tileSize mat.Vec) *MinHash

NMinHash is MinHash constructor

func (*MinHash) Adr

func (h *MinHash) Adr(pos mat.Vec) mat.Point

Adr returns node, position belongs to

func (*MinHash) Insert

func (h *MinHash) Insert(adr *mat.Point, pos mat.Vec, id, group int)

Insert adds shape to MinHash

func (*MinHash) Query

func (h *MinHash) Query(rect mat.AABB, coll *[]int, group int, including bool)

Query returns colliding shapes with given rect

func (*MinHash) Remove

func (h *MinHash) Remove(adr *mat.Point, id, group int) bool

Remove removes shape from MinHash. If operation fails, false is returned

func (*MinHash) TileSize

func (h *MinHash) TileSize() mat.Vec

TileSize ...

func (*MinHash) Update

func (h *MinHash) Update(old *mat.Point, pos mat.Vec, id, group int) bool

Update updates state of object if it changed quadrant, if operation fails, false is returned

type Node

type Node struct {
	Count int
	Sets  []Set
}

Node keeps over all count of ids in sets for quick lookup Its a main building piece of hasher, as we do not expect big amounts of entities in a single node it does not use maps to store ids witch is not that elegant but fatser

func (*Node) Collect

func (n *Node) Collect(group int, include bool, coll *[]T)

Collect retrieve ids from a node to coll, if include is true only ids of given group will get collected, otherwise ewerithing but specified group is returned

func (*Node) CollectAll

func (n *Node) CollectAll(coll *[]T)

CollectAll colects all objects withoud differentiating a group

func (*Node) Insert

func (n *Node) Insert(id T, group int)

Insert ...

func (*Node) Remove

func (n *Node) Remove(id T, group int) bool

Remove panics if id does not exist within the node, you always have to make sure you are removing correctly as leaving dead ids in a hasher is leaking of memory

method panics if object you tried to remove is not present to remove

type Set

type Set struct {
	Group int
	IDs   []T
}

Set is an id set that also has a group important for node

type Set22

type Set22 struct {
	Group int
	IDs   []TreeEntity
}

Set22 is an id set that also has a group important for node

type T

type T = int

T is template parameter

type TNode

type TNode struct {
	Count int
	Sets  []Set22
}

TNode keeps over all count of ids in sets for quick lookup Its a main building piece of hasher, as we do not expect big amounts of entities in a single node it does not use maps to store ids witch is not that elegant but fatser

func (*TNode) Collect

func (n *TNode) Collect(group int, include bool, coll *[]TreeEntity)

Collect retrieve ids from a node to coll, if include is true only ids of given group will get collected, otherwise ewerithing but specified group is returned

func (*TNode) CollectAll

func (n *TNode) CollectAll(coll *[]TreeEntity)

CollectAll colects all objects withoud differentiating a group

func (*TNode) Insert

func (n *TNode) Insert(id TreeEntity, group int)

Insert ...

func (*TNode) Remove

func (n *TNode) Remove(id TreeEntity, group int) bool

Remove panics if id does not exist within the node, you always have to make sure you are removing correctly as leaving dead ids in a hasher is leaking of memory

method panics if object you tried to remove is not present to remove

type Tree

type Tree struct {
	*Globals
	TNode

	Bounds          mat.AABB
	Ch              []Tree
	Branch, NotRoot bool
}

Tree is a quadtree that prefers updating over reinseting. If you have to detect collizions between big amount of objects with variety of shape sizes this is a good pick, use hasher instead if you are using lot of same sized objects

Tree has to be initialized with NTree as Tree.Globals is pointer

Tree is not fully tested feature

func NTree

func NTree(cap int, bounds mat.AABB) *Tree

NTree returns ready to use tree

func (*Tree) Bail

func (t *Tree) Bail()

Bail retrives all objects from TNode into coll

func (*Tree) FormatDebug

func (t *Tree) FormatDebug(depth int) string

FormatDebug makes a readable formatting of tree structure

func (*Tree) Insert

func (t *Tree) Insert(te TreeEntity) bool

Insert inserts entity to tree, returns false if entity cannot be inserted

func (*Tree) Query

func (t *Tree) Query(group int, include bool, coll *[]TreeEntity, area mat.AABB)

Query returns all entities that can intersect with area, if include is false only entities with different group are returned, othervise entities with sam group are returned, using QueryAll if you don't need all groups and filtering them your self is slower as Quadterr si structured to optimize the process

func (*Tree) QueryAll

func (t *Tree) QueryAll(coll *[]TreeEntity, area mat.AABB)

QueryAll returns all Entities that area can intersect with

func (*Tree) Remove

func (t *Tree) Remove(te TreeEntity) bool

Remove removes the entity, if there is no such entity, false is returned

func (*Tree) Split

func (t *Tree) Split()

Split allocates Quadtree children

func (*Tree) TotalCount

func (t *Tree) TotalCount() (total int)

TotalCount returns total count of children in Tree

func (*Tree) Update

func (t *Tree) Update() (count int)

Update does two things, it moves

type TreeEntity

type TreeEntity interface {
	// Bounds returns bounding rectangle
	Bounds() mat.AABB
	// Group returns a entity group
	Group() int
	// Dead returns whether entity should be removed
	Dead() bool
}

TreeEntity represents insertabel data for Tree

Jump to

Keyboard shortcuts

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