Git Product home page Git Product logo

quadtree's People

Contributors

asim avatar ronanj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

quadtree's Issues

KNearest returns empty slice for big values of k

If k is bigger than the actual object count within the search rectangle (or the whole tree?), KNearest returns an empty slice in all of my experiments.
By reducing k to a smaller value, we get the correct results.

See pull-request for a fix for this.

Best regards,
Maurice

License

What is the license of quadtree please?

.depth is never updated

I noticed that QuadTree.depth is never updated. So MaxDepth never comes in to play.

QuadTree.divide() simply sets the new depths to the same as the parent:

qt.nodes[0] = New(bb, qt.depth, qt)

KNearest return not in dist order?

Hi, thanks for the quadtree codes and it’s very fast for many points query.

However I wrote a simple program, and found the qtree.KNearest didn’t return in dist order:

package main

import (
	"fmt"
	"log"

	"github.com/asim/quadtree"
)

func main() {

	centerPoint := quadtree.NewPoint(0.0, 0.0, nil)
	halfPoint := quadtree.NewPoint(90.0, 180.0, nil)
	boundingBox := quadtree.NewAABB(centerPoint, halfPoint)

	qtree := quadtree.New(boundingBox, 0, nil)
	points := []struct {
		Lng float64
		Lat float64
		ID  string
	}{
		{
			Lng: 116.2748,
			Lat: 39.9989,
			ID:  "yi-he-yuan",
		},
		{
			Lng: 116.3202,
			Lat: 39.9166,
			ID:  "yu-yuan-tan",
		},
		{
			Lng: 116.3905,
			Lat: 39.9285,
			ID:  "bei-hai",
		},
	}
	for _, point := range points {
		if !qtree.Insert(quadtree.NewPoint(point.Lat, point.Lng, point.ID)) {
			log.Fatal("Failed to insert the point")
		}
	}

	center := quadtree.NewPoint(39.9289, 116.3883, nil)
	distance := 10000.0 /* Distance to the center point in meters */
	bounds := quadtree.NewAABB(center, center.HalfPoint(distance))

	maxPoints := 3
	for _, point := range qtree.KNearest(bounds, maxPoints, nil) {
		fmt.Printf("Found point: %s\n", point.Data().(string))
	}
}

Output:

Found point: yi-he-yuan
Found point: yu-yuan-tan
Found point: bei-hai

Expect:

Found point: bei-hai
Found point: yu-yuan-tan
Found point: yi-he-yuan

Is that expect? If so how can set return order?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.