https://github.com/lovasoa/rectangle-overlap
Fastly compute the intersection of two rectangles.
https://github.com/lovasoa/rectangle-overlap
geometry overlapping-rectangles rectangle
Last synced: 10 months ago
JSON representation
Fastly compute the intersection of two rectangles.
- Host: GitHub
- URL: https://github.com/lovasoa/rectangle-overlap
- Owner: lovasoa
- License: lgpl-3.0
- Created: 2016-01-20T16:47:16.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T11:00:34.000Z (almost 3 years ago)
- Last Synced: 2025-03-19T01:59:55.955Z (10 months ago)
- Topics: geometry, overlapping-rectangles, rectangle
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/rectangle-overlap
- Size: 258 KB
- Stars: 6
- Watchers: 2
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rectangle-overlap
[](https://github.com/lovasoa/rectangle-overlap/blob/master/index.ts)
[](https://github.com/lovasoa/rectangle-overlap/blob/master/LICENSE)
[](https://travis-ci.org/lovasoa/rectangle-overlap)

Fastly compute the intersection of two rectangles.
## Usage
```js
const intersection = require("rectangle-overlap");
let rect1 = {x: 0, y: 0, width: 10, height: 10};
let rect2 = {x: 2, y: 3, width: 42, height: 42};
const overlap = intersection(rect1, rect2);
if (overlap) {
console.log(`The rectangles overlap over an area of ${overlap.area}`);
console.log(
`Intersection coordinates: x=${overlap.x}, y=${overlap.y}, width=${overlap.width}, height=${overlap.height}`,
)
} else {
console.log("The rectangles do not overlap");
}
```