// CCMap computes the connected component which contains a given position.
// It returns a cached slice with all the positions in the same connected
// component as p, or nil if p is out of range.  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.
//
// It makes uses of the same caching structures as ComputeCCAll, so CCAt will
// return -1 on all unreachable positions from p.
CCMap computes the connected component which contains a given position.
It returns a cached slice with all the positions in the same connected
component as p, or nil if p is out of range.  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.

It makes uses of the same caching structures as ComputeCCAll, so CCAt will
return -1 on all unreachable positions from p.
// CCMap computes the connected component which contains a given position . // It returns a cached slice with all the positions in the same connected // component as p or nil if p is out of range . 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 . // // It makes uses of the same caching structures as ComputeCCAll so CCAt will // return - 1 on all unreachable positions from p .
func (pr *PathRange) CCMap(nb Pather, p gruid.Point) []gruid.Point {
	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
		}
	}
	if pr.CCIterCache == nil {
		pr.CCIterCache = make([]gruid.Point, w*h)
	}
	pr.CCIterCache = pr.CCIterCache[:0]
	pr.CCStack = pr.CCStack[:0]
	if !p.In(pr.Rg) {
		return nil
	}
	idx := pr.idx(p)
	ccid := 1
	pr.CC[idx] = ccid
	pr.CCStack = append(pr.CCStack, idx)
	for len(pr.CCStack) > 0 {
		idx = pr.CCStack[len(pr.CCStack)-1]
		pr.CCStack = pr.CCStack[:len(pr.CCStack)-1]
		p := idxToPos(idx, w)
		pr.CCIterCache = append(pr.CCIterCache, p)
		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)
		}
	}
	return pr.CCIterCache
}
func ( pr * PathRange ) CCMap ( nb Pather , p gruid . Point ) [ ] gruid . Point { 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 } } if pr . CCIterCache == nil { pr . CCIterCache = make ( [ ] gruid . Point , w * h ) } pr . CCIterCache = pr . CCIterCache [ : 0 ] pr . CCStack = pr . CCStack [ : 0 ] if ! p . In ( pr . Rg ) { return nil } idx := pr . idx ( p ) ccid := 1 pr . CC [ idx ] = ccid pr . CCStack = append ( pr . CCStack , idx ) for len ( pr . CCStack ) > 0 { idx = pr . CCStack [ len ( pr . CCStack ) - 1 ] pr . CCStack = pr . CCStack [ : len ( pr . CCStack ) - 1 ] p := idxToPos ( idx , w ) pr . CCIterCache = append ( pr . CCIterCache , p ) 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 ) } } return pr . CCIterCache }
CCMap computes the connected component which contains a given position.
CCMap computes the connected component which contains a given position .