GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - devlsh/quadtree: A lightweight TypeScript quadtree for spatial indexing.

BranchesTags
Open more actions menu

Latest commit

 

History

36 Commits
36 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.openchamber
.openchamber
 
 
.vscode
.vscode
 
 
demo
demo
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.manifest.json
.manifest.json
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
lefthook.yml
lefthook.yml
 
 
oxfmt.config.ts
oxfmt.config.ts
 
 
oxlint.config.ts
oxlint.config.ts
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
release.json
release.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
tsdown.config.ts
tsdown.config.ts
 
 
vitest.config.ts
vitest.config.ts
 
 

Repository files navigation

@devlsh/quadtree

A lightweight TypeScript quadtree for spatial indexing.


NPM Downloads GitHub Stars Build Status Software License


  • Interactive demo.
  • TypeScript generics for custom object types.
  • Single-object and batch insertion.
  • Configurable bounds, tree depth, and subdivision thresholds.
  • Spatial queries for collision candidates.
  • Zero runtime dependencies.

Not sure what a quadtree is or why it helps? Check out "What are quadtrees" on YouTube.


Installation

$ npm install @devlsh/quadtree

Usage

import { Quadtree, type Rect } from '@devlsh/quadtree';

/**
 * If you want custom data (such as an ID) attached to objects, you can pass in a
 * generic based on `Rect`.
 */
interface Entity extends Rect {
  id: string;
}

const tree = new Quadtree<Entity>({
  width: 1024, // World/canvas width.
  height: 1024, // World/canvas height.
  maxDepth: 12, // Limit how many times regions subdivide.
  maxObjects: 15, // Split crowded regions into four; not a hard cap at maxDepth.
});

const object: Entity = {
  id: 'object-1',
  x: 489,
  y: 200,
  width: 20,
  height: 20,
};

const others: Entity[] = [
  { id: 'object-2', x: 460, y: 190, width: 20, height: 20 },
  { id: 'object-3', x: 1000, y: 1000, width: 20, height: 20 },
];

tree.insert(object);
tree.insertAll(others);

/**
 * Candidates are not exact collisions - they are neighboring spatial objects.
 * Retrieval returns each original reference at most once, even across child boundaries.
 * Distinct objects with equal bounds remain separate candidates. TODO: fix this.
 * Apply your own collision check afterward.
 */
const candidates = tree.retrieve({ x: 480, y: 180, width: 100, height: 100 });

/**
 * No update/remove methods: after moving objects, clear and reinsert all current objects.
 */
object.x = 600;
tree.clear();
tree.insertAll([object, ...others]);

Contributing

Report bugs through issues or ask questions in Discussions. Report vulnerabilities privately as described in SECURITY.md.

For local development, pull requests, and other contributions, see the Contributing Guidelines.

License

@devlsh/quadtree is free and open-source software licensed under the MIT License.


devlsh.com  ·  GitHub: @devlsh  ·  X: @itsdevlsh

About

A lightweight TypeScript quadtree for spatial indexing.

devlsh.com

Topics

quadtreespatialspatial-indexspatial-partitioningtypescript

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity

Stars

6 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.