Esempio n. 1
0
func findXHoles(blocks []*indexRLE, minX, maxX int32) (bestBeg, bestEnd int32, found bool) {
	nx := maxX - minX + 1
	used := make([]bool, nx, nx)

	for _, rle := range blocks {
		spanBeg := rle.start[0]
		if spanBeg > maxX {
			continue
		}
		spanEnd := spanBeg + int32(rle.span) - 1
		if spanEnd < minX {
			continue
		}
		x0 := dvid.MaxInt32(minX, spanBeg)
		x1 := dvid.MinInt32(maxX, spanEnd)

		for x := x0; x <= x1; x++ {
			i := x - minX
			used[i] = true
		}
	}

	// See if there are holes.
	var holeSize, bestSize int32
	var holeBeg, holeEnd int32
	var inHole bool
	for x := minX; x <= maxX; x++ {
		i := x - minX
		if !used[i] {
			if inHole {
				holeEnd = x
				holeSize++
			} else {
				inHole = true
				holeBeg = x
				holeEnd = x
				holeSize = 1
			}
		} else {
			inHole = false
		}
		if holeSize > bestSize {
			bestSize = holeSize
			bestBeg = holeBeg
			bestEnd = holeEnd
		}
	}
	if bestSize > 0 {
		found = true
	}
	return
}
Esempio n. 2
0
func findActives(blocks []*indexRLE, minX, maxX int32) int32 {
	var numActive int32
	for _, rle := range blocks {
		spanBeg := rle.start[0]
		if spanBeg > maxX {
			continue
		}
		spanEnd := spanBeg + int32(rle.span) - 1
		if spanEnd < minX {
			continue
		}
		x0 := dvid.MaxInt32(minX, spanBeg)
		x1 := dvid.MinInt32(maxX, spanEnd)
		numActive += x1 - x0 + 1
	}
	return numActive
}