GithubHelp home page GithubHelp logo

krisgray / rtree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imbcmdth/rtree

2.0 3.0 1.0 541 KB

An OO R-Tree Library for Javascript/Typescript

License: MIT License

CSS 4.31% JavaScript 61.08% HTML 2.92% TypeScript 31.70%

rtree's Introduction

RTree

A non-recursive R-Tree library for 2D rectangles in pure JavaScript with no dependencies. This library has been refactored by Kristian Gray https://github.com/KrisGray into typescript and utilises OO principals.

Below is a graphical example of a a 2D RTree:

Example of a 2D RTree

This library can now be installed via npm with the following command:

npm install --save https://github.com/HGNC/RTree.git#release

How to use:

// create a new rtree object
const rt = new RTree();

// insert root rectangle and sub rectangles
const rects = [
  { x: 1, y: 1, w: 4, h: 4 },
  { x: 2, y: 3, w: 1, h: 1 },
  { x: 3, y: 2, w: 1, h: 1 },
  { x: 6, y: 4, w: 1, h: 1 },
  { x: 4, y: 1, w: 2, h: 1 }
];
for (let i=0; i<rects.length; i++){
  rt.insert(rects[i], `store obj ${i}`);
}

// Search for rectangles (rTrees.length === 4)
const rTrees: RTree[] = rt.search({
  x: 1, y: 1, w: 4, h: 4
});

// remove rectangles (rmRTrees.length === 3)
const rmRTrees: RTrees[] = rt.remove({
  x: 1, y: 1, w: 3, h: 4
});

// rt.nodes.length === 2

rtree's People

Contributors

krisgray avatar imbcmdth avatar

Stargazers

దామోదర avatar Kamil Slowikowski avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

hgnc

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.