From 3d83a6b8923b69deb822720a1c102609fee2e805 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 15 Aug 2021 13:25:37 -0700 Subject: [PATCH] Render::PrintEdgeShape: rewrite center box calculation into something simpler --- plugin/visio/VisioRender.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/visio/VisioRender.cpp b/plugin/visio/VisioRender.cpp index e682c442c..8d26bc1c0 100644 --- a/plugin/visio/VisioRender.cpp +++ b/plugin/visio/VisioRender.cpp @@ -26,10 +26,12 @@ #include "VisioRender.h" +#include #include #include #include #include +#include #include namespace Visio @@ -403,21 +405,19 @@ namespace Visio pointf textCenter; if (!_texts.empty()) { - boxf outerTextBounds = _texts[0]->GetBounds(); + // create a box with invalid dimensions that we will refine to a tight bound + boxf outerTextBounds; + outerTextBounds.LL.x = std::numeric_limits::max(); + outerTextBounds.LL.y = std::numeric_limits::max(); + outerTextBounds.UR.x = std::numeric_limits::min(); + outerTextBounds.UR.y = std::numeric_limits::min(); - for (Texts::const_iterator nextText = _texts.begin() + 1, lastText = _texts.end(); - nextText != lastText; - ++nextText) - { - boxf innerTextBounds = (*nextText)->GetBounds(); - if (outerTextBounds.LL.x > innerTextBounds.LL.x) - outerTextBounds.LL.x = innerTextBounds.LL.x; - if (outerTextBounds.LL.y > innerTextBounds.LL.y) - outerTextBounds.LL.y = innerTextBounds.LL.y; - if (outerTextBounds.UR.x < innerTextBounds.UR.x) - outerTextBounds.UR.x = innerTextBounds.UR.x; - if (outerTextBounds.UR.y < innerTextBounds.UR.y) - outerTextBounds.UR.y = innerTextBounds.UR.y; + for (const Text *t : _texts) { + boxf innerTextBounds = t->GetBounds(); + outerTextBounds.LL.x = std::min(outerTextBounds.LL.x, innerTextBounds.LL.x); + outerTextBounds.LL.y = std::min(outerTextBounds.LL.y, innerTextBounds.LL.y); + outerTextBounds.UR.x = std::max(outerTextBounds.UR.x, innerTextBounds.UR.x); + outerTextBounds.UR.y = std::max(outerTextBounds.UR.y, innerTextBounds.UR.y); } textCenter.x = (outerTextBounds.LL.x + outerTextBounds.UR.x) / 2.0; textCenter.y = (outerTextBounds.LL.y + outerTextBounds.UR.y) / 2.0; -- 2.40.0