From 5c498e8af3fa35e8d484a06f2f4c517c97cb1106 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Wed, 3 May 2017 15:53:23 -0400
Subject: [PATCH] improve logic for determining the smallest dimensions of a
 GOP with xlets

---
 pd/src/g_graph.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/pd/src/g_graph.c b/pd/src/g_graph.c
index cd6e0e09d..fc8b2354e 100644
--- a/pd/src/g_graph.c
+++ b/pd/src/g_graph.c
@@ -1214,14 +1214,16 @@ void graph_checkgop_rect(t_gobj *z, t_glist *glist,
 
     // failsafe where we cannot have a gop that is smaller than 1x1 pixels
     // regardless whether the text is hidden
-    int in = obj_ninlets(pd_checkobject(&z->g_pd)) * IOWIDTH;
-    int out = obj_noutlets(pd_checkobject(&z->g_pd)) * IOWIDTH;
-    int minhsize = (in >= out ? in : out) + SCALE_GOP_MINWIDTH;
-    int minvsize = ((in > 0 ? 1 : 0) + (out > 0 ? 1 : 0)) * 2 +
-        SCALE_GOP_MINHEIGHT;
+    int in = obj_ninlets(pd_checkobject(&z->g_pd));
+    int out = obj_noutlets(pd_checkobject(&z->g_pd));
+    int max_xlets = in >= out ? in : out;
+    int minhsize = (max_xlets * IOWIDTH) +
+        ((max_xlets > 1 ? max_xlets - 1 : 0) * IOWIDTH);
+    if (minhsize < SCALE_GOP_MINWIDTH) minhsize = SCALE_GOP_MINWIDTH;
+    int minvsize = ((in > 0 ? 1 : 0) + (out > 0 ? 1 : 0)) * 2;
+    if (minvsize < SCALE_GOP_MINHEIGHT) minvsize = SCALE_GOP_MINHEIGHT;
     if (*xp2 < *xp1+minhsize) *xp2 = *xp1+minhsize;
     if (*yp2 < *yp1+minvsize) *yp2 = *yp1+minvsize;
-    
 }
 
     /* get the rectangle, enlarged to contain all the "contents" --
-- 
GitLab