From: Magnus Jacobsson Date: Tue, 4 Oct 2022 11:40:45 +0000 (+0200) Subject: arrows: arrow_length_box: take edge penwidth into account when calculating length X-Git-Tag: 7.0.0~10^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dad7d7fe3e5a11442701f20aea40143f62fe8757;p=graphviz arrows: arrow_length_box: take edge penwidth into account when calculating length The test_edge_node_overlap_box_edge_arrow test case now succeeds, so the expectancy that it should fail is removed. Towards https://gitlab.com/graphviz/graphviz/-/issues/372. --- diff --git a/lib/common/arrows.c b/lib/common/arrows.c index 0047235bd..80ef590f1 100644 --- a/lib/common/arrows.c +++ b/lib/common/arrows.c @@ -124,12 +124,13 @@ static pointf arrow_type_gap(GVJ_t * job, pointf p, pointf u, double arrowsize, static double arrow_length_generic(double lenfact, double arrowsize, double penwidth, int flag); static double arrow_length_normal(double lenfact, double arrowsize, double penwidth, int flag); +static double arrow_length_box(double lenfact, double arrowsize, double penwidth, int flag); static const arrowtype_t Arrowtypes[] = { {ARR_TYPE_NORM, 1.0, arrow_type_normal, arrow_length_normal}, {ARR_TYPE_CROW, 1.0, arrow_type_crow, arrow_length_generic}, {ARR_TYPE_TEE, 0.5, arrow_type_tee, arrow_length_generic}, - {ARR_TYPE_BOX, 1.0, arrow_type_box, arrow_length_generic}, + {ARR_TYPE_BOX, 1.0, arrow_type_box, arrow_length_box}, {ARR_TYPE_DIAMOND, 1.2, arrow_type_diamond, arrow_length_generic}, {ARR_TYPE_DOT, 0.8, arrow_type_dot, arrow_length_generic}, {ARR_TYPE_CURVE, 1.0, arrow_type_curve, arrow_length_generic}, @@ -983,3 +984,14 @@ static double arrow_length_normal(double lenfact, double arrowsize, // the positive x axis and ends at origin return full_length - overlap; } + +static double arrow_length_box(double lenfact, double arrowsize, + double penwidth, int flag) { + (void)flag; + + // The `box` arrow shape begins with a polyline which doesn't extend + // visually beyond its starting point, so we only have to take penwidth + // into account at the end point. + + return lenfact * arrowsize * ARROW_LENGTH + penwidth / 2; +} diff --git a/tests/test_edge_node_overlap_box_edge_arrow.cpp b/tests/test_edge_node_overlap_box_edge_arrow.cpp index dd5763f2e..accbed814 100644 --- a/tests/test_edge_node_overlap_box_edge_arrow.cpp +++ b/tests/test_edge_node_overlap_box_edge_arrow.cpp @@ -6,8 +6,8 @@ #include "test_utilities.h" TEST_CASE("Edge node overlap for box arrow", - "[!shouldfail] An edge connected to a node shall touch that node and " - "not overlap it too much") { + "An edge connected to a node shall touch that node and not overlap " + "it too much") { const std::string_view primitive_arrow_shape = "box";