From adf3c651e2fe1f2e11a011cc3d35e1373d138dd7 Mon Sep 17 00:00:00 2001 From: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com> Date: Sat, 8 Mar 2025 10:42:17 +0000 Subject: [PATCH] try --- d2layouts/d2cycle/layout.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/d2layouts/d2cycle/layout.go b/d2layouts/d2cycle/layout.go index 73f663551..6cee125be 100644 --- a/d2layouts/d2cycle/layout.go +++ b/d2layouts/d2cycle/layout.go @@ -41,12 +41,22 @@ func Layout(ctx context.Context, g *d2graph.Graph, layout d2graph.LayoutGraph) e func calculateRadius(objects []*d2graph.Object) float64 { numObjects := float64(len(objects)) - maxSize := 0.0 - for _, obj := range objects { - size := math.Max(obj.Box.Width, obj.Box.Height) - maxSize = math.Max(maxSize, size) + if numObjects == 0 { + return MIN_RADIUS } - minRadius := (maxSize/2.0 + PADDING) / math.Sin(math.Pi/numObjects) + + maxDiagonal := 0.0 + for _, obj := range objects { + // Calculate the diagonal of the object's bounding box + diagonal := math.Sqrt(obj.Box.Width*obj.Box.Width + obj.Box.Height*obj.Box.Height) + if diagonal > maxDiagonal { + maxDiagonal = diagonal + } + } + + // Required chord length: sum of two radii (maxDiagonal/2) + padding + requiredChordLength := maxDiagonal + PADDING + minRadius := requiredChordLength / (2 * math.Sin(math.Pi/numObjects)) return math.Max(minRadius, MIN_RADIUS) }