New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

spatial-hashmap

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spatial-hashmap

Broad phase collision detection using a spatial hashmap

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

Spatial Hashmap

CircleCI

Spatial Hashmap is a module for answering the question "What is near an object with these coordinates?". It was created based off the algorithm defined in "Optimization of Large-Scale, Real-Time Simulations by Spatial Hashing"

Install

npm i spatial-hashmap

Usage

// pass in the width, height, and cell size
// cell size - use this to control how big a region is returned when asking for nearby objects
const sm = new SpatialManager(100, 100, 10)
// this can be literally anything
const yourObject = {your: 'object'}
// pass in a geometry with this shape
const geometry = {
  pos: {
    x: 0,
    y: 0
  },
  aabb: {
    min: {
      x: 0,
      y: 0
    }
    max: {
      x: 12,
      y: 10
    }
  }
}
sm.registerObject(yourObject, geometry)
sm.registerObject({your: 'otherObject'}, ...)

// returns Set of nearby objects
sm.getNearby(geometryOfOtherObject)
sm.clearMap()

API

clearMap()

Empties Spatial Hashmap and reinitializes.

registerObject(obj, geo)

How you get your obj into the map

@param obj - what you want to register in the spatial hashmap

@param geo - a description of the objects position and bounding box

{
  // position of the object
  pos: {
    x: 0,
    y: 0
  },
  // bounding box relative to position
  aabb: {
    min: {
      x: 0,
      y: 0
    }
    max: {
      x: 12,
      y: 10
    }
  }
}

getIdsForGeometry(geo)

Returns all the possible buckets an object's geometry is in as a set

SpatialManager.idForPoint(point, cellsizeInv, numCols) (static)

Given a Point return its bucket ID

@param cellsizeInv - 1 / cellsize

@param numcols - the number of cols in the spatial map

spatialManager.idForPoint(point) (instance)

Given a Point return its bucket ID

getNearby(geo)

Given a geometry return the objects nearby

Keywords

collision

FAQs

Package last updated on 01 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts