zearches

module
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT

README

zearches

Go Report Card Go Reference Tests

Zearches is a simple spatial segmentation/search toolkit that includes Octree, Quadtree, Rtree. It can be used to implement AOI, such as vision management in game projects, and also provides simple intersection detection

RoadMap

  • Octree
  • Quadtree
  • Rtree
  • simple intersection detection, but it is coming soon

octree

octree

quadtree

quadtree

Installation

go get -u github.com/cozmo-zh/zearches

Usage

func main() {
    // create an octree
    otree, _ := zearches.CreateOctree(
        bounds.NewBound(
            geo.NewVec3Int(0, 0, 0), geo.NewVec3Int(100, 100, 100)), // bound, required
            1,                          // maxDepth, required
            1,                          // capacity, required
            zearches.WithMergeIf(true), // Flag to determine if nodes should be merged when removing an entity , optional, default is false
            zearches.WithScale(func(v []float32) geo.Vec3Int {
                return geo.NewVec3Int(int32(v[0]), int32(v[1]), int32(v[2]))
            }), // Function to scale float32 slice to geo.Vec3Int , optional, default is identity function
    )
    
	otree.GetSurroundingEntities(
		[]float32{1, 1, 1}, 10, 
	    func(entity siface.ISpatial) bool {
            return entity.GetID() == 999
    })
    
    // create a quadtree
    qtree, _ := zearches.CreateQuadtree(
        bounds.NewBound(geo.NewVec3Int(0, 0, 0), geo.NewVec3Int(100, 100, 100)), // bound, required
        1, // maxDepth, required
        1, // capacity, required
    )
    qtree.Remove(999)
}

Visualization

    quadtree, _ := zearches.CreateQuadtree(
            //...                   
            zearches.WithDrawPath("${workspace}/dot"), // path to save dot file, optional, default is empty
    )
		
   // ...
   err := quadtree.ToDot() // it will generate a dot file in the path you specified

if you want to visualize the octree, you can use the following command to generate the dot file, then generate the image file by using the graphviz tool

install graphviz

download

generate image file
dot -Tjpg -o quadtree.jpg quadtree.dot

quadtree

Directories

Path Synopsis
Package consts .
Package consts .
internal
pkg/tree
Package tree .
Package tree .
pkg/tree/mocks
Package mocks .
Package mocks .
pkg/tree/octree
Package octree provides an implementation of an octree data structure for spatial partitioning.
Package octree provides an implementation of an octree data structure for spatial partitioning.
pkg/tree/option
Package option .
Package option .
pkg/tree/quadtree
Package quadtree provides an implementation of a quadtree data structure for spatial partitioning.
Package quadtree provides an implementation of a quadtree data structure for spatial partitioning.
pkg/tree/rtree
Package rtree .
Package rtree .
pkg/tree/treenode
Package treenode .
Package treenode .
pkg
bounds
Package bounds provides the implementation of spatial boundaries.
Package bounds provides the implementation of spatial boundaries.
geo
Package geo .
Package geo .
siface
Package siface .
Package siface .
zearches
Package zearches provides functions to create and manage spatial partitioning structures like octrees and quadtrees, etc.
Package zearches provides functions to create and manage spatial partitioning structures like octrees and quadtrees, etc.
Package util provides utility functions for distance calculations.
Package util provides utility functions for distance calculations.

Jump to

Keyboard shortcuts

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