{"id":16579716,"url":"https://github.com/oguzeroglu/nearby","last_synced_at":"2025-10-10T15:16:51.017Z","repository":{"id":47859980,"uuid":"260465350","full_name":"oguzeroglu/Nearby","owner":"oguzeroglu","description":"Find nearby 3D objects in constant time O(1).","archived":false,"fork":false,"pushed_at":"2023-01-06T04:49:24.000Z","size":313,"stargazers_count":108,"open_issues_count":6,"forks_count":4,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-09-28T09:24:08.106Z","etag":null,"topics":["3d","algortihm","binning","closest","game-development","octree","spatial-hash"],"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/oguzeroglu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-01T13:26:44.000Z","updated_at":"2025-05-19T23:12:24.000Z","dependencies_parsed_at":"2023-02-05T08:46:36.420Z","dependency_job_id":null,"html_url":"https://github.com/oguzeroglu/Nearby","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/oguzeroglu/Nearby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguzeroglu%2FNearby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguzeroglu%2FNearby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguzeroglu%2FNearby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguzeroglu%2FNearby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oguzeroglu","download_url":"https://codeload.github.com/oguzeroglu/Nearby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguzeroglu%2FNearby/sbom","scorecard":{"id":703368,"data":{"date":"2025-08-11","repo":{"name":"github.com/oguzeroglu/Nearby","commit":"4f3fbeb96d9ce38f534d0a1224f1f8c590c70c75"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.5,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":0,"reason":"Found 1/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v1.2.0 not signed: https://api.github.com/repos/oguzeroglu/Nearby/releases/26130034","Warn: release artifact v1.1.0 not signed: https://api.github.com/repos/oguzeroglu/Nearby/releases/26105275","Warn: release artifact v1.0.0 not signed: https://api.github.com/repos/oguzeroglu/Nearby/releases/26094208","Warn: release artifact v1.2.0 does not have provenance: https://api.github.com/repos/oguzeroglu/Nearby/releases/26130034","Warn: release artifact v1.1.0 does not have provenance: https://api.github.com/repos/oguzeroglu/Nearby/releases/26105275","Warn: release artifact v1.0.0 does not have provenance: https://api.github.com/repos/oguzeroglu/Nearby/releases/26094208"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"37 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T05:46:33.973Z","repository_id":47859980,"created_at":"2025-08-22T05:46:33.973Z","updated_at":"2025-08-22T05:46:33.973Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279004577,"owners_count":26083735,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["3d","algortihm","binning","closest","game-development","octree","spatial-hash"],"created_at":"2024-10-11T22:19:04.135Z","updated_at":"2025-10-10T15:16:50.984Z","avatar_url":"https://github.com/oguzeroglu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nearby\nNearby is an easy-to-use lightweight JS library for your 2D/3D games that helps you get the nearby objects in a constant time `O(1)` instead of simple brute force algorithms that run on `O(n)`.\n\nPorted from the [WorldBinHandler class of ROYGBIV engine](https://github.com/oguzeroglu/ROYGBIV/blob/master/js/handler/WorldBinHandler.js).\n\n# The Problem\nIn most of the games (2D/3D), collision checks are essential both for physics or AI (steering behaviors such as obstacle avoidance, collision avoidance). Many naive implementations depend on comparing a certain bounding box with the bounding box of every other object of the scene:\n\n    forEach object of the scene\n\t    checkIfCollided(box, object.box)\n\nThis naive approach runs on `O(n)` and this is a problem especially for rather crowded scenes with many dynamic/static objects.\n\nIn order to overcome this problem, game engines use [Octree](https://en.wikipedia.org/wiki/Octree) data structure. However Octree is not so easy to implement for dynamic objects. A tree needs to be reconstructed in that case, which triggers GC activity and slows down the main thread in Javascript.\n# The Solution\n\nWhile working on [ROYGBIV engine](https://github.com/oguzeroglu/ROYGBIV) particle collisions, I experimented with couple of solutions and ended up implementing a binning algorithm that splits the world into bins, insert the object into different bins based on their bounding boxes. This helps us finding nearby objects of a given point in constant time `O(1)`. This library is a standalone version of the same algorithm.\n# Performance Comparison\nRun the [performance-test](https://github.com/oguzeroglu/Nearby/blob/master/performance-test.html) in your browser. In order to test the efficiency of Nearby, a defined amount of objects are created and put into random positions. Then the closest object to the point `(0, 0, 0)` is searched first with Nearby algorithm and then with the naive approach (brute forcing).\n\nHere are the results:\n| Number of objects | Nearby | Naive approach |\n|--|--|--|\n| 1000000 | 1.33 ms | 51 ms |\n| 100000 | 0.2 ms | 11 ms |\n| 10000 | 0.18 ms | 2 ms |\n\nAs you can see Nearby offers a much faster solution.\n\n# Usage\n\nGet the latest release. Include the Nearby.min.js in your HTML\n```HTML\n\u003chead\u003e\n\t\u003cscript src=\"[Path to Nearby.min.js]\"\u003e\u003c/script\u003e\n\n```\n\nFor NodeJS:\n\n```\nnpm install --save nearby-js\n```\n\n```Javascript\nvar Nearby = require(\"nearby-js\");\n```\n\nThen with Javascript:\n```javascript\n// INITIALIZE\nvar sceneWidth = 1000, sceneHeight = 1000, sceneDepth = 1000;\nvar binSize = 50;\n// Creates a world centered in (0, 0, 0) of size (1000x1000x1000)\n// The world is splitted into cubes of (50x50x50).\nvar nearby = new Nearby(sceneWidth, sceneHeight, sceneDepth, binSize);\n\n// CREATE AN OBJECT REPRESENTATION\nvar objectPosX = 0, objectPosY = 100, objectPosZ = -100;\nvar objectWidth = 10, objectHeight = 50, objectDepth = 100;\n\n// Creates a new bounding box of (10x50x100) size, located at\n// the position (x: 0, y: 100, z: -100)\nvar box = nearby.createBox(\n\tobjectPosX, objectPosY, objectPosZ,\n\tobjectWidth, objectHeight, objectDepth\n);\n\nvar objectID = \"my_collidable_object\";\nvar object = nearby.createObject(objectID, box);\n\n// INSERT THE OBJECT INTO THE WORLD\nnearby.insert(object);\n```\n\nTo find Nearby objects:\n```javascript\nvar searchX = 0, searchY = 0, searchZ = 0;\n\n// Find the nearby objects from (searchX, searchY, searchZ)\n//\n// Nearby returns the object within range (3 * binSize) / 2\n// So for this example the max distance that makes an object \"nearby\"\n// is (50 * 3) / 2 = 75\n\n// returns a Map having keys: inserted objects\nvar result = nearby.query(searchX, searchY, searchZ);\n\nfor (var object of result.keys()){\n\tconsole.log(object.id + \" is found nearby!\");\n}\n```\n\nTo update an object:\n```javascript\nvar newPosX = -500, newPosY = 100, newPosZ = 100;\nvar newWidth = 1000, newHeight = 1000, newDepth = 1000;\nnearby.update(\n\tobject, newPosX, newPosY, newPosZ,\n\tnewWidth, newHeight, newDepth\n);\n```\n\nTo delete an object:\n```javascript\nnearby.delete(object);\n```\n# In Action\nThis algorithm is used by ROYGBIV engine in many demos.\nFor instance in [this demo](https://oguzeroglu.github.io/ROYGBIV/demo/blaster/application.html) and [this demo](https://oguzeroglu.github.io/ROYGBIV/demo/plasmaGun/application.html) Nearby algorithm is used to check if a ParticleSystem is collided with walls or objects. In [this demo](https://oguzeroglu.github.io/ROYGBIV/demo/shooter/application.html) the algorithm is used to perform Ray checks from the weapon (when the user shoots).\n\n# License\nNearby uses MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foguzeroglu%2Fnearby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foguzeroglu%2Fnearby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foguzeroglu%2Fnearby/lists"}