From: Magnus Jacobsson Date: Tue, 4 Oct 2022 12:30:12 +0000 (+0200) Subject: tests: test_edge_node_overlap_utilities: factor out GraphvizEdge::arrowtail_outline_b... X-Git-Tag: 7.0.0~10^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57b3c2d5b74633eceba211218f2255405aa03882;p=graphviz tests: test_edge_node_overlap_utilities: factor out GraphvizEdge::arrowtail_outline_bbox() --- diff --git a/tests/graphviz_edge.cpp b/tests/graphviz_edge.cpp index 980fd7ddb..602b90191 100644 --- a/tests/graphviz_edge.cpp +++ b/tests/graphviz_edge.cpp @@ -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 { diff --git a/tests/graphviz_edge.h b/tests/graphviz_edge.h index a9d57156e..36a0dd327 100644 --- a/tests/graphviz_edge.h +++ b/tests/graphviz_edge.h @@ -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 diff --git a/tests/test_edge_node_overlap_utilities.cpp b/tests/test_edge_node_overlap_utilities.cpp index 97b13102e..3e5654e61 100644 --- a/tests/test_edge_node_overlap_utilities.cpp +++ b/tests/test_edge_node_overlap_utilities.cpp @@ -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));