From: Magnus Jacobsson Date: Fri, 16 Sep 2022 08:53:36 +0000 (+0200) Subject: shapes: poly_init: fix clipping of edge at node outline for ellipse node shapes X-Git-Tag: 7.0.0~21^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1a03d58771a11977cd46fdceed6cd3227e512d6;p=graphviz shapes: poly_init: fix clipping of edge at node outline for ellipse node shapes Take node penwidth into account also for ellipse node shapes. Following the fix for polygon node shapes, this fixes the second part of arrow not respecting penwith for ellipse shapes other than 'point'. Similar fixes need to be applied to fix the second part for the 'point' and 'cylinder' node shapes. The test_edge_node_overlap_ellipse_node_shapes_except_point test now succeeds, so the expectancy that it should fail is removed. Towards https://gitlab.com/graphviz/graphviz/-/issues/372. --- diff --git a/lib/common/shapes.c b/lib/common/shapes.c index 41b68e001..a392816fb 100644 --- a/lib/common/shapes.c +++ b/lib/common/shapes.c @@ -2067,6 +2067,13 @@ static void poly_init(node_t * n) outp = peripheries; if (peripheries < 1) outp = 1; + + if (peripheries >= 1 && penwidth > 0) { + // allocate extra vertices representing the outline, i.e., the outermost + // periphery with penwidth taken into account + ++outp; + } + if (sides < 3) { /* ellipses */ sides = 2; vertices = N_NEW(outp * sides, pointf); @@ -2091,6 +2098,20 @@ static void poly_init(node_t * n) bb.y = 2. * P.y; } outline_bb = bb; + if (outp > peripheries) { + // add an outline at half the penwidth outside the outermost periphery + P.x += penwidth / 2; + P.y += penwidth / 2; + i = sides * peripheries; + vertices[i].x = -P.x; + vertices[i].y = -P.y; + i++; + vertices[i].x = P.x; + vertices[i].y = P.y; + i++; + outline_bb.x = 2. * P.x; + outline_bb.y = 2. * P.y; + } } else { /* @@ -2106,12 +2127,6 @@ static void poly_init(node_t * n) * the current segments, and outside by GAP distance, intersect. */ - if (peripheries >= 1 && penwidth > 0) { - // allocate extra vertices representing the outline, i.e., the outermost - // periphery with penwidth taken into account - ++outp; - } - vertices = N_NEW(outp * sides, pointf); if (ND_shape(n)->polygon->vertices) { poly_desc_t* pd = (poly_desc_t*)ND_shape(n)->polygon->vertices; diff --git a/tests/test_edge_node_overlap_ellipse_node_shapes_except_point.cpp b/tests/test_edge_node_overlap_ellipse_node_shapes_except_point.cpp index 2fab50089..61a1d43be 100644 --- a/tests/test_edge_node_overlap_ellipse_node_shapes_except_point.cpp +++ b/tests/test_edge_node_overlap_ellipse_node_shapes_except_point.cpp @@ -7,10 +7,10 @@ #include "test_edge_node_overlap_utilities.h" #include "test_utilities.h" -TEST_CASE("Overlap ellipse node shapes", - "[!shouldfail] Test that an edge connected to an ellipse based node " - "touches that node and does not overlap it too much, regardless of " - "the node shape") { +TEST_CASE( + "Overlap ellipse node shapes", + "Test that an edge connected to an ellipse based node touches that " + "node and does not overlap it too much, regardless of the node shape") { const auto shape = GENERATE_COPY( filter([](const std::string_view shape) { return shape != "point"; },