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

rectangles-intersect

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rectangles-intersect

Determine if two rectangles intersect each other.

latest
Source
npmnpm
Version
0.0.0
Version published
Weekly downloads
11
120%
Maintainers
1
Weekly downloads
 
Created
Source

rectangles-intersect

Determine if two rectangles intersect each other.

installation

npm install rectangles-intersect

usage

var intersects = require('rectangles-intersect');
inersects(rect1,rect2 [,precision]);

rect1 and rect2 are rectangles, array of corner points. Whereas point is array of x and y coordinate.
precision after decimal places, default is 6

example

var intersects = require('rectangles-intersect');
var check = intersects(
  [[0,10], [10,0], [20,10], [10,20]],
  [[10,10], [20,0], [30,10], [20,20]]);
if (check) {
  console.log('two rectangles intersect');
}
```
## note
In this module my approach is:  
check 1: intersection of any edge of rectangle with another rectangle's edges  
check 2: any corner point of rectangle is inside another rectangle  
If check 1 or check 2 satisfies then rectangles intersect otherwise not.  
This approach is not quite efficient. For improving efficiency get the implementation of [Separating Axis Theorem](http://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169), read more at [wiki](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) 

## developing
Once you run
 
```npm isntall```

then for running test 

```npm run test```

to create build

```npm run build```

## License
This project is licensed under the terms of the MIT license.

Keywords

rectangle

FAQs

Package last updated on 21 Jun 2015

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