package placement

import (
	
	
	

	
	
	
	
)

// moveNodeToBest chooses the candidate with the lowest placement cost using
// the compaction stage's shared work guard.
func moveNodeToBest( context.Context,  *layoutgraph.Graph,  *layoutgraph.Node,  []*geo.Point,  []*layoutgraph.EdgeAbduction,  bool,  *limits.OptimizationWorkGuard) (bool, error) {
	if  == nil {
		return false, fmt.Errorf("TALA moveNodeToBest requires a work guard")
	}
	if  := .Finish();  != nil {
		return false, 
	}

	 := .CellSize * float64(len(.Edges))
	 := math.Inf(1)
	 := .TopLeft.Copy()
	,  := .TopLeft.X, .TopLeft.Y

	,  := optimizerFixedOrigin(, .EffectiveContainer(), )
	if  != nil {
		return false, 
	}
	if  != nil && ! {
		.X = math.Round(.X / .CellSize)
		.Y = math.Round(.Y / .CellSize)
	}

	for ,  := range  {
		if  := .Step();  != nil {
			return false, 
		}
		if  == nil {
			return false, fmt.Errorf("TALA %s found a nil placement point", .Location())
		}
		,  := .X, .Y
		if  != nil && ( < .X ||  < .Y) {
			continue
		}
		 :=  ==  &&  == 
		if ! {
			,  = optimizerCanMove(, , , )
			if  != nil {
				return false, 
			}
		}
		if ! {
			continue
		}
		if  := optimizerMoveNodeAbs(, , , );  != nil {
			return false, 
		}
		if  := chargeOptimizerScoring(, , , );  != nil {
			return false, 
		}
		,  := placementcost.NodeEdgeLength(, , placementcost.EdgeLengthOptions{EdgeAbductions: , IncludeNodeSizes: , EnforceMinimumGap: false, PenalizeDirection: true})
		if  != nil {
			return false, 
		}
		if  {
			if !math.IsInf(, 1) && geo.PrecisionCompare(-, , geo.PRECISION) == 1 {
				continue
			}
			,  := placementcost.ColumnCrossingCost(, , )
			if  != nil {
				return false, 
			}
			,  := placementcost.NodeSymmetry(, , )
			if  != nil {
				return false, 
			}
			 += 
			 -=  * 
		}
		switch geo.PrecisionCompare(, , geo.PRECISION) {
		case -1:
			,  = , 
		case 0:
			if .X ==  && .Y ==  {
				,  = , 
			}
		}
	}

	if  := .Err();  != nil {
		return false, fmt.Errorf("EdgeLength: %w", )
	}
	if math.IsInf(, 1) {
		return false, fmt.Errorf("sizedOptimizer.moveNodeToBest: could not find any placement")
	}
	if  := optimizerMoveNodeAbs(, .X, .Y, );  != nil {
		return false, 
	}
	if  := .Finish();  != nil {
		return false, 
	}
	return .TopLeft.X !=  || .TopLeft.Y != , nil
}