Fixing overlapping intervals bug (#138)

why:
  did not properly merge
This commit is contained in:
Jordan Hrycaj 2022-08-16 14:21:01 +01:00 committed by GitHub
parent 0476bcad1b
commit 1e86bd1ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -426,14 +426,15 @@ proc merge[P,S](ds: Desc[P,S]; iv: Segm[P,S]): Segm[P,S] =
# iv: ...----------------)
# p: ...-----)
#
p.blk.size += iv.len # update database
ds.ptsCount += iv.len # update database
let extend = iv.right - p.right
p.blk.size += extend # update database
ds.ptsCount += extend # update database
#
# iv: ...----------------)
# p: ...----------------)
# result: [---------)
#
return Segm[P,S].new(p.right, iv.right)
return Segm[P,S].new(p.right - extend, iv.right)
# now: iv.right <= p.right and p.left <= iv.left:
if p.left <= iv.left:

View File

@ -239,6 +239,18 @@ suite "IntervalSet: Intervals of FancyPoint entries over FancyScalar":
check br.ge(uHigh) == iv(uHigh,uHigh)
check br.envelope(uHigh) == iv(uHigh,uHigh)
test "Merge overlapping intervals":
br.clear()
check br.merge(100, 199) == 100
check br.merge(150, 200) == 1
check br.total == 101
check br.chunks == 1
check br.verify.isOk
check br.merge( 99, 150) == 1
check br.total == 102
check br.chunks == 1
check br.verify.isOk
test "Merge disjunct intervals on 1st set":
br.clear()
check br.merge( 0, 99) == 100