]> granicus.if.org Git - graphviz/commitdiff
smyrna: simplify bounding box calculation in 'set_boundaries'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 5 May 2022 15:32:35 +0000 (08:32 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 11 May 2022 03:14:22 +0000 (20:14 -0700)
cmd/smyrna/topviewfuncs.c

index e1b87bc442f060332900960da37f0ffd4629a9b0..15cd6e490e1a16a009374d1896bd224fecb0e27d 100644 (file)
@@ -23,6 +23,7 @@
 #include <common/utils.h>
 #include <ctype.h>
 #include <float.h>
+#include <math.h>
 
 static xdot *parseXdotwithattrs(void *e)
 {
@@ -54,27 +55,15 @@ static void set_boundaries(Agraph_t * g)
     Agsym_t* pos_attr = GN_pos(g);
     glCompPoint pos;
     float left = FLT_MAX, right = -FLT_MAX, top = FLT_MAX, bottom = -FLT_MAX;
-    int id=0;
 
     for (v = agfstnode(g); v; v = agnxtnode(g, v)) 
     {
        pos=getPointFromStr(agxget(v, pos_attr));
-       if(id==0)
-       {
-           left=pos.x;
-           right=pos.x;
-           top=pos.y;
-           bottom=pos.y;
-       }
-       if (left > pos.x)
-           left = pos.x;
-       if (right < pos.x)
-           right = pos.x;
-       if (bottom > pos.y)
-           bottom = pos.y;
-       if (top < pos.y)
-           top = pos.y;
-       id++;
+
+       left = fminf(left, pos.x);
+       right = fmaxf(right, pos.x);
+       top = fmaxf(top, pos.y);
+       bottom = fminf(bottom, pos.y);
     }
     view->bdxLeft = left;
     view->bdyTop = top;