From: Magnus Jacobsson Date: Wed, 14 Sep 2022 07:28:10 +0000 (+0200) Subject: tests: test_edge_node_overlap_utilities: support all rank directions X-Git-Tag: 6.0.2~34^2~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bf8c899eac5aff2e81ae484fcebb1fc9157ee53a;p=graphviz tests: test_edge_node_overlap_utilities: support all rank directions --- diff --git a/tests/test_edge_node_overlap_utilities.cpp b/tests/test_edge_node_overlap_utilities.cpp index 3597ea72a..b40319575 100644 --- a/tests/test_edge_node_overlap_utilities.cpp +++ b/tests/test_edge_node_overlap_utilities.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -8,6 +7,19 @@ #include "svg_analyzer.h" #include "test_edge_node_overlap_utilities.h" #include "test_utilities.h" +#include + +/// return the overlap in the rank direction from an intersection rectangle +static double overlap_in_rank_direction(SVG::SVGRect intersection, + const std::string_view rankdir) { + if (rankdir == "LR" || rankdir == "RL") { + return intersection.width; + } + if (rankdir == "TB" || rankdir == "BT") { + return intersection.height; + } + UNREACHABLE(); +} /// check that edges do not overlap nodes static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer, @@ -43,11 +55,8 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer, INFO("Head node overlap:"); INFO(fmt::format(" width: {:.3f}", overlap_bbox.width)); INFO(fmt::format(" height: {:.3f}", overlap_bbox.height)); - // FIXME: add support for rank direction "LR" and "RL". For now assume - // "TB" or "BT" and check only in the vertical direction - assert((rankdir == "TB" || rankdir == "BT") && - "Only rankdir=TB or rankdir=BT is supported"); - const auto head_node_edge_overlap = overlap_bbox.height; + const auto head_node_edge_overlap = + overlap_in_rank_direction(overlap_bbox, rankdir); // check maximum head node and edge overlap DO_CHECK(head_node_edge_overlap <= @@ -62,11 +71,8 @@ static bool check_analyzed_svg(SVGAnalyzer &svg_analyzer, INFO("Tail node overlap:"); INFO(fmt::format(" width: {:.6f}", overlap_bbox.width)); INFO(fmt::format(" height: {:.6f}", overlap_bbox.height)); - // FIXME: add support for rank direction "LR" and "RL". For now assume - // "TB" or "BT" and check only in the vertical direction - assert((rankdir == "TB" || rankdir == "BT") && - "Only rankdir=TB or rankdir=BT is supported"); - const auto tail_node_edge_overlap = overlap_bbox.height; + const auto tail_node_edge_overlap = + overlap_in_rank_direction(overlap_bbox, rankdir); // check maximum tail node and edge overlap DO_CHECK(tail_node_edge_overlap <=