Giter VIP home page Giter VIP logo

in-n-out's Introduction

in-n-out NPM version Dependency Status Build Status

A library to perform point-in-geofence searches. A tiled cache is used to determine inclusion very efficiently, so the library is tailored for create once, query many times uses.

Geofence.inside() should be faster than utils.pointInPolygon: iterations: 1000000, innout: 48ms, pointinpolygon: 747ms

Install

npm install in-n-out

Geofence(vertices, granularity = 20)

Using the Geofence class you can determine whether a point is inside the geofence or not. Upon construction, the geofence's bounding box is broken down into tiles. The tiles that either intersect or are inside the geofence are tracked in a hash table. Geofence.inside() queries then use this cache to quickly answer inside() queries.

var InNOut = require('in-n-out');
var gf = new InNOut.Geofence([[0,0], [1,0], [1,1], [0,1], [0,0]], 100);

gf.inside([0.5,0.5]); // true
gf.inside([100,100]); // false

The geofence's bbox will be broken down into a granularity x granylarity grid, defaulting to 20x20.

GeofencedGroup(id, whiteoutGfs[], blackoutGfs[])

Used to determine which ids are valid for a given location, based on the whiteout and blackout geofence rules provided for each id. A typical use case is geofence triggers for loccations, offering location based services or denying services based on location.

var InNOut = require('in-n-out');
var whiteoutGf = new InNOut.Geofence([[0,0], [1,0], [1,1], [0,1], [0,0]]);
var blackoutGf = new InNOut.Geofence([[0.5,0], [1,0], [1,1], [0.5,1], [0.5, 0]]);
var gfGroup = new InNOut.GeofencedGroup();

gfGroup.add(1, [whiteoutGf], [blackoutGf]);

gfGroup.getValidKeys([0.1, 0.1]); // [1] - Included by whiteout
gfGroup.getValidKeys([0.6, 0.6]); // [] - Excluded by blackout
gfGroup.getValidKeys([100, 100]); // [] - Excluded by whiteout

The inclusion logic is as follows:

  • If there are blackout zones, exclude the point if it is inside any of them
  • If there are whiteout zones
    • Include the point if it is inside of any of them
    • Exclude the point otherwise
  • Include the point

Passing null for the geofence arrays is the same as [].

License (MIT)

Copyright (C) 2013 by Uber Technologies, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

in-n-out's People

Contributors

bigo avatar countrodrigo avatar squamos avatar

Watchers

 avatar  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.