Skip to content

chrisdickinson/spatial-trigger

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
January 23, 2013 21:27
January 23, 2013 21:27
January 23, 2013 21:27
January 23, 2013 21:27

spatial-trigger

given a spatial event emitter and an axis aligned bounding box, return a new event emitter that emits enter and exit events when spatial events indicate that something has passed into the bounding box.

var trigger = require('spatial-trigger')
  , aabb = require('aabb-3d')
  , SPEE = require('spatial-events')
  , spee = new SPEE

trigger(spee, aabb([0, 0, 0], [4, 4, 4]), 'point')
  .on('enter', function() { console.log('entered box') })
  .on('exit', function() { console.log('exited box') })

spee.emit('point', [-4, -4, -4])
spee.emit('point', [-2, -2, -2])
spee.emit('point', [+0, +0, +0]) // 'entered box'
spee.emit('point', [+2, +2, +2])
spee.emit('point', [+4, +4, +4])
spee.emit('point', [+6, +6, +6]) // 'exited box'

API

ee = trigger(spatial_ee, boundingBox[, eventName='position'])

attaches one infinite listener to spatial_ee and one at boundingBox for eventName (which defaults to 'position' if not given), and returns an event emitter that emits 'enter' and 'exit' events.

Events

enter

enter events happen whenever the positions emitted by spatial_ee cross into the given bounding box. When an event triggers the enter event, its arguments will be forwarded to enter listeners.

exit

exit events happen whenever the positions emitted by spatial_ee leave the given bounding box. When an event triggers the exit event, its arguments will be forwarded to exit listeners.

License

MIT

About

enter/exit events for bounding boxes based on events from spatial-events

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published