]> granicus.if.org Git - graphviz/commitdiff
arrows: arrow_length_box: take edge penwidth into account when calculating length
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 4 Oct 2022 11:40:45 +0000 (13:40 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Fri, 14 Oct 2022 13:59:16 +0000 (15:59 +0200)
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.

lib/common/arrows.c
tests/test_edge_node_overlap_box_edge_arrow.cpp

index 0047235bdef5059518338b4600296fdc2934cd93..80ef590f1a002fa60187ac854d2818a1f7ff01df 100644 (file)
@@ -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;
+}
index dd5763f2ebf80bf14ba0b230fa7a782ada413177..accbed814036ce319947f249c55c33651aacadfd 100644 (file)
@@ -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";