]> granicus.if.org Git - graphviz/commitdiff
tests: GraphvizEdge: handle primitive arrow shape 'dot' in arrowhead_outline_bbox
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 5 Oct 2022 20:28:14 +0000 (22:28 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 18 Oct 2022 18:58:25 +0000 (20:58 +0200)
tests/graphviz_edge.cpp

index 35c75015fa6aaad307bbf684af6c4c55490d1aee..72754195eeac69e9b54a50bc5d57af9543e6043c 100644 (file)
@@ -21,10 +21,35 @@ void GraphvizEdge::add_outline_overlap_bbox(const GraphvizNode &node,
 static const std::unordered_set<std::string_view>
     supported_primitive_arrow_shapes = {
         "box",    //
+        "dot",    //
         "inv",    //
         "normal", //
 };
 
+static const std::unordered_set<std::string_view>
+    polygon_based_primitive_arrow_shapes = {
+        "box",    //
+        "inv",    //
+        "normal", //
+};
+
+static const std::unordered_set<std::string_view>
+    ellipse_based_primitive_arrow_shapes = {
+        "dot", //
+};
+
+static SVG::SVGElementType
+edge_arrowhead_main_svg_element_type(std::string_view primitive_arrow_shape) {
+  if (polygon_based_primitive_arrow_shapes.contains(primitive_arrow_shape)) {
+    return SVG::SVGElementType::Polygon;
+  } else if (ellipse_based_primitive_arrow_shapes.contains(
+                 primitive_arrow_shape)) {
+    return SVG::SVGElementType::Ellipse;
+  } else {
+    assert(false && "unsupported primitive arrow shape");
+  }
+}
+
 SVG::SVGRect GraphvizEdge::arrowhead_outline_bbox(
     std::string_view dir, std::string_view primitive_arrow_shape) const {
   assert((dir == "forward" || dir == "both") &&
@@ -36,8 +61,11 @@ SVG::SVGRect GraphvizEdge::arrowhead_outline_bbox(
                     primitive_arrow_shape)};
   }
   const auto index = dir == "forward" ? 0 : 1;
+
+  const auto main_svg_element_type =
+      edge_arrowhead_main_svg_element_type(primitive_arrow_shape);
   auto edge_arrowhead =
-      m_svg_g_element.find_child(SVG::SVGElementType::Polygon, index);
+      m_svg_g_element.find_child(main_svg_element_type, index);
   auto edge_arrowhead_bbox = edge_arrowhead.outline_bbox();
   if (primitive_arrow_shape == "box") {
     auto edge_arrowhead_stem =