
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
box-intersect-1d
Advanced tools
Find all intersections in a collection of intervals.
Here is how you can use this module to detect all intersections in a collection of intervals:
var boxIntersect1D = require('box-intersect-1d')
var boxes = [
[0, 1],
[0, 2],
[10, 100],
[5, 8],
[1.5, 7]
]
boxIntersect1D.full(boxes, function(i,j) {
console.log(i,j)
console.log('overlap:', boxes[i], boxes[j])
})
overlap: [ 0, 1 ] [ 0, 2 ]
overlap: [ 1.5, 7 ] [ 0, 2 ]
overlap: [ 5, 8 ] [ 1.5, 7 ]
If you want to compare intersections between two different sets of intervals you can use the .bipartite version of the test:
var boxIntersect1D = require('box-intersect-1d')
var red = [
[0, 1],
[0, 2],
[10, 100],
[5, 8],
[1.5, 7]
]
var blue = [
[0, 100],
[1, 2],
[-1, 5]
]
boxIntersect1D.bipartite(red, blue, function(r, b) {
console.log('overlap:', red[r], blue[b])
})
overlap: [ 0, 2 ] [ -1, 5 ]
overlap: [ 0, 2 ] [ 0, 100 ]
overlap: [ 0, 1 ] [ -1, 5 ]
overlap: [ 0, 1 ] [ 0, 100 ]
overlap: [ 0, 2 ] [ 1, 2 ]
overlap: [ 0, 1 ] [ 1, 2 ]
overlap: [ 1.5, 7 ] [ -1, 5 ]
overlap: [ 1.5, 7 ] [ 0, 100 ]
overlap: [ 1.5, 7 ] [ 1, 2 ]
overlap: [ 5, 8 ] [ -1, 5 ]
overlap: [ 5, 8 ] [ 0, 100 ]
overlap: [ 10, 100 ] [ 0, 100 ]
npm install box-intersect-1d
var boxIntersect1D = require('box-intersect-1d')
boxIntersect1D.full(boxes, visit)Find all pairs of boxes which intersect
boxes is an array of intervals represented by [lo,hi] value pairsvisit(i,j) is called for every pair over overlapping intervals with the index of the intervals. If visit returns any value other than undefined, then this terminates early with that value.boxIntersect1D.bipartite(red, blue, visit)Find all intersections between two sets of intervals
red and blue are two collections of intervals as described abovevisit(r,b) is called once for every pair of intervals in red and blue which overlap. r and b are the indices of the overlapping boxes.(c) 2014 Mikola Lysenko. MIT License
FAQs
Find all intersections in a set of intervals
We found that box-intersect-1d demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.