]> granicus.if.org Git - graphviz/commitdiff
Render::PrintEdgeShape: rewrite center box calculation into something simpler
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 15 Aug 2021 20:25:37 +0000 (13:25 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Mon, 23 Aug 2021 23:59:49 +0000 (16:59 -0700)
plugin/visio/VisioRender.cpp

index e682c442c01dcd0b7bbb1e6ebb639a24eba75753..8d26bc1c00147419c91e4ec7671af25d8f66c2ca 100644 (file)
 
 #include "VisioRender.h"
 
+#include <algorithm>
 #include <common/const.h>
 #include <common/macros.h>
 #include <gvc/gvcjob.h>
 #include <gvc/gvio.h>
+#include <limits>
 #include <memory>
 
 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<double>::max();
+                               outerTextBounds.LL.y = std::numeric_limits<double>::max();
+                               outerTextBounds.UR.x = std::numeric_limits<double>::min();
+                               outerTextBounds.UR.y = std::numeric_limits<double>::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;