// Copyright (c) 2016 Kiel University and others.
// Copyright (c) 2026 The elk-go Authors.
//
// 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 wrapping

import (
	
	basegraph 
	
)

// RemoveBreakingPoints reassembles each split edge after routing and removes
// the paired breaking-point markers.
func ( *layered.LGraphArena,  layered.LGraphID) {
	 := basegraph.Get(&.Graph().Properties, layered.EdgeRoutingOption)
	for ,  := range .Graph().Layers {
		for ,  := range append([]layered.LNodeID(nil), .Layer().Nodes...) {
			if !IsBreakingPointEnd(, ) {
				continue
			}
			 := basegraph.Get(&.Node().Properties, breakingPointInfo)
			if .Next == nil {
				removeBreakingPoint(, , )
			}
		}
	}
}

func removeBreakingPoint(
	 *layered.LGraphArena,
	 *BPInfo,
	 layered.EdgeRouting,
) {
	 := .Edge(.OriginalEdge)
	 := make(geometry.Chain, 0,
		len(.Edge(.NodeStartEdge).BendPoints)+
			len(.Edge(.StartEndEdge).BendPoints)+len(.BendPoints)+2)
	switch  {
	case layered.EdgeRoutingSplines:
		,  := basegraph.TryGet(&.Edge(.NodeStartEdge).Properties, layered.SplineControlPointSegments)
		,  := basegraph.TryGet(&.Edge(.StartEndEdge).Properties, layered.SplineControlPointSegments)
		,  := basegraph.TryGet(&.Properties, layered.SplineControlPointSegments)
		 := make([]geometry.Chain, 0, len()+len()+len())
		for ,  := range  {
			 = append(, )
		}
		for  := len() - 1;  >= 0; -- {
			 = append(, [].Reverse())
		}
		for ,  := range  {
			 = append(, )
		}
		basegraph.Set(&.Properties, layered.SplineControlPointSegments, )
		basegraph.Unset(&.Edge(.NodeStartEdge).Properties, layered.SplineControlPointSegments)
		basegraph.Unset(&.Edge(.StartEndEdge).Properties, layered.SplineControlPointSegments)

		,  := basegraph.TryGet(
			&.Edge(.NodeStartEdge).Properties, layered.SplineCompactionSegments)
		,  := basegraph.TryGet(
			&.Edge(.StartEndEdge).Properties, layered.SplineCompactionSegments)
		,  := basegraph.TryGet(
			&.Properties, layered.SplineCompactionSegments)
		 := make([]layered.SplineCompactionSegment, 0,
			len()+len()+len())
		 = append(, ...)
		for  := len() - 1;  >= 0; -- {
			 = append(, [])
		}
		 = append(, ...)
		basegraph.Set(&.Properties, layered.SplineCompactionSegments, )
		basegraph.Unset(&.Edge(.NodeStartEdge).Properties, layered.SplineCompactionSegments)
		basegraph.Unset(&.Edge(.StartEndEdge).Properties, layered.SplineCompactionSegments)
	case layered.EdgeRoutingPolyline:
		 = append(, .Edge(.NodeStartEdge).BendPoints...)
		 = append(, .Node(.Start).Position)
		 = append(, .Edge(.StartEndEdge).BendPoints.Reverse()...)
		 = append(, .Node(.End).Position)
		 = append(, .BendPoints...)
	default:
		 = append(, .Edge(.NodeStartEdge).BendPoints...)
		 = append(, .Edge(.StartEndEdge).BendPoints.Reverse()...)
		 = append(, .BendPoints...)
	}
	.BendPoints = 
	 := *.Edge(.NodeStartEdge).Source
	.SetEdgeSource(.OriginalEdge, &)

	,  := basegraph.TryGet(&.Edge(.NodeStartEdge).Properties, layered.JunctionPoints)
	,  := basegraph.TryGet(&.Edge(.StartEndEdge).Properties, layered.JunctionPoints)
	,  := basegraph.TryGet(&.Properties, layered.JunctionPoints)
	if  ||  ||  {
		 := .Clone()
		 = append(, ...)
		 = append(, ...)
		basegraph.Set(&.Properties, layered.JunctionPoints, )
	}

	.SetEdgeSource(.StartEndEdge, nil)
	.SetEdgeTarget(.StartEndEdge, nil)
	.SetEdgeSource(.NodeStartEdge, nil)
	.SetEdgeTarget(.NodeStartEdge, nil)
	.SetNodeLayer(.End, nil)
	.SetNodeLayer(.Start, nil)
	if .Prev != nil {
		(, .Prev, )
	}
}