Git Product home page Git Product logo

qtree's People

Contributors

asaarinen avatar martindrapeau 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  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

qtree's Issues

update method

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.

Update errors and fixes

  1. When updating an object, you might want to remove and add it back to the tree when it is out of the node's boundary. The conditions you check to do this need to be fixed. In specific, in the update function, (orig.x > node.x + node.w || orig.y > node.y + node.h || orig.x + orig.w < node.x || orig.y + orig.h < node.y ) should be (orig.x >= node.x + node.w || orig.y >= node.y + node.h || orig.x + orig.w <= node.x || orig.y + orig.h <= node.y ). I came across this issue when the new updated object is supposed to be in a node leaf, but the conditions keep it in a node child, which prevents you from updating or removing the object in the future.
  2. Please fix the missing parameter 'updatedcoords' in the recursive call of update function as someone already pointed out.

buffer is not working?

The same data is returned whether i specify a buffer in const results = qt.get(xywh, buffer); or not.

error in updating

Hello, i suspect that you forgot to pass the parameter updatedcoords in the recursive call of update function on line 256.

Remove method

Like this API over many of the quadtrees out there - Any plans for a remove method?

Seems to fail simple test

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

Line segment tests return all objects?

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)

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.