From a32319d59838ad845b305f3e62d458ad1c229ffa Mon Sep 17 00:00:00 2001 From: Gavin Nishizawa Date: Wed, 12 Jul 2023 15:30:41 -0700 Subject: [PATCH] fix dagre_broken_arrowhead --- d2graph/layout.go | 8 ++++---- d2layouts/d2dagrelayout/layout.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/d2graph/layout.go b/d2graph/layout.go index 4b53cee12..05ef65fb0 100644 --- a/d2graph/layout.go +++ b/d2graph/layout.go @@ -346,7 +346,7 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n points[startIndex] = p startingSegment.End = p // if the segment becomes too short, just merge it with the next segment - if startIndex+1 < len(points)-1 && startingSegment.Length() < MIN_SEGMENT_LEN { + if startIndex+1 < endIndex && startingSegment.Length() < MIN_SEGMENT_LEN { points[startIndex+1] = points[startIndex] startIndex++ } @@ -359,7 +359,7 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n points[startIndex] = intersections[0] startingSegment.End = intersections[0] // if the segment becomes too short, just merge it with the next segment - if startIndex+1 < len(points)-1 && startingSegment.Length() < MIN_SEGMENT_LEN { + if startIndex+1 < endIndex && startingSegment.Length() < MIN_SEGMENT_LEN { points[startIndex+1] = points[startIndex] startIndex++ } @@ -391,7 +391,7 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n points[endIndex] = p endingSegment.End = p // if the segment becomes too short, just merge it with the previous segment - if endIndex-1 > 0 && endingSegment.Length() < MIN_SEGMENT_LEN { + if endIndex-1 > startIndex && endingSegment.Length() < MIN_SEGMENT_LEN { points[endIndex-1] = points[endIndex] endIndex-- } @@ -404,7 +404,7 @@ func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (n points[endIndex] = intersections[0] endingSegment.End = intersections[0] // if the segment becomes too short, just merge it with the previous segment - if endIndex-1 > 0 && endingSegment.Length() < MIN_SEGMENT_LEN { + if endIndex-1 > startIndex && endingSegment.Length() < MIN_SEGMENT_LEN { points[endIndex-1] = points[endIndex] endIndex-- } diff --git a/d2layouts/d2dagrelayout/layout.go b/d2layouts/d2dagrelayout/layout.go index cea99951f..6949f7179 100644 --- a/d2layouts/d2dagrelayout/layout.go +++ b/d2layouts/d2dagrelayout/layout.go @@ -273,7 +273,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err // arrowheads can appear broken if segments are very short from dagre routing a point just outside the shape // to fix this, we try extending the previous segment into the shape instead of having a very short segment - if !start.Equals(points[0]) && startIndex+2 < len(points) { + if startIndex+2 < len(points) { newStartingSegment := *geo.NewSegment(start, points[startIndex+1]) if newStartingSegment.Length() < d2graph.MIN_SEGMENT_LEN { // we don't want a very short segment right next to the source because it will mess up the arrowhead @@ -294,7 +294,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err } } } - if !end.Equals(points[len(points)-1]) && endIndex-2 >= 0 { + if endIndex-2 >= 0 { newEndingSegment := *geo.NewSegment(end, points[endIndex-1]) if newEndingSegment.Length() < d2graph.MIN_SEGMENT_LEN { // extend the prev segment into the shape border if possible