-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bde85ac
Showing
33 changed files
with
21,107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"no-undef":"error" | ||
}, | ||
"env" : { | ||
"node" : true, | ||
"es6": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
/build | ||
|
||
/demo/outline/ | ||
/demo/interactive/public/lines.json | ||
|
||
# local env files | ||
.env.local | ||
.env.*.local | ||
|
||
|
||
# Log files | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Editor directories and files | ||
.idea | ||
.vscode | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
!build/ | ||
demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# isect - intersection detection library | ||
|
||
This library allows you to find all intersections in a given set of | ||
segments. | ||
|
||
TODO: Image | ||
|
||
# Methods | ||
|
||
The library implements two methods | ||
|
||
## Bentley-Ottmann sweep line algorithm | ||
|
||
This algorithm has `O(n*log(n) + k*log(n))` performance, where `n` is number of | ||
segments, and `k` is number of intersections. | ||
|
||
This method is preferred when you have large number of lines, and not too many | ||
intersections (`k = o(n^2/log(n)`, to be more specific). | ||
|
||
The algorithm follows "Computation Geometry, Algorithms and Applications" book | ||
by Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars. It does support | ||
degenerate cases, though read limitations to learn more. | ||
|
||
## Brute force algorithm | ||
|
||
This is "naive" implementation where each segment is compared with all other segments, | ||
and thus has O(n*n) performance. | ||
|
||
Despite it's naiveté, it works much faster than Bentley-Ottmann algorithm for the cases | ||
when there are a few thousand lines and millions of intersections. This scenario is | ||
common in force-based graph drawing, where "hairball" formed by a few thousand lines. | ||
|
||
## Performance measurements | ||
|
||
The benchmark code is available here. | ||
|
||
[]() | ||
``` | ||
Sweep: Circular lines 12x40 x 1,022 ops/sec ±1.94% (90 runs sampled) | ||
Brute: Circular lines 12x40 x 7,252 ops/sec ±3.15% (78 runs sampled) | ||
Sweep: 100 Random lines lines in 42px box x 267 ops/sec ±0.80% (89 runs sampled) | ||
Brute: 100 Random lines lines in 42px box x 3,751 ops/sec ±2.42% (76 runs sampled) | ||
Sweep: 2,500 sparse lines x 135 ops/sec ±0.55% (75 runs sampled) | ||
Brute: 2,500 sparse lines x 13.57 ops/sec ±0.43% (38 runs sampled) | ||
``` | ||
|
||
|
||
# usage | ||
|
||
## installation | ||
Install the module from npm: | ||
|
||
``` | ||
npm i isect | ||
``` | ||
|
||
## basic usage | ||
|
||
The code below detects all intersections between segments in the array: | ||
|
||
``` js | ||
var isect = require('isect'); | ||
|
||
// Prepare the library to detect all intersection | ||
var iSector = isect([{ | ||
from: {x: 0, y: 0}, | ||
to: {x: 10, y: 10} | ||
}, { | ||
from: {x: 0, y: 10}, | ||
to: {x: 10, y: 0} | ||
}]); | ||
|
||
// Detect them all, operation is synchronous. | ||
var intersections = iSector.run(); | ||
console.log(intersections); | ||
// Prints: | ||
// | ||
// [ { point: { x: 5, y: 5 }, segments: [ [Object], [Object] ] } ] | ||
// | ||
// array of segments contain both segments. | ||
``` | ||
|
||
## Early stopping | ||
|
||
If you don't care about all intersections, but want to know if there is | ||
at least one intersection, you can pass a `onFound()` callback and request | ||
the library to stop as soon as it finds the intersection: | ||
|
||
``` js | ||
var iSector = isect([/* array of segments */], { | ||
onFound(point, interior, lower, upper) { | ||
// `point` is {x, y} of the intersection, | ||
// `interior`is array of segments that have this point inside | ||
// `lower` are segments that have point as a lower endpoint (segment.to) | ||
// `upper` are segments that have point as an upper endpoint (segment.from) | ||
|
||
// If you return true from this method, no further processing will be done: | ||
|
||
return true; // yes, stop right now! | ||
} | ||
}); | ||
``` | ||
|
||
## Asynchronous workflow | ||
|
||
TODO: explain | ||
|
||
|
||
## Performance | ||
|
||
|
||
|
||
## Limitations | ||
|
||
The library is susceptible to floating point rounding errors. It is | ||
possible to construct an example, with nearly horizontal lines, that would | ||
cause library to fail. TODO: link to drunk grid with small variance and large | ||
number of lines. | ||
|
||
While library does detected `point-segment` overlap, it does not detected `point-point` | ||
overlap. I.e. identical points in the input dataset, that do not overlap any segment | ||
will not be reported. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# sweep | ||
|
||
## Project setup | ||
``` | ||
npm install | ||
``` | ||
|
||
### Compiles and hot-reloads for development | ||
``` | ||
npm start | ||
``` | ||
|
||
### Compiles and minifies for production | ||
``` | ||
npm run build | ||
``` | ||
|
||
### Lints and fixes files | ||
``` | ||
npm run lint | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: [ | ||
'@vue/app' | ||
] | ||
} |
Oops, something went wrong.