]> granicus.if.org Git - graphviz/commitdiff
tests: test_edge_node_overlap_utilities: check edge/node min overlap
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 24 Aug 2022 14:32:25 +0000 (16:32 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 20 Sep 2022 15:53:06 +0000 (17:53 +0200)
tests/test_edge_node_overlap_simple.cpp
tests/test_edge_node_overlap_utilities.cpp
tests/test_edge_node_overlap_utilities.h

index e7893946de5513c71c6a7aba8c88b91090152558..1989d98ed6e2661dc5f446dd11e7acfadacf30b4 100644 (file)
@@ -5,9 +5,9 @@
 #include "test_edge_node_overlap_utilities.h"
 #include "test_utilities.h"
 
-TEST_CASE(
-    "Overlap",
-    "[!shouldfail] An edge connected to a node shall not overlap that node") {
+TEST_CASE("Edge node overlap",
+          "[!shouldfail] An edge connected to a node shall touch that node and "
+          "not overlap it too much") {
 
   const graph_options graph_options = {
       .node_shape = "polygon",
index cb8b81035cf6648ffbd7d7d1af53c3b8b7afd870..6e218d2131cc924e13e50c3a69556a749af560e1 100644 (file)
@@ -21,7 +21,7 @@ static double overlap_in_rank_direction(SVG::SVGRect intersection,
   UNREACHABLE();
 }
 
-/// check that edges do not overlap nodes
+/// check overlap between the edge and the nodes
 static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
                                const graph_options &graph_options,
                                const check_options &check_options) {
@@ -64,6 +64,13 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
                check_options.max_node_edge_overlap +
                    check_options.svg_rounding_error * 2);
     }
+
+    // check minimum head node and edge overlap
+    if (check_options.check_min_edge_node_overlap) {
+      DO_CHECK(head_node_edge_overlap >=
+               check_options.min_node_edge_overlap -
+                   check_options.svg_rounding_error * 2);
+    }
   }
 
   // check tail node and edge overlap
@@ -82,6 +89,13 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
                check_options.max_node_edge_overlap +
                    check_options.svg_rounding_error * 2);
     }
+
+    // check minimum overlap at edge tail
+    if (check_options.check_min_edge_node_overlap) {
+      DO_CHECK(tail_node_edge_overlap >=
+               check_options.min_node_edge_overlap -
+                   check_options.svg_rounding_error * 2);
+    }
   }
 
   return success;
@@ -161,7 +175,10 @@ void test_edge_node_overlap(const graph_options &graph_options,
   const check_options check_options = {
       .check_max_edge_node_overlap =
           tc_check_options.check_max_edge_node_overlap,
+      .check_min_edge_node_overlap =
+          tc_check_options.check_min_edge_node_overlap,
       .max_node_edge_overlap = graphviz_bezier_clip_margin,
+      .min_node_edge_overlap = 0,
       .svg_rounding_error = graphviz_max_svg_rounding_error,
   };
 
index 1b09708c4032ba3a8fd298e1bb1a943af06705b7..41f8287268744fa4e6d2dbacb27ebde8f36c5a02 100644 (file)
@@ -6,13 +6,19 @@
 struct tc_check_options {
   /// whether to check that there is not too much overlap
   bool check_max_edge_node_overlap = true;
+  /// whether to check that there is enough overlap
+  bool check_min_edge_node_overlap = true;
 };
 
 struct check_options {
   /// whether to check that there is not too much overlap
   bool check_max_edge_node_overlap = true;
+  /// whether to check that there is enough overlap
+  bool check_min_edge_node_overlap = true;
   /// maximum allowed overlap between edge and node
   double max_node_edge_overlap;
+  /// minimum required overlap between edge and node
+  double min_node_edge_overlap;
   /// rounding error caused by limited precision in SVG attribute values
   double svg_rounding_error;
 };