Closed jonyrock closed 5 years ago
@amper43 @rozetko
In first version of this PR, I said:
One-point cut
If we cut [1, 10] with [5, 5] , we should get spans [1, 5] and [5, 10]
but is truly correct behavior? In theory we can get such case when we run detector for one point for threshold.
We should better define what Span(x,y)
is. Possible options are: (x, y)
, (x, y]
, [x, y)
and [x, y]
I believe that Span
should represent a discrete structure, which is a countable set, integer segment , subset of Z
So when we want to get cut [x, x]
from [a, b]
where a < x < b
, then we should return split [a, x - 1]
and [x + 1, b]
Also, I propose to stop using word "Span" without clear math definition. So I an going to rename Utils.spans.cutSpanWithSpans
accordingly.
If [a, b]
is the segment we are cutting from and [z, z]
and [x, y]
are cutting segments, we should get [[a, a], [a, x - 1]]
in result
All thread compiled to https://github.com/hastic/hastic-server/pull/756
Just to be sure that the function
Utils.spans.cutSpanWithSpans
works as it should, few more tests added: It will help in future if we want to improve the performance.This PR changes the behavior of
cutSpanWithSpans
and renames it tocutSegmentWithSegments
New tests:
One-point cut
If we cut
[1, 10]
with[5, 5]
, we should get spans[1, 4]
and[6, 10]
Infinite spans
If we cut
[0, Infinity]
with[5, 10]
, we should get[0, 4]
and[11, Infinity]
If we cut
[1, 6]
with[0, Infinity]
, we should get[]
If we cut
[0, 6]
with[1, Infinity]
, we should get[0, 0]
If we cut
[-Infinity, Infinity]
with[-Infinity, Infinity]
we should get[]
Overlapping cuts
There are many combinations where cuts include each other or could be sorted wrong. Many new combinations added. Including infinite case.