asaarinen / qtree Goto Github PK
View Code? Open in Web Editor NEWSimple JavaScript quadtree
License: MIT License
Simple JavaScript quadtree
License: MIT License
Creating a tree with a million elements takes 3secs on my PC with current qtree version while it only took 0.5sec to version v0.1.2.
Like this API over many of the quadtrees out there - Any plans for a remove method?
I analyzed code and I noticed that algorithm does not remove node even if it's empty. Is it proper behaviour?
Hello, i suspect that you forgot to pass the parameter updatedcoords
in the recursive call of update
function on line 256.
Code to reproduce:
var qt = new QuadTree(0, 0, 100, 100);
qt.put({x: 200, y: 200, w: 50, h: 50, string: 'myId2'});
qt.put({x: 50, y: 50, w: 50, h: 50, string: 'myId1'});
qt.put({x: 101, y: 50, w: 5, h: 5, string: 'myId3'});
qt.put({x: 200, y: 500, w: 50, h: 50, string: 'myId4'});
qt.get({x:55, y: 55, w: 10, h: 10}, function(a) {
console.log('should be myId1', a);
});
qt.get({x:190, y: 490, w: 100, h: 100}, function(a) {
console.log('should be nothing');
});
Always return id2
I've been using methods remove and add to perform an update. The use case for this is when an object has moved (i.e. a sprite changes position). Would be nice to have an optimized update method.
The same data is returned whether i specify a buffer in const results = qt.get(xywh, buffer);
or not.
For some reason, when dealing with line segments using get()
, all objects are returned. I'm thinking maybe I am misunderstanding what using a line segment actually does, but it definitely is not what I would expect.
Code example (es6):
import QuadTree from 'simple-quadtree'
let quadTree = QuadTree(0, 0, 100000, 100000)
// This should be the only collision
quadTree.put({x: 10, y: 10, w: 4, h: 4, obj: 'Yay'})
// Far away objects
quadTree.put({x: 200, y: 200, w: 4, h: 4, obj: 'Boo 1'})
quadTree.put({x: 300, y: 100, w: 4, h: 4, obj: 'Boo 2'})
// Here is where my confusion lies: all objects are returned instead of just the first one
let collisions = quadTree.get({x: 1, y: 11, dx: 1, dy: 0})
console.log('Quadtree Tests:')
console.log(collisions)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.