Skip to content

Gambler13/quadtree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go Quadtree implementation

Usage

func Example() {

	//Set tree bounds
	bounds := NewRect(11, 13, 1307, 1567)

	//Create new tree
	qt := NewTree(bounds)

	//Insert values
	for i := 0; i < 500; i++ {
		qt.Insert(Value{
			//Set position of values
			Point: Point{
				X: rand.Float64()*bounds.Width + bounds.X,
				Y: rand.Float64()*bounds.Height + bounds.Y,
			},
			//Add payload if necessary, for example an ID
			Data: rand.Int(),
		})
	}

	//Define 2D query range
	query := NewRect(229, 461, 631, 181)

	//Query tree
	results := qt.Retrieve(query)

	fmt.Printf("Results (%d):\n", len(results))
	for i := range results {
		fmt.Printf("%+v\n", results[i])
	}
}

About

Golang implementation of a Quadtree

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages