spatial

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxRange float64 = 4.0

MaxRange is using for automatically adding the new node in AddItem

Functions

This section is empty.

Types

type Bounds

type Bounds struct {
	X      float64
	Y      float64
	Width  float64
	Height float64
	Item   Item
}

Bounds - A bounding box with a x,y origin and width and height

func (Bounds) GetId added in v1.1.1

func (bound Bounds) GetId() string

func (*Bounds) Intersects

func (b *Bounds) Intersects(a Bounds) bool

Intersects - Checks if a Bounds object intersects with another Bounds

func (*Bounds) IsPoint

func (b *Bounds) IsPoint() bool

IsPoint - Checks if a bounds object is a point or not (has no width or height)

func (Bounds) Location

func (bound Bounds) Location() r2.Point

type Circle

type Circle struct {
	Location r2.Point
	Radius   float32
}

func NewCircle

func NewCircle() *Circle

type Item

type Item interface {
	GetId() string
	Location() r2.Point
}

type Quadtree

type Quadtree struct {
	Bounds     Bounds
	MaxObjects int // Maximum objects a node can hold before splitting into 4 subnodes
	MaxLevels  int // Total max levels inside root Quadtree
	Level      int // Depth level, required for subnodes
	Objects    []Bounds
	Nodes      []Quadtree
	Total      int
}

Quadtree - The quadtree data structure

func (*Quadtree) Clear

func (qt *Quadtree) Clear()

Clear - Clear the Quadtree

func (*Quadtree) Insert

func (qt *Quadtree) Insert(pRect Bounds) (q *Quadtree)

Insert - Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.

func (*Quadtree) RemoveItem added in v1.1.1

func (qt *Quadtree) RemoveItem(item Item)

func (*Quadtree) Retrieve

func (qt *Quadtree) Retrieve(pRect Bounds) []Bounds

Retrieve - Return all objects that could collide with the given object

func (*Quadtree) RetrieveIntersections

func (qt *Quadtree) RetrieveIntersections(find Bounds) []Bounds

RetrieveIntersections - Bring back all the bounds in a Quadtree that intersect with a provided bounds

func (*Quadtree) RetrievePoints

func (qt *Quadtree) RetrievePoints(find Bounds) []Bounds

RetrievePoints - Return all points that collide

func (*Quadtree) TotalNodes

func (qt *Quadtree) TotalNodes() int

TotalNodes - Retrieve the total number of sub-Quadtrees in a Quadtree

type RTree

type RTree struct {
	Ancestor   *RTree
	Descendant []*RTree
	Items      []Item
	Rect       r2.Rect
	MaxItem    int
	// contains filtered or unexported fields
}

RTree representation a tree for spatial indexing which improve the time for searching a location in space

func NewRTree

func NewRTree() *RTree

Create new pointer RTree

func (*RTree) AddItem

func (rt *RTree) AddItem(item Item) error

The AddItem adds a new item to the tree. automatically create new RTree to hold this item if these are no RTree near the item in MaxRange AddItem helps to automatically scale the tree and find the right tree for grouping

func (*RTree) AddTree

func (r *RTree) AddTree(l *RTree) error

AddTree new RTree to current Tree, the left tree will be descendant of the right tree and the right tree will be the ancestor of the left tree. An error will be returned in case the left tree is nil or the left tree is already been the descendant of the right.

func (*RTree) Contains

func (rt *RTree) Contains(item Item) *RTree

Find the Tree which is holding finding item The smallest tree will be returned if found otherwise the return value will be nil

func (RTree) Distance

func (r RTree) Distance(p r2.Point) float64

Get the distance between two RTree Location is measure by center of two RTree

func (*RTree) Find

func (rt *RTree) Find(condition func(tree *RTree) bool) []RTree

Find all RTree which are matched with the condition

func (*RTree) InRange

func (rt *RTree) InRange(location r2.Point, max_range float64) []*RTree

InRange find trees which are not further than the max range with the location Items in the tree are potential to be the item in the range

func (RTree) Level

func (rt RTree) Level() int

func (*RTree) Nearest

func (rt *RTree) Nearest(location r2.Point, max_range float64) *RTree

Nearest find the nearest RTree in Descendant which is in max_range from the location nil will be returned if there are no RTree

func (*RTree) RemoveItem added in v1.1.3

func (rt *RTree) RemoveItem(item Item)

func (*RTree) UpdateRect

func (rt *RTree) UpdateRect()

UpdateRect modify the Rect the size and affect to the Rect of Ancestor UpdateRect should be used for automatically updating size of Rect

Jump to

Keyboard shortcuts

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