{"id":21025613,"url":"https://github.com/robertcorponoi/superquad","last_synced_at":"2025-03-13T18:27:17.691Z","repository":{"id":53777868,"uuid":"186179625","full_name":"robertcorponoi/superquad","owner":"robertcorponoi","description":"A modern quadtree for modern games and projects","archived":false,"fork":false,"pushed_at":"2021-03-14T20:27:21.000Z","size":240,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T11:49:13.040Z","etag":null,"topics":["bounds","collision","quadtree"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertcorponoi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-11T20:43:27.000Z","updated_at":"2021-03-15T02:02:23.000Z","dependencies_parsed_at":"2022-09-10T21:01:57.935Z","dependency_job_id":null,"html_url":"https://github.com/robertcorponoi/superquad","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertcorponoi%2Fsuperquad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertcorponoi%2Fsuperquad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertcorponoi%2Fsuperquad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertcorponoi%2Fsuperquad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertcorponoi","download_url":"https://codeload.github.com/robertcorponoi/superquad/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243457213,"owners_count":20294013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bounds","collision","quadtree"],"created_at":"2024-11-19T11:34:50.835Z","updated_at":"2025-03-13T18:27:17.670Z","avatar_url":"https://github.com/robertcorponoi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"250\" height=\"250\" src=\"https://github.com/robertcorponoi/graphics/blob/master/superquad/superquad-logo.png?raw=true\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eSuperquad\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eSuperquad is yet another quadtree implementation for JavaScript that hopes to provide some additional functionality on top of standard quadtree implementations.\u003cp\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  [![NPM version](https://img.shields.io/npm/v/superquad.svg?style=flat)](https://www.npmjs.com/package/superquad)\n  [![Known Vulnerabilities](https://snyk.io/test/github/robertcorponoi/superquad/badge.svg)](https://snyk.io/test/github/robertcorponoi/superquad)\n  ![npm](https://img.shields.io/npm/dt/superquad)\n  [![NPM downloads](https://img.shields.io/npm/dm/superquad.svg?style=flat)](https://www.npmjs.com/package/superquad)\n  \u003ca href=\"https://badge.fury.io/js/superquad\"\u003e\u003cimg src=\"https://img.shields.io/github/issues/robertcorponoi/superquad.svg\" alt=\"issues\" height=\"18\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://badge.fury.io/js/superquad\"\u003e\u003cimg src=\"https://img.shields.io/github/license/robertcorponoi/superquad.svg\" alt=\"license\" height=\"18\"\u003e\u003c/a\u003e\n  [![Gitter](https://badges.gitter.im/gitterHQ/gitter.svg)](https://gitter.im/robertcorponoi)\n\n\u003c/div\u003e\n\n## **Install**\n\nSuperquad is offered as both a Node package and an ES6 module. To download Superquad through npm, use:\n\n```bash\n$ npm install superquad\n```\n\nand to use it, you can either require it or import it if you're in a browser environment:\n\nIn Node.js:\n```js\nconst Superquad = require('superquad');\n```\n\nIn a browser environment:\n```js\n// Browser\nimport Superquad from 'node_modules/superquad/superquad.js';\n\n// Webpack\nimport Superquad from 'superquad';\n```\n\n## **Usage**\n\nTo create a new instance of Superquad, you have to supply at minimum the width and height of the quadtree:\n\n```js\nconst dimensions = {\n  width: 1024,\n  height: 768\n};\n\nconst superquad = new Superquad(dimensions);\n```\n\nNow let's say you want to customize Superquad further and adjust the number of objects a quad can hold before it splits:\n\n```js\nconst dimensions = {\n  width: 1024,\n  height: 768\n};\n\nconst options = {\n  maxObjects: 20\n};\n\nconst superquad = new Superquad(dimensions, options);\n```\n\nThe complete layout of initialization parameters is as follows:\n\n| param      \t        | type   \t| description                                                             \t                                                 | default \t|\n|-------------------\t|--------\t|--------------------------------------------------------------------------------------------------------------------------- |---------\t|\n| bounds              | Object  |                                                                                                                            |          |\n| bounds.x            | number  | The x position of the top left point of the quad. This should only be set if you're working with negative position values. | 0        |\n| bounds.y            | number  | The y position of the top left point of the quad. This should only be set if you're working with negative position values. | 0        |\n| bounds.width        | number  | The width of the quadtree.                                                                                                 |          |\n| bounds.height       | number  | The height of the quadtree.                                                                                                |          |\n| options             |         |                                                                                                                            |          |\n| options.maxObjects \t| number \t| The amount of objects a quad can hold before it splits into 4 sub-quads \t                                                 | 10      \t|\n| options.maxLevels  \t| number \t| The number of sub-quads a quad can have.                                \t                                                 | 4       \t|\n\n## **API**\n\n### **add**\n\nAdds an object to the quadtree by specifying the space that it occupies.\n\n| param         \t| type   \t| description                     \t| default \t|\n|---------------\t|--------\t|---------------------------------\t|---------\t|\n| bounds        \t| Object \t| The bounds of the object to add \t|         \t|\n| bounds.x      \t| number \t| The x position of the object    \t|         \t|\n| bounds.y      \t| number \t| The y position of the object    \t|         \t|\n| bounds.width  \t| number \t| The width of the object         \t|         \t|\n| bounds.height \t| number \t| The height of the object        \t|         \t|\n\nSo to add an object to the quadtree at (150, 200) with a width of 50 and a height of 75, you would do:\n\n```js\nsuperquad.add({ x: 150, y: 200, width: 50, height: 75 });\n```\n\nNow because it takes an object of bounds specification, if your game objects automatically include this information you can just add the whole game object. However, when retrieving objects from the quadtree all of the extra data will not be present.\n\n### **get**\n\nGets any objects that are in the same sub-quad as the provided bounds. These are not guaranteed to be collisions so you will have to check for collisions manually.\n\n| param         \t| type   \t| description                     \t      | default \t|\n|---------------\t|--------\t|---------------------------------------- |---------\t|\n| bounds        \t| Object \t| The bounds to check for nearby objects\t|         \t|\n| bounds.x      \t| number \t| The x position of the bounds    \t      |         \t|\n| bounds.y      \t| number \t| The y position of the bounds    \t      |         \t|\n| bounds.width  \t| number \t| The width of the bounds         \t      |         \t|\n| bounds.height \t| number \t| The height of the bounds        \t      |         \t|\n\n```js\nconst possibleCollisions = superquad.get({ x: 5, y: 10, width: 50, height: 50 });\n```\n\n### **getIntersections**\n\nGets any objects whose bounds intersect with the bounds provided. This does return objects that collide with the provided bounds but if your object is circular this is not very accurate as it checks for rectangular collision only.\n\n| param         \t| type   \t| description                     \t      | default \t|\n|---------------\t|--------\t|---------------------------------------- |---------\t|\n| bounds        \t| Object \t| The bounds to check for nearby objects\t|         \t|\n| bounds.x      \t| number \t| The x position of the bounds    \t      |         \t|\n| bounds.y      \t| number \t| The y position of the bounds    \t      |         \t|\n| bounds.width  \t| number \t| The width of the bounds         \t      |         \t|\n| bounds.height \t| number \t| The height of the bounds        \t      |         \t|\n\n```js\nconst intersections = superquad.getIntersections({ x: 5, y: 10, width: 50, height: 50 });\n```\n\n### **getPoints**\n\nWorks in a similar fashion to `getIntersections` but instead it returns objects that collide with the bounds only if the objects are points (no width and no height).\n\n| param         \t| type   \t| description                     \t      | default \t|\n|---------------\t|--------\t|---------------------------------------- |---------\t|\n| bounds        \t| Object \t| The bounds to check for nearby points  \t|         \t|\n| bounds.x      \t| number \t| The x position of the bounds    \t      |         \t|\n| bounds.y      \t| number \t| The y position of the bounds    \t      |         \t|\n| bounds.width  \t| number \t| The width of the bounds         \t      |         \t|\n| bounds.height \t| number \t| The height of the bounds        \t      |         \t|\n\n```js\nconst points = superquad.getPoints({ x: 5, y: 10, width: 50, height: 50 });\n```\n\n### **clear**\n\nClears all objects from the each quad in the quadtree.\n\n```js\nsuperquad.clear();\n```\n\n## **Acknowledgements**\n\nThis package is based on Timo Hausmann [Quadtree implementation](https://github.com/timohausmann/quadtree-js) and also JamesMilnerUK's [Go Quadtree implementation](https://github.com/JamesMilnerUK/quadtree-go).\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertcorponoi%2Fsuperquad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertcorponoi%2Fsuperquad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertcorponoi%2Fsuperquad/lists"}