// Copyright (c) 2010, 2019 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 intermediate

import (
	

	
	
)

// CalculateInnermostNodeMargins ports ELK 0.8.1's
// InnermostNodeMarginCalculator. In particular, it deliberately excludes edge
// head and tail labels: EndLabelPreprocessor places those precisely after this
// baseline margin has been recomputed.
func ( *layered.LGraphArena,  layered.LGraphID) {
	for ,  := range .Graph().Layers {
		for ,  := range .Layer().Nodes {
			calculateInnermostNodeMargin(, )
		}
	}
}

func calculateInnermostNodeMargin( *layered.LGraphArena,  layered.LNodeID) {
	 := .Node()
	 := geometry.Rectangle{
		X:      .Position.X,
		Y:      .Position.Y,
		Width:  .Size.X,
		Height: .Size.Y,
	}

	for ,  := range .Labels {
		 := .Label()
		 = .Union(geometry.Rectangle{
			X:      .Position.X + .Position.X,
			Y:      .Position.Y + .Position.Y,
			Width:  .Size.X,
			Height: .Size.Y,
		})
	}
	for ,  := range .Ports {
		 := .Port()
		 := .Position.X + .Position.X
		 := .Position.Y + .Position.Y
		 = .Union(geometry.Rectangle{
			X:      ,
			Y:      ,
			Width:  .Size.X,
			Height: .Size.Y,
		})
		for ,  := range .Labels {
			 := .Label()
			 = .Union(geometry.Rectangle{
				X:       + .Position.X,
				Y:       + .Position.Y,
				Width:  .Size.X,
				Height: .Size.Y,
			})
		}
	}

	.Margin.Top = math.Max(0, .Position.Y-.Y)
	.Margin.Bottom = math.Max(0, .MaxY()-(.Position.Y+.Size.Y))
	.Margin.Left = math.Max(0, .Position.X-.X)
	.Margin.Right = math.Max(0, .MaxX()-(.Position.X+.Size.X))
}