From: Magnus Jacobsson Date: Wed, 24 Aug 2022 07:48:19 +0000 (+0200) Subject: tests: SVGAnalyzer: add SVGRect::intersection() X-Git-Tag: 6.0.1~7^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03f74de74d772c7d7b9452667f26330cfc0ba31a;p=graphviz tests: SVGAnalyzer: add SVGRect::intersection() This will be used in an upcoming commit the determine overlap between edges and nodes. --- diff --git a/tests/svg_element.cpp b/tests/svg_element.cpp index 474e01aa5..c76428029 100644 --- a/tests/svg_element.cpp +++ b/tests/svg_element.cpp @@ -801,6 +801,19 @@ SVG::SVGPoint SVG::SVGRect::center() const { return {x + width / 2, y + height / 2}; } +SVG::SVGRect SVG::SVGRect::intersection(SVG::SVGRect other) const { + const SVG::SVGLine intersection_diagonal = { + std::max(x, other.x), std::max(y, other.y), + std::min(x + width, other.x + other.width), + std::min(y + height, other.y + other.height)}; + + return SVG::SVGRect{ + .x = intersection_diagonal.x1, + .y = intersection_diagonal.y1, + .width = intersection_diagonal.x2 - intersection_diagonal.x1, + .height = intersection_diagonal.y2 - intersection_diagonal.y1}; +} + 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 76167cef1..9113d2798 100644 --- a/tests/svg_element.h +++ b/tests/svg_element.h @@ -33,6 +33,7 @@ struct SVGRect { double width; double height; SVGPoint center() const; + SVGRect intersection(SVGRect other) const; void extend(const SVGPoint &point); void extend(const SVGRect &other); };