]> granicus.if.org Git - graphviz/commitdiff
shapes: star_inside: fix clipping of edge at node outline
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 14 Sep 2022 19:58:57 +0000 (21:58 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 11 Oct 2022 19:45:27 +0000 (21:45 +0200)
Take node penwidth into account when doing the clipping of the 'star'
shape. This causes the clipping to occur at the visible node outline
instead of at the "ideal" bounding box which does not take node
penwidth into account.

For the star shape, this fixes the second part of arrow not respecting
penwidth. Similar fixes need to be applied to fix the second part for
other node shapes.

The test_max_edge_node_overlap_node_shapes test case now succeeds, so
the expectancy that it should fail is removed.

Towards https://gitlab.com/graphviz/graphviz/-/issues/372.

lib/common/shapes.c
tests/test_max_edge_node_overlap_polygon_node_shapes.cpp

index 0f595308f6bc74ba0ee5c243fd279426547c9acd..41b68e001a839bdd417f59b5d06529b4b516430a 100644 (file)
@@ -4002,10 +4002,16 @@ static bool star_inside(inside_t * inside_context, pointf p)
        vertex = poly->vertices;
        sides = poly->sides;
 
-       /* index to outer-periphery */
-       outp = (poly->peripheries - 1) * sides;
-       if (outp < 0)
-           outp = 0;
+       const double penwidth = late_int(n, N_penwidth, DEFAULT_NODEPENWIDTH, MIN_NODEPENWIDTH);
+       if (poly->peripheries >= 1 && penwidth > 0) {
+           /* index to outline, i.e., the outer-periphery with penwidth taken into account */
+           outp = (poly->peripheries + 1 - 1) * sides;
+       } else {
+           /* index to outer-periphery */
+           outp = (poly->peripheries - 1) * sides;
+           if (outp < 0)
+               outp = 0;
+       }
        lastn = n;
     }
 
index 182666e56c8b29c021e1f7774f111a66842c006f..6095e82b8f457acf348b85d6d3463386e5464eb2 100644 (file)
@@ -4,10 +4,9 @@
 #include "test_edge_node_overlap_utilities.h"
 #include "test_utilities.h"
 
-TEST_CASE(
-    "Maximum edge and node overlap for polygon node shapes",
-    "[!shouldfail] Test that an edge connected to a polygon based node does "
-    "not overlap that node, regardless of the node shape") {
+TEST_CASE("Maximum edge and node overlap for polygon node shapes",
+          "Test that an edge connected to a polygon based node does not "
+          "overlap that node, regardless of the node shape") {
 
   const auto shape = GENERATE(from_range(node_shapes_consisting_of_polygon));
   INFO("Node shape: " << shape);