GithubHelp home page GithubHelp logo

quadtree's Introduction

quadtree


Installation

$ git clone && cd
$ make
$ make install

Usage

#include <stdio.h>
#include <quadtree.h>

int main() {
  int val = 10;
  quadtree_t *tree = quadtree_new(0, 0, 10, 10);
  quadtree_insert(tree, 1, 1, 1, &val);
  quadtree_insert(tree, 2, 2, 2, &val);
  quadtree_insert(tree, 3, 3, 3, &val);

  printf("tree length: %d\n", tree->length);

  return 0;
}

Finds in tree:

result_node_t *head, *cur;

void within_callback(point_t *point) {
  printf("%d\n", point->x);
}

quadtree_within(tree->root, bbox, within_callback);

Walks in tree:

void ascent(node_t *node) {
  if (node && node->point) {
    printf("%d\n", node->point->x);
  }
}

void descent(node_t *node) {
  if (node && node->point) {
    printf("%d\n", node->point->x);
  }
}

quadtree_walk(tree->root, &ascent, &descent);

Reference:

// Create new tree and return pointer
quadtree_t *
quadtree_new(double minx, double miny, double maxx, double maxy)

// Insert point to the tree and return point pointer
point_t *
quadtree_insert(quadtree_t *tree, double x, double y, void *key, bool update)

// Search if tree has point and return point pointer
point_t *
quadtree_search(quadtree_t *tree, double x, double y)

// Destroy tree
void
quadtree_free(quadtree_t *tree)

// Walks in tree, works like each for points
void
quadtree_walk(node_t *root, void (*descent)(node_t *node),
                            void (*ascent)(node_t *node))

// Find points in bbox
void
quadtree_within(node_t *root, bounds_t *bounds, within_callback_t cb)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make changes
  4. make test benchmark
  5. Commit your changes (git commit -am 'add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

quadtree's People

Contributors

artemeff avatar sw897 avatar

Stargazers

Chikee avatar  avatar

Watchers

James Cloos avatar

Forkers

hl0071

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.