GithubHelp home page GithubHelp logo

imclab / spatial-trigger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chrisdickinson/spatial-trigger

0.0 1.0 0.0 60 KB

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

spatial-trigger's Introduction

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

spatial-trigger's People

Contributors

chrisdickinson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.