From: Magnus Jacobsson Date: Wed, 17 Aug 2022 12:55:18 +0000 (+0200) Subject: tests: SvgAnalyzer: GraphvizNode add retrieval of center position X-Git-Tag: 6.0.1~32^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8ba97c1db057a245c6a5ad7bb784450a7c5d258;p=graphviz tests: SvgAnalyzer: GraphvizNode add retrieval of center position --- diff --git a/tests/graphviz_node.cpp b/tests/graphviz_node.cpp index a7ca9fd58..ecaa75174 100644 --- a/tests/graphviz_node.cpp +++ b/tests/graphviz_node.cpp @@ -3,6 +3,8 @@ GraphvizNode::GraphvizNode(SVG::SVGElement &svg_element) : m_node_id(svg_element.graphviz_id), m_svg_g_element(svg_element) {} +SVG::SVGPoint GraphvizNode::center() const { return bbox().center(); } + std::string_view GraphvizNode::node_id() const { return m_node_id; } SVG::SVGRect GraphvizNode::bbox() const { return m_svg_g_element.bbox(); } diff --git a/tests/graphviz_node.h b/tests/graphviz_node.h index 2bfc8e2ad..74713197b 100644 --- a/tests/graphviz_node.h +++ b/tests/graphviz_node.h @@ -17,6 +17,8 @@ public: /// Return the node's bounding box SVG::SVGRect bbox() const; + /// Return the center of the node's bounding box + SVG::SVGPoint center() const; /// Return the node's `node_id` as defined by the DOT language std::string_view node_id() const; /// Return a non-mutable reference to the SVG `g` element corresponding to the diff --git a/tests/svg_element.cpp b/tests/svg_element.cpp index ac9ea4cde..0d150c7ff 100644 --- a/tests/svg_element.cpp +++ b/tests/svg_element.cpp @@ -353,6 +353,10 @@ void SVG::SVGRect::extend(const SVGPoint &point) { height = ymax - ymin; } +SVG::SVGPoint SVG::SVGRect::center() const { + return {x + width / 2, y + height / 2}; +} + void SVG::SVGRect::extend(const SVG::SVGRect &other) { const auto xmin = std::min(x, other.x); const auto ymin = std::min(y, other.y); diff --git a/tests/svg_element.h b/tests/svg_element.h index d22b102ee..2837496dc 100644 --- a/tests/svg_element.h +++ b/tests/svg_element.h @@ -18,6 +18,7 @@ struct SVGRect { double y; double width; double height; + SVGPoint center() const; void extend(const SVGPoint &point); void extend(const SVGRect &other); };