package packing

import (
	
	

	
	
	
)

type combineNodePositionSnapshot struct {
	node    *layoutgraph.Node
	topLeft pointerSnapshot[geo.Point]
}

func restoreCombineNodePositions( []combineNodePositionSnapshot) {
	for ,  := range  {
		.node.TopLeft = .topLeft.restore()
	}
}

// snapshotCombineNodePositions captures every position that CombineSubgraphs
// can translate while preserving each point's exact identity.
func snapshotCombineNodePositions( context.Context,  []*layoutgraph.Node) ([]combineNodePositionSnapshot, error) {
	,  := limits.NewWorkGuard(, "CombineSubgraphs", limits.MaxEngineWorkUnits)
	if  != nil {
		return nil, 
	}
	 := make(map[*layoutgraph.Node]struct{})
	 := make([]combineNodePositionSnapshot, 0, len())
	type  struct {
		  *layoutgraph.Node
		 *layoutgraph.Graph
	}
	 := make([], 0, len())
	 := func( *layoutgraph.Node,  *layoutgraph.Graph) error {
		if  == nil {
			return nil
		}
		if ,  := [];  {
			return nil
		}
		if len() >= limits.MaxEngineNodes {
			return fmt.Errorf("TALA CombineSubgraphs unique node count exceeds limit %d", limits.MaxEngineNodes)
		}
		if  := .Step();  != nil {
			return 
		}
		[] = struct{}{}
		 = append(, combineNodePositionSnapshot{node: , topLeft: snapshotPointer(.TopLeft)})
		 = append(, {: , : })
		return nil
	}
	for ,  := range  {
		if  != nil {
			if  := (, .Graph);  != nil {
				return nil, 
			}
		}
	}
	for  := 0;  < len(); ++ {
		 := []
		if . == nil {
			continue
		}
		 := .
		if .IsContainer() {
			for ,  := range ..Containers[] {
				if  := (, .);  != nil {
					return nil, 
				}
			}
		}
		if .IsClusterVessel() {
			if  := ..Clusters[];  != nil {
				for ,  := range .Nodes {
					if  := (, .);  != nil {
						return nil, 
					}
				}
			}
		}
		if  := ..Sequences[];  != nil {
			for ,  := range .Nodes {
				if  := (, .);  != nil {
					return nil, 
				}
			}
		}
	}
	if  := .Finish();  != nil {
		return nil, 
	}
	return , nil
}