npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtree

v1.4.2

Published

rtree library for javascript

Downloads

8,340

Readme

#rTree Build Status

A non-recursive R-Tree library in pure JavaScript with no dependencies. Fork of Jon-Carlos Rivera's fantastic library which sadly seems not to be maintained. MIT Licensed.

##So far:

  • Bug fix when deleting points.
  • Common.js module.
  • Updated tests.
  • Factory function for constructor.
  • Method for dealing with GeoJSON.
  • All methods now accept callbacks.
  • Query by bbox instead of rectangle.
  • Submit to NPM.
  • Update examples.
  • add closure
  • add GruntFile
  • fix syntax (make it pass jslint)
  • more modular
  • that bug with deleting

##API

  • RTree ( [ Number max_node_width, Function callback ] )

###Parameters:

  • max_node_width : optional : The maximum width of a node before a split is performed1.

###Returns:

  • An empty rTree object.

###Usage:

  • Make a new rTree with a max node width of 10:
  • var myRTree = RTree(10);

##rTree.insert

  • rTree.insert ( Rectangle3 bounds, Object element)

###Parameters:

  • bounds : required : A minimally bounding box for element.
  • element : required : An object to add to the R-Tree.

###Returns:

  • True.

###Usage:

  • Insert a 10x10 object that starts at position 10x10:
  • myRTree.insert({x:10, y:10, w:10, h:10}, myObject);

##rTree.remove

  • rTree.remove ( Rectangle3 area _[, Object element)

###Parameters:

  • area : required : An area to search within.
  • element : optional : An object to remove from the R-Tree. If no object is specified, all elements that touch area are deleted.

###Returns:

  • An array of leafs deleted from the R-Tree.

###Usage:

  • Deletes all object that touch the 10x10 rectangle starting at position 10x10:
  • var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10});
  • Delete only specific object if it touches the 10x10 rectangle starting at position 10x10:
  • var myDelCount = myRTree.delete({x:10, y:10, w:10, h:10}, specific_object);

##rTree.geoJSON:

  • rTree.geoJSON ( Object or Array geoJSON)

###Parameters

  • geoJSON : required : Either an Object representing a GeoJSON feature collection or an Array representing a list of GeoJSON features.

###Usage:

myRTree.geoJSON({
	"type":"FeatureCollection",
	"features":[
		{
			"type":"Feature",
			"geometry":{
				"type":"Point",
				"coordinates":[100,1]
			},
			"properties":{
				"prop0":"value0"
			}
		},
		{
			"type":"Feature",
			"geometry":{
				"type":"LineString",
				"coordinates":[
					[100,0],
					[101,1]
				]
			},
			"properties":{
				"prop0":"value0"
			}
		}
	]
});

##rTree.bbox:

  • rTree.bbox ( Bounds area)

###Parameters

  • area : required : Area to search, this can either be represented by a single parameter bounds array [[x1,y1],[x2,y2]], two parameters representing the southwest and northeast corners [x1,y1],[x2,y2], or 4 parameters of [x1,y1,x2,y2].

###Returns:

  • An array of matched features.

###Usage:

  • Search a 10x10 area that starts at position 10x10 (these are all equivalent):
  • var myObjects1 = myRTree.bbox([[10,10],[20,20]]);
  • var myObjects2 = myRTree.bbox([[10,10],[20,20]]);
  • var myObjects3 = myRTree.bbox([10,10],[20,20]);
  • var myObjects4 = myRTree.bbox([10,10],[20,20]);
  • var myObjects5 = myRTree.bbox(10,10,20,20);
  • var myObjects6 = myRTree.bbox(10,10,20,20);

##rTree.search

  • RTree.search ( Rectangle3 area [, Boolean return node, Array return_array ])

###Parameters:

  • area : required : An area to search within.
  • return node : optional : Whether to return the entire node, mainly internal option.
  • return array : optional : An existing array to add the results to, defaults to [], mainly internal option.

###Returns:

  • An array of objects that overlap or touch area.

###Usage:

  • Search a 10x10 area that starts at position 10x10:
  • var myObjects = myRTree.search({x:10, y:10, w:10, h:10});

###Notes

1 Default max node width is currently 6.

3 A Rectangle is any object with public x, y, w, h properties. The object itself is not saved or used directly but copies are made of its x, y, w, h properties.