Skip to content

Commit

Permalink
another couple of tests that were meant to be outside the loop, not i…
Browse files Browse the repository at this point in the history
…nside #13
  • Loading branch information
sobri909 committed May 29, 2018
1 parent 2d65a0b commit 9f8c26b
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions LocoKit/LocalStore/PersistentProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class PersistentProcessor {

// MARK: - Brexits
// MARK: - ItemSegment brexiting

public static func extractItem(for segment: ItemSegment, in store: PersistentTimelineStore, completion: ((TimelineItem?) -> Void)? = nil) {
store.process {
Expand All @@ -27,29 +27,25 @@ public class PersistentProcessor {
for overlapper in overlappers {
var lostPrevEdge = false, lostNextEdge = false

for sample in overlapper.samples {

// sample is inside the segment's range?
if segmentRange.contains(sample.date) {
if sample == overlapper.samples.first { lostPrevEdge = true }
if sample == overlapper.samples.last { lostNextEdge = true }
print("Moving sample from overlapper to inserted item")
samplesToSteal.append(sample)
}
// find samples inside the segment's range
for sample in overlapper.samples where segmentRange.contains(sample.date) {
if sample == overlapper.samples.first { lostPrevEdge = true }
if sample == overlapper.samples.last { lostNextEdge = true }
samplesToSteal.append(sample)
}

// detach previous edge, if modified
if lostPrevEdge {
print("Detaching overlapper.previousItem")
overlapper.previousItem = nil
modifiedItems.append(overlapper)
}
// detach previous edge, if modified
if lostPrevEdge {
print("Detaching overlapper.previousItem")
overlapper.previousItem = nil
modifiedItems.append(overlapper)
}

// detach next edge, if modified
if lostNextEdge {
print("Detaching overlapper.nextItem")
overlapper.nextItem = nil
modifiedItems.append(overlapper)
}
// detach next edge, if modified
if lostNextEdge {
print("Detaching overlapper.nextItem")
overlapper.nextItem = nil
modifiedItems.append(overlapper)
}

// if only extracted from middle, split the item in two
Expand All @@ -63,7 +59,10 @@ public class PersistentProcessor {
let newItem = createItem(from: segment, in: store)

// add the stolen samples to the new item
newItem.add(samplesToSteal)
if !samplesToSteal.isEmpty {
print("Moving \(samplesToSteal.count) samples from overlappers to inserted item")
newItem.add(samplesToSteal)
}

// delete any newly empty items
for modifiedItem in modifiedItems where modifiedItem.samples.isEmpty {
Expand Down

0 comments on commit 9f8c26b

Please sign in to comment.