{"_id":"@adamarthur/spatial-hashmap","_rev":"2-6f89b7259558b5f65b7a711d83d389d5","name":"@adamarthur/spatial-hashmap","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.2":{"name":"@adamarthur/spatial-hashmap","version":"1.0.2","description":"Spatial Hashmap data structure for use in broad phase collision detection","keywords":["collision","collision detection","physics","spatial hashmap","game","broad phase","spatial hashing"],"license":"MIT","author":{"name":"Adam Arthur","email":"adam.arthur.wilson@gmail.com","url":"https://adamarthur.io"},"repository":{"type":"git","url":"git+https://github.com/adam-arthur/spatial-hashmap.git"},"main":"./dist/cjs/index.js","module":"./dist/esm/index.js","browser":"./dist/cjs/index.js","scripts":{"build":"npm run clean && tsc && tsc -p tsconfig.esm.json","test":"jest","test.watch":"jest --watchAll","clean":"rimraf dist","prepublishOnly":"npm run build"},"devDependencies":{"@types/jest":"^26.0.20","jest":"^26.6.3","rimraf":"^3.0.2","ts-jest":"^26.4.4","typescript":"^4.1.3"},"gitHead":"402e4d2ce060c7849acdb39c779d3df5fb57e67c","bugs":{"url":"https://github.com/adam-arthur/spatial-hashmap/issues"},"homepage":"https://github.com/adam-arthur/spatial-hashmap#readme","_id":"@adamarthur/spatial-hashmap@1.0.2","_nodeVersion":"14.15.3","_npmVersion":"6.14.9","dist":{"integrity":"sha512-2P7VDnio2v+hdqnmkqFBrrKlfxUWO1TIErH/ewFSXWy5kDLtuWfX8asR4WjumoWXSyY/GL7Qx7qrIPHBqf28zg==","shasum":"42162b572c9d9a198ec63d4754ce523859613365","tarball":"https://registry.npmjs.org/@adamarthur/spatial-hashmap/-/spatial-hashmap-1.0.2.tgz","fileCount":41,"unpackedSize":37767,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgDcbBCRA9TVsSAnZWagAAx7EP/iMDOcpPDhllsP+BLaWY\nQH1t0JdO4UfgnRq+Cmo7SmZW3c8QLk2fkQF/MNArWEQ83lAbkf+pPMjqj/Qu\n7iDfpM8P8bukvxkLYBEm5c6rVq4PHQin49H4jQFOWgWfeXaGE5NvrWiu5Nlu\nAtv16WO22ymzgWQvsy6Bcs+Qh1zGu+8urAg7325vlA+tZ+lXHqsiuPLou6PQ\nXOqMEAQujFYmSQPO5VfxevD7wMWAsnNWn9oIafjWYdcwvSyKrDovUPh+oUcp\nF+WuAj9/kmnrRtKwW2nDxlXIktRRqC/FjtuAoX2jS4SEb/aT5LG2y+5DBeQo\nTOaYJ52OQgAJ5Kzh0YjO6jZ1v5rlQ/YHqA4/9oChPM+7LnL3oAGF5MprK0Zw\n8dKLhSIeiF/9lCL7kN779N0tQ86xVm5VR2LtEXSxiIFUGKVMdJEuLzhlIjuT\nxtrcOnlOzN00+j5PufPBoA4qpTTmQNjvGu0zsGjr3KNZnh+ewdJvo6I5yrFZ\no+NEIa0dagFHmddB3SqtdaGw2SczhfrmQQtz7ja/9CT2j2T8LvOB87oAz5O1\nXEnpH+o1J52tgKsv1BLb8xu499EvMj8/HgIrXBq1dRnet/312vWuTajxkd3l\nnKodSeX44Tu7B8tHdPuLcG7bsFLTRjjBJJsEKDpeul2fYaYVrFXarb2nPxVt\nwEBa\r\n=RTtz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0j2NkbPSR8huZqb895K9QZRY5n19abcfMTg+BQoII3QIhAJp1AsP7EljwwD+S0RjjhkGa9HiRKf+P1rnRSj6BMc0U"}]},"_npmUser":{"name":"adamarthur","email":"adam.arthur.wilson@gmail.com"},"directories":{},"maintainers":[{"name":"adamarthur","email":"adam.arthur.wilson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/spatial-hashmap_1.0.2_1611515585131_0.9170667436411091"},"_hasShrinkwrap":false},"1.0.3":{"name":"@adamarthur/spatial-hashmap","version":"1.0.3","description":"Spatial Hashmap data structure for use in broad phase collision detection","keywords":["collision","collision detection","physics","spatial hashmap","game","broad phase","spatial hashing"],"license":"MIT","author":{"name":"Adam Arthur","email":"adam.arthur.wilson@gmail.com","url":"https://adamarthur.io"},"repository":{"type":"git","url":"git+https://github.com/adam-arthur/spatial-hashmap.git"},"main":"./dist/cjs/index.js","module":"./dist/esm/index.js","browser":"./dist/cjs/index.js","scripts":{"build":"npm run clean && tsc && tsc -p tsconfig.esm.json","test":"jest","test.watch":"jest --watchAll","clean":"rimraf dist","prepublishOnly":"npm run build"},"devDependencies":{"@types/jest":"^26.0.20","jest":"^26.6.3","rimraf":"^3.0.2","ts-jest":"^26.4.4","typescript":"^4.1.3"},"gitHead":"7d0c4c7bb296224bc56e5e90486f34c1e81f7e95","bugs":{"url":"https://github.com/adam-arthur/spatial-hashmap/issues"},"homepage":"https://github.com/adam-arthur/spatial-hashmap#readme","_id":"@adamarthur/spatial-hashmap@1.0.3","_nodeVersion":"14.15.3","_npmVersion":"6.14.9","dist":{"integrity":"sha512-LD1GqpV17zInOJdBYg1jZ8qU6D/Tah7j9UUrQ93ip81zTOKZfDzBho4jeDXWTciIeY43LCQVZPim1v0goyBhQQ==","shasum":"15069bb79ad07ce4fcb10deb76355522a0fb22c2","tarball":"https://registry.npmjs.org/@adamarthur/spatial-hashmap/-/spatial-hashmap-1.0.3.tgz","fileCount":41,"unpackedSize":37769,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgDchgCRA9TVsSAnZWagAAS7UQAIju23E2aGFKaHSBxva6\nuJ+XnjHltT++OlJ/tFkYyOL8tercR109lPeZkzyX7c93oKbgiXDjZzRZ6Cdo\ndT1WVaB/sqP94tczWtiumytq6t797Yqqx9pCZLuteeZsGblc+8rRXAq+OpCF\nVlOery4kPJHWIUuzmfCEkORRtBDToGEW5qXHOKrjJw2QJbC57xgRqdHfXX+n\ngTMjEtlyxq9DVVtes2rskt3mK4Otfvb87FuaqOGf0LJRwrd2OqdV9Z8biLIa\nmXVmfMAqOC3bhvw35Ll7JuayOYyi+t/Ch1m4o7inSOz/t1TOr93KIFNmMnT5\nHa0D9ZPLlV8jUAQqxVFdGVo4HatqrJaVeGGovBnY4+BjPn6veD+/Te0pm3Oq\nUwJWrAO6d3S5miAT9y9L/LR6/JNqCiYYMCT4pvjKPWVRFZJ78thKNARILoc5\nRdcnjCwxfCSl3X3v1x+ok2gpKD0b3iymQRZim+zKYph6nMqjeab1bROlR2Z6\nfsUw5ZAsqPVnEWlEvT/tcld3pr9OiO1x1caN1MvQ8ifHAmG3GSWK5cw7izPj\nhRrMy2JEdcNGUqxZgCj/a6mdcPIORaoW0OmYO5+dR76b6CMZt5grbCzuXbZw\njCSWCnr0nTxW4Nc0U/qcFaw7IXGK3HPhDt4vpvloBhF8QrTYbZFYsN16i5Ap\nvbV4\r\n=glPW\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEYBt54fH/ZE0YxLaxROfjcKPkEAk90wgMddA8mE5XULAiAcea2Xe0tms48yf25JROEUG9uWhzJd4+sUUYD6z5Aqlg=="}]},"_npmUser":{"name":"adamarthur","email":"adam.arthur.wilson@gmail.com"},"directories":{},"maintainers":[{"name":"adamarthur","email":"adam.arthur.wilson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/spatial-hashmap_1.0.3_1611516000171_0.014066709859214432"},"_hasShrinkwrap":false}},"time":{"created":"2021-01-24T19:13:05.082Z","1.0.2":"2021-01-24T19:13:05.289Z","modified":"2022-04-04T11:25:02.717Z","1.0.3":"2021-01-24T19:20:00.297Z"},"maintainers":[{"name":"adamarthur","email":"adam.arthur.wilson@gmail.com"}],"description":"Spatial Hashmap data structure for use in broad phase collision detection","homepage":"https://github.com/adam-arthur/spatial-hashmap#readme","keywords":["collision","collision detection","physics","spatial hashmap","game","broad phase","spatial hashing"],"repository":{"type":"git","url":"git+https://github.com/adam-arthur/spatial-hashmap.git"},"author":{"name":"Adam Arthur","email":"adam.arthur.wilson@gmail.com","url":"https://adamarthur.io"},"bugs":{"url":"https://github.com/adam-arthur/spatial-hashmap/issues"},"license":"MIT","readme":"# Spatial Hashmap\nAn implementation of [spatial hashing](https://en.wikipedia.org/wiki/Collision_detection#Spatial_partitioning), which is typically used in collision detection. Objects are placed into \"cells\" within a 2D grid based on their position and size. Any object within the same cell is potentially colliding.\n\n\n## Why is this useful?\nFor collision detection, it can be significantly faster to have both a coarse, \"broad phase\" to get potentially colliding objects first, and then a \"narrow phase\" where a precise collision check is used between any potentially colliding objects. Rather than always comparing every pair of objects.\n\n\n## Install\n`npm install @adamarthur/spatial-hashmap`\n\n## Usage\n\n```javascript\nimport SpatialHashmap from '@adamarthur/spatial-hashmap';\n\nconst map = new SpatialHashmap({ \n                width: 100, \n                height: 100, \n                cellSize: 10 \n            });\n\nconst gameObject = {\n    id: 'Player',\n    body: {\n        x: 0,\n        y: 0,\n        width: 10,\n        height: 10,\n    },\n};\n\n// Second argument can be any rectangle definining position. In this case the player.body is a rectangle.\nmap.add(gameObject, gameObject.body);\n\n// Get array of objects that could be intersecting this rectangle\nmap.getNearby({\n    x: 5,\n    y: 5,\n    width: 1,\n    height: 1,\n});\n\n// Used as a pre-filter to more precise collision detection\nfor (const group of map.getPossiblyCollidingGroups()) {\n    checkForCollisions(group);\n}\n```\n\n## API\n\n### add(object, range)\nInserts an object into any cells of the grid that overlap range.\n\n### getNearby(range)\nReturns an array of any object that could potentially be touching the supplied range.\n\n### getPossiblyCollidingGroups()\nReturns all sets of objects that are possibly colliding\n\n\n## Support\nFor any questions, support, or to follow my other projects, contact me at [adamarthur.io](https://adamarthur.io)!\n\n","readmeFilename":"README.md"}