Giter VIP home page Giter VIP logo

box-collide's Introduction

box-collide

return whether two boxes or points are colliding in 2d

build status

testling badge

example

var collide = require('box-collide');
var a = { left: 4, right: 8, top: 100, bottom: 140 };
var b = { left: 6, top: 90, height: 20, width: 1 };
var c = { x: -3, y: 20, width: 400, height: 300 };
var d = { x: 2, y: 8 };

console.log('a,b', collide(a, b));
console.log('a,c', collide(a, c));
console.log('a,d', collide(a, d));
console.log('b,c', collide(b, c));
console.log('b,d', collide(b, d));
console.log('c,d', collide(c, d));

output:

a,b false
a,c true
a,d false
b,c true
b,d false
c,d false

methods

var collide = require('box-collide')

var colliding = collide(a, b)

Return a boolean colliding indicating whether a and b overlap.

a and b can be points or bounding boxes and must have any of these combinations of properties:

  • left, right, top, bottom
  • left, top, width, height
  • x, y
  • x, y, width, height

x and y indicate the top left corner of the box or point.

install

With npm do:

npm install box-collide

license

MIT

box-collide's People

Watchers

 avatar

Forkers

ios-user01 kjirou

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.