|
|
@ -23,7 +23,7 @@ export function cutSpanWithSpans(inputSpan: Span, cutSpans: Span[]): Span[] { |
|
|
|
|
|
|
|
|
|
|
|
// we sort and merge out cuts to normalize it
|
|
|
|
// we sort and merge out cuts to normalize it
|
|
|
|
cutSpans = _.sortBy(cutSpans, s => s.from); |
|
|
|
cutSpans = _.sortBy(cutSpans, s => s.from); |
|
|
|
var mergedSortedCuts =_.reduce(cutSpans,
|
|
|
|
const mergedSortedCuts =_.reduce(cutSpans,
|
|
|
|
((acc: Span[], s: Span) => { |
|
|
|
((acc: Span[], s: Span) => { |
|
|
|
if(acc.length === 0) return [s]; |
|
|
|
if(acc.length === 0) return [s]; |
|
|
|
let last = acc[acc.length - 1]; |
|
|
|
let last = acc[acc.length - 1]; |
|
|
@ -38,20 +38,20 @@ export function cutSpanWithSpans(inputSpan: Span, cutSpans: Span[]): Span[] { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// this is what we get if we cut `mergedSortedCuts` from (-Infinity, Infinity)
|
|
|
|
// this is what we get if we cut `mergedSortedCuts` from (-Infinity, Infinity)
|
|
|
|
var holes = mergedSortedCuts.map((cut, i) => { |
|
|
|
const holes = mergedSortedCuts.map((cut, i) => { |
|
|
|
let from = -Infinity; |
|
|
|
let from = -Infinity; |
|
|
|
let to = cutSpans[0].from; |
|
|
|
let to = cutSpans[0].from; |
|
|
|
if(i > 0) { |
|
|
|
if(i > 0) { |
|
|
|
from = mergedSortedCuts[i - 1].to; |
|
|
|
from = mergedSortedCuts[i - 1].to; |
|
|
|
to = cut.from; |
|
|
|
to = cut.from; |
|
|
|
} |
|
|
|
} |
|
|
|
return { from, to } |
|
|
|
return { from, to }; |
|
|
|
}).concat({ |
|
|
|
}).concat({ |
|
|
|
from: mergedSortedCuts[mergedSortedCuts.length - 1].to, |
|
|
|
from: mergedSortedCuts[mergedSortedCuts.length - 1].to, |
|
|
|
to: Infinity |
|
|
|
to: Infinity |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
return _(holes).map(c => { |
|
|
|
const holesInsideInputSpan = _(holes).map(c => { |
|
|
|
if(c.to <= inputSpan.from) return undefined; |
|
|
|
if(c.to <= inputSpan.from) return undefined; |
|
|
|
if(inputSpan.to <= c.from) return undefined; |
|
|
|
if(inputSpan.to <= c.from) return undefined; |
|
|
|
return { |
|
|
|
return { |
|
|
@ -60,4 +60,5 @@ export function cutSpanWithSpans(inputSpan: Span, cutSpans: Span[]): Span[] { |
|
|
|
} |
|
|
|
} |
|
|
|
}).compact().value(); |
|
|
|
}).compact().value(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Array.from(holesInsideInputSpan); |
|
|
|
} |
|
|
|
} |
|
|
|