Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/red-blue-line-segment-intersect
Find all intersections between two sets of line segments
https://github.com/mikolalysenko/red-blue-line-segment-intersect
Last synced: about 2 months ago
JSON representation
Find all intersections between two sets of line segments
- Host: GitHub
- URL: https://github.com/mikolalysenko/red-blue-line-segment-intersect
- Owner: mikolalysenko
- License: mit
- Created: 2014-06-04T21:03:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-06-04T21:44:16.000Z (over 10 years ago)
- Last Synced: 2024-10-20T14:28:22.844Z (2 months ago)
- Language: JavaScript
- Size: 145 KB
- Stars: 3
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
red-blue-line-segment-intersect
===============================
Given two sets of line segments, find all pairs of intersections between the two of them.[![testling badge](https://ci.testling.com/mikolalysenko/red-blue-line-segment-intersect.png)](https://ci.testling.com/mikolalysenko/red-blue-line-segment-intersect)
[![build status](https://secure.travis-ci.org/mikolalysenko/red-blue-line-segment-intersect.png)](http://travis-ci.org/mikolalysenko/red-blue-line-segment-intersect)
# Example
```javascript
var findIntersections = require("red-blue-line-segment-intersect")var red = [
[[0, 0], [10, 10]],
[[10, 10], [10, 0]]
]var blue = [
[[1,0], [1, 8]]
]findIntersections(red, blue, function(r, b) {
console.log("segments", red[r], blue[b], "intersect")
})
```Output:
```
segments [ [ 0, 0 ], [ 10, 10 ] ] [ [ 1, 0 ], [ 1, 8 ] ] intersect
```# Install
```
npm install red-blue-line-segment-intersect
```# API
#### `require("red-blue-line-segment-intersect")(red, blue, visit)`
Finds all pair of segments between `red` and `blue` which intersect.* `red` is a list of line segments encoded as pairs of length 2 arrays
* `blue` is a second list of line segments
* `visit(r,b)` is a function which is called once for each pair of line segments that intersect. If `visit` returns truthy value, then iteration is terminated and that value is returned from the traversal.**Returns** The return value of the last call to `visit`, or `undefined` otherwise.
# Credits
(c) 2013-2014 Mikola Lysenko. MIT License