Skip to content

Commit 0b3e296

Browse files
committed
fix: finds the lowest intersecting interval #47
1 parent 45bcbbf commit 0b3e296

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

dist/main.cjs.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ class IntervalTree {
403403
}
404404

405405
/**
406-
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
406+
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
407407
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
408408
* @returns {Iterator}
409409
*/
@@ -657,8 +657,12 @@ class IntervalTree {
657657
let curr = node;
658658
while (curr && curr != this.nil_node) {
659659
if (curr.less_than(search_node)) {
660-
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
661-
curr = curr.right;
660+
if (curr.intersect(search_node)) {
661+
best = curr;
662+
curr = curr.left;
663+
} else {
664+
curr = curr.right;
665+
}
662666
} else {
663667
if (!best || curr.less_than(best)) best = curr;
664668
curr = curr.left;

dist/main.esm.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class IntervalTree {
399399
}
400400

401401
/**
402-
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
402+
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
403403
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
404404
* @returns {Iterator}
405405
*/
@@ -653,8 +653,12 @@ class IntervalTree {
653653
let curr = node;
654654
while (curr && curr != this.nil_node) {
655655
if (curr.less_than(search_node)) {
656-
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
657-
curr = curr.right;
656+
if (curr.intersect(search_node)) {
657+
best = curr;
658+
curr = curr.left;
659+
} else {
660+
curr = curr.right;
661+
}
658662
} else {
659663
if (!best || curr.less_than(best)) best = curr;
660664
curr = curr.left;

dist/main.umd.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@
405405
}
406406

407407
/**
408-
* @param {Interval} interval - optional if the iterator is intended to start from the beginning or end
408+
* @param {Interval} interval - optional if the iterator is intended to start from the beginning
409409
* @param outputMapperFn(value,key) - optional function that maps (value, key) to custom output
410410
* @returns {Iterator}
411411
*/
@@ -659,8 +659,12 @@
659659
let curr = node;
660660
while (curr && curr != this.nil_node) {
661661
if (curr.less_than(search_node)) {
662-
if (curr.intersect(search_node) && (!best || curr.less_than(best))) best = curr;
663-
curr = curr.right;
662+
if (curr.intersect(search_node)) {
663+
best = curr;
664+
curr = curr.left;
665+
} else {
666+
curr = curr.right;
667+
}
664668
} else {
665669
if (!best || curr.less_than(best)) best = curr;
666670
curr = curr.left;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@flatten-js/interval-tree",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Interval search tree",
55
"author": "Alex Bol",
66
"license": "MIT",

0 commit comments

Comments
 (0)