// Copyright (c) 2012, 2015 Kiel University and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0

package components

import (
	
	basegraph 
	
)

// graphPlacer is the arena-backed counterpart of AbstractGraphPlacer.
type graphPlacer interface {
	combine(*layered.LGraphArena, []layered.LGraphID, layered.LGraphID) error
}

func moveGraphs(
	 *layered.LGraphArena,
	 layered.LGraphID,
	 []layered.LGraphID,
	 geometry.Point,
) {
	for ,  := range  {
		moveGraph(, , , )
	}
}

// moveGraph applies both the supplied offset and the source graph's own
// offset. Like the Java method, it must only be called once for a source.
func moveGraph(
	 *layered.LGraphArena,
	,  layered.LGraphID,
	 geometry.Point,
) {
	 := .Graph()
	 := .Offset.Add()
	for ,  := range .LayerlessNodes {
		offsetNodeAndOutgoingEdges(, , )
		.Graph().LayerlessNodes = append(
			.Graph().LayerlessNodes, )
		.Node().Graph = 
	}
}

func offsetGraph( *layered.LGraphArena,  layered.LGraphID,  geometry.Point) {
	for ,  := range .Graph().LayerlessNodes {
		offsetNodeAndOutgoingEdges(, , )
	}
}

func offsetNodeAndOutgoingEdges(
	 *layered.LGraphArena,
	 layered.LNodeID,
	 geometry.Point,
) {
	 := .Node()
	.Position = .Position.Add()
	for ,  := range .Ports {
		for ,  := range .Port().OutgoingEdges {
			 := .Edge()
			.BendPoints = .BendPoints.Offset()
			if ,  := basegraph.TryGet(
				&.Properties, layered.JunctionPoints,
			);  {
				basegraph.Set(&.Properties, layered.JunctionPoints,
					.Offset())
			}
			for ,  := range .Labels {
				 := .Label()
				.Position = .Position.Add()
			}
		}
	}
}