From: Magnus Jacobsson Date: Tue, 4 Oct 2022 11:40:09 +0000 (+0200) Subject: arrows: arrow_type_box: fix positioning of box arrow X-Git-Tag: 7.0.0~10^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=475bd815124f4d6505b909dad75e0696016af9a8;p=graphviz arrows: arrow_type_box: fix positioning of box arrow Towards https://gitlab.com/graphviz/graphviz/-/issues/372. --- diff --git a/lib/common/arrows.c b/lib/common/arrows.c index 00cc94d42..0047235bd 100644 --- a/lib/common/arrows.c +++ b/lib/common/arrows.c @@ -701,6 +701,21 @@ static pointf arrow_type_box(GVJ_t * job, pointf p, pointf u, double arrowsize, m.y = p.y + u.y * 0.8; q.x = p.x + u.x; q.y = p.y + u.y; + + const pointf P = {-u.x, -u.y}; + // phi = angle of arrow + const double cosPhi = P.x / hypot(P.x, P.y); + const double sinPhi = P.y / hypot(P.x, P.y); + const pointf delta = {penwidth / 2.0 * cosPhi, penwidth / 2.0 * sinPhi}; + + // move the arrow backwards to not visually overlap the node + p.x -= delta.x; + p.y -= delta.y; + m.x -= delta.x; + m.y -= delta.y; + q.x -= delta.x; + q.y -= delta.y; + a[0].x = p.x + v.x; a[0].y = p.y + v.y; a[1].x = p.x - v.x; @@ -721,6 +736,9 @@ static pointf arrow_type_box(GVJ_t * job, pointf p, pointf u, double arrowsize, a[1] = q; gvrender_polyline(job, a, 2); + // A polyline doesn't extend visually beyond its starting point, so we + // return the starting point as it is, without taking penwidth into account + return q; }