]> granicus.if.org Git - graphviz/commitdiff
tests: test_edge_node_overlap_utilities: factor out GraphvizEdge::arrowtail_outline_b...
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 4 Oct 2022 12:30:12 +0000 (14:30 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Fri, 14 Oct 2022 13:59:16 +0000 (15:59 +0200)
tests/graphviz_edge.cpp
tests/graphviz_edge.h
tests/test_edge_node_overlap_utilities.cpp

index 980fd7ddb7925b70fcf4254194e37a68693d3af9..602b90191731e89552d53b2aca275ecfc27b6bf1 100644 (file)
@@ -44,6 +44,21 @@ SVG::SVGRect GraphvizEdge::arrowhead_outline_bbox(
   return edge_arrowhead_bbox;
 }
 
+SVG::SVGRect GraphvizEdge::arrowtail_outline_bbox(
+    std::string_view dir, std::string_view primitive_arrow_shape) const {
+  assert((dir == "back" || dir == "both") &&
+         "no arrowhead for this edge direction");
+  if (!supported_primitive_arrow_shapes.contains(primitive_arrow_shape)) {
+    throw std::runtime_error{
+        fmt::format("primitive arrow shape {} is not yet supported",
+                    primitive_arrow_shape)};
+  }
+  auto edge_arrowtail = arrow(0);
+  const auto edge_arrowtail_bbox = edge_arrowtail.outline_bbox();
+
+  return edge_arrowtail_bbox;
+}
+
 std::string_view GraphvizEdge::edgeop() const { return m_edgeop; }
 
 std::string GraphvizEdge::fillcolor() const {
index a9d57156e4d4443220e1d2a59939add3827b0135..36a0dd3272ceef03ac4b62967987c8722003bca3 100644 (file)
@@ -38,6 +38,11 @@ public:
   SVG::SVGRect
   arrowhead_outline_bbox(std::string_view dir,
                          std::string_view primitive_arrow_shape) const;
+  /// Return the outline bounding box of the edge arrowtail. The outline
+  /// bounding box is the bounding box with penwidth taken into account.
+  SVG::SVGRect
+  arrowtail_outline_bbox(std::string_view dir,
+                         std::string_view primitive_arrow_shape) const;
   /// Return the bounding box of the edge
   SVG::SVGRect bbox() const;
   /// Return the center of the edge's bounding box
index 97b13102e6008aad78e45ddb59267a38f945c69a..3e5654e61655b9e44275c4de208b35b0c094ced6 100644 (file)
@@ -184,6 +184,8 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
   const auto dir = graph_options.dir;
   const auto primitive_arrowhead_shape =
       graph_options.primitive_arrowhead_shape;
+  const auto primitive_arrowtail_shape =
+      graph_options.primitive_arrowtail_shape;
 
   REQUIRE(svg_analyzer.graphs().size() == 1);
   auto &recreated_graph = svg_analyzer.graphs().back();
@@ -299,8 +301,8 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer,
 
   // check overlap of edge stem and arrowtail
   if (dir == "back" || dir == "both") {
-    auto edge_arrowtail = edge.arrow(0);
-    const auto edge_arrowtail_bbox = edge_arrowtail.outline_bbox();
+    const auto edge_arrowtail_bbox =
+        edge.arrowtail_outline_bbox(dir, primitive_arrowtail_shape);
     const auto overlap_bbox = edge_stem_bbox.intersection(edge_arrowtail_bbox);
     INFO("Edge stem and arrowtail overlap:");
     INFO(fmt::format("  width:  {:.3f}", overlap_bbox.width));