From b2a639540126d5083c90bddee83128c88863adae Mon Sep 17 00:00:00 2001 From: Mayank Mohapatra <125661248+Mayank77maruti@users.noreply.github.com> Date: Sat, 22 Feb 2025 09:54:19 +0000 Subject: [PATCH] try --- d2layouts/d2cycle/layout.go | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/d2layouts/d2cycle/layout.go b/d2layouts/d2cycle/layout.go index 940a2ff09..3a661b1a8 100644 --- a/d2layouts/d2cycle/layout.go +++ b/d2layouts/d2cycle/layout.go @@ -101,6 +101,29 @@ func createCircularArc(edge *d2graph.Edge) { edge.IsCurve = true } +// func clampPointOutsideBox(box *geo.Box, path []*geo.Point, startIdx int) (int, *geo.Point) { +// if startIdx >= len(path)-1 { +// return startIdx, path[startIdx] +// } +// if !boxContains(box, path[startIdx]) { +// return startIdx, path[startIdx] +// } + +// for i := startIdx + 1; i < len(path); i++ { +// if boxContains(box, path[i]) { +// continue +// } +// seg := geo.NewSegment(path[i-1], path[i]) +// inters := boxIntersections(box, *seg) +// if len(inters) > 0 { +// return i, inters[0] +// } +// return i, path[i] +// } +// last := len(path) - 1 +// return last, path[last] +// } + func clampPointOutsideBox(box *geo.Box, path []*geo.Point, startIdx int) (int, *geo.Point) { if startIdx >= len(path)-1 { return startIdx, path[startIdx] @@ -116,6 +139,7 @@ func clampPointOutsideBox(box *geo.Box, path []*geo.Point, startIdx int) (int, * seg := geo.NewSegment(path[i-1], path[i]) inters := boxIntersections(box, *seg) if len(inters) > 0 { + // Optionally, if multiple intersections are returned, choose the one nearest to path[i-1] return i, inters[0] } return i, path[i] @@ -146,13 +170,20 @@ func clampPointOutsideBoxReverse(box *geo.Box, path []*geo.Point, endIdx int) (i return 0, path[0] } +// func boxContains(b *geo.Box, p *geo.Point) bool { +// return p.X >= b.TopLeft.X && +// p.X <= b.TopLeft.X+b.Width && +// p.Y >= b.TopLeft.Y && +// p.Y <= b.TopLeft.Y+b.Height +// } func boxContains(b *geo.Box, p *geo.Point) bool { - return p.X >= b.TopLeft.X && - p.X <= b.TopLeft.X+b.Width && - p.Y >= b.TopLeft.Y && - p.Y <= b.TopLeft.Y+b.Height + return p.X > b.TopLeft.X && + p.X < b.TopLeft.X+b.Width && + p.Y > b.TopLeft.Y && + p.Y < b.TopLeft.Y+b.Height } + func boxIntersections(b *geo.Box, seg geo.Segment) []*geo.Point { return b.Intersections(seg) }