// CCMapAll computes a map of the connected components. It makes the
// assumption that the paths are bidirectional, allowing for efficient
// computation. This means, in particular, that the pather should return no
// neighbors for obstacles.
CCMapAll computes a map of the connected components. It makes the
assumption that the paths are bidirectional, allowing for efficient
computation. This means, in particular, that the pather should return no
neighbors for obstacles.
// CCMapAll computes a map of the connected components . It makes the // assumption that the paths are bidirectional allowing for efficient // computation . This means in particular that the pather should return no // neighbors for obstacles .
func (pr *PathRange) CCMapAll(nb Pather) {
	max := pr.Rg.Size()
	w, h := max.X, max.Y
	if pr.CC == nil {
		pr.CC = make([]int, w*h)
	} else {
		for i := range pr.CC {
			pr.CC[i] = 0
		}
	}
	pr.CCStack = pr.CCStack[:0]
	ccid := 1
	for i := 0; i < len(pr.CC); i++ {
		if pr.CC[i] > 0 {
			continue
		}
		pr.CC[i] = ccid
		pr.CCStack = append(pr.CCStack, i)
		for len(pr.CCStack) > 0 {
			idx := pr.CCStack[len(pr.CCStack)-1]
			pr.CCStack = pr.CCStack[:len(pr.CCStack)-1]
			p := idxToPos(idx, w)
			for _, q := range nb.Neighbors(p) {
				if !q.In(pr.Rg) {
					continue
				}
				nidx := pr.idx(q)
				if pr.CC[nidx] > 0 {
					continue
				}
				pr.CC[nidx] = ccid
				pr.CCStack = append(pr.CCStack, nidx)
			}
		}
		ccid++
	}
}
func ( pr * PathRange ) CCMapAll ( nb Pather ) { max := pr . Rg . Size ( ) w , h := max . X , max . Y if pr . CC == nil { pr . CC = make ( [ ] int , w * h ) } else { for i := range pr . CC { pr . CC [ i ] = 0 } } pr . CCStack = pr . CCStack [ : 0 ] ccid := 1 for i := 0 ; i < len ( pr . CC ) ; i ++ { if pr . CC [ i ] > 0 { continue } pr . CC [ i ] = ccid pr . CCStack = append ( pr . CCStack , i ) for len ( pr . CCStack ) > 0 { idx := pr . CCStack [ len ( pr . CCStack ) - 1 ] pr . CCStack = pr . CCStack [ : len ( pr . CCStack ) - 1 ] p := idxToPos ( idx , w ) for _ , q := range nb . Neighbors ( p ) { if ! q . In ( pr . Rg ) { continue } nidx := pr . idx ( q ) if pr . CC [ nidx ] > 0 { continue } pr . CC [ nidx ] = ccid pr . CCStack = append ( pr . CCStack , nidx ) } } ccid ++ } }
CCMapAll computes a map of the connected components.
CCMapAll computes a map of the connected components .