]> granicus.if.org Git - graphviz/commitdiff
shapes: poly_init: fix clipping of edge at node outline for ellipse node shapes
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Fri, 16 Sep 2022 08:53:36 +0000 (10:53 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 11 Oct 2022 19:45:27 +0000 (21:45 +0200)
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.

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

index 41b68e001a839bdd417f59b5d06529b4b516430a..a392816fb18bb3c84ce8465695e3dab805b9c1b3 100644 (file)
@@ -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;
index 2fab5008999f64dac16836ca27121d284cdee98d..61a1d43be61e459356f0babe06d322a5ef1c01fe 100644 (file)
@@ -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"; },