@@ -1254,6 +1254,9 @@ Int_t TPad::DistancetoPrimitive(Int_t px, Int_t py)
12541254// / __Note3:__ in case xmargin < 0 or ymargin < 0, there is no space
12551255// / between pads. The current pad margins are recomputed to
12561256// / optimize the layout.
1257+ // /
1258+ // / __Note4:__ in case nx < 0 or ny < 0, there is no outer x or y margin, but
1259+ // / the inner margins are equal to xmargin and ymargin, respectively.
12571260
12581261void TPad::Divide (Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t color)
12591262{
@@ -1269,30 +1272,44 @@ void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t co
12691272 TContext ctxt (kTRUE );
12701273
12711274 cd ();
1272- if (nx <= 0 ) nx = 1 ;
1273- if (ny <= 0 ) ny = 1 ;
1274- Int_t ix, iy;
1275- Double_t x1, y1, x2, y2, dx, dy;
1276- TPad *pad;
1275+ if (nx == 0 )
1276+ nx = 1 ;
1277+ if (ny == 0 )
1278+ ny = 1 ;
1279+
1280+ // Outer margins, equal to half of the inner margin. Set to zero if nx or ny are negative.
1281+ Float_t xmargin_outer = xmargin;
1282+ Float_t ymargin_outer = ymargin;
1283+
1284+ if (nx < 0 ) {
1285+ xmargin_outer = 0.0 ;
1286+ nx = -nx;
1287+ }
1288+
1289+ if (ny < 0 ) {
1290+ ymargin_outer = 0.0 ;
1291+ ny = -ny;
1292+ }
1293+
12771294 TString name, title;
12781295 Int_t n = 0 ;
12791296 if (color == 0 ) color = GetFillColor ();
12801297 if (xmargin >= 0 && ymargin >= 0 ) {
12811298 // general case
1282- dy = 1 / Double_t (ny);
1283- dx = 1 / Double_t (nx);
1284- for (iy= 0 ;iy< ny;iy++) {
1285- y2 = 1 - iy* dy - ymargin;
1286- y1 = y2 - dy + 2 *ymargin ;
1299+ auto dx = ( 1 - 2 * xmargin * (nx - 1 ) - 2 * xmargin_outer) / nx; // width of a subpad
1300+ auto dy = ( 1 - 2 * ymargin * (ny - 1 ) - 2 * ymargin_outer) / ny; // height of a subpad
1301+ for (auto iy = 0 ; iy < ny; iy++) {
1302+ auto y2 = 1 - iy * dy - 2 * ymargin * iy - ymargin_outer ;
1303+ auto y1 = y2 - dy;
12871304 if (y1 < 0 ) y1 = 0 ;
12881305 if (y1 > y2) continue ;
1289- for (ix= 0 ;ix< nx;ix++) {
1290- x1 = ix* dx + xmargin;
1291- x2 = x1 +dx - 2 *xmargin ;
1306+ for (auto ix = 0 ; ix < nx; ix++) {
1307+ auto x1 = ix * dx + 2 * xmargin * ix + xmargin_outer ;
1308+ auto x2 = x1 + dx ;
12921309 if (x1 > x2) continue ;
12931310 n++;
12941311 name.Form (" %s_%d" , GetName (), n);
1295- pad = new TPad (name.Data (), name.Data (), x1, y1, x2, y2, color);
1312+ auto pad = new TPad (name.Data (), name.Data (), x1, y1, x2, y2, color);
12961313 pad->SetNumber (n);
12971314 pad->Draw ();
12981315 }
@@ -1311,23 +1328,23 @@ void TPad::Divide(Int_t nx, Int_t ny, Float_t xmargin, Float_t ymargin, Int_t co
13111328 SetRightMargin (xr);
13121329 SetBottomMargin (yb);
13131330 SetTopMargin (yt);
1314- dx = (1 -xl- xr)/ nx;
1315- dy = (1 -yb- yt)/ ny;
1331+ auto dx = (1 - xl - xr) / nx;
1332+ auto dy = (1 - yb - yt) / ny;
13161333 Int_t number = 0 ;
13171334 for (Int_t i=0 ;i<nx;i++) {
1318- x1 = i*dx+ xl;
1319- x2 = x1 + dx;
1335+ auto x1 = i * dx + xl;
1336+ auto x2 = x1 + dx;
13201337 if (i == 0 ) x1 = 0 ;
13211338 if (i == nx-1 ) x2 = 1 -xr;
13221339 for (Int_t j=0 ;j<ny;j++) {
13231340 number = j*nx + i +1 ;
1324- y2 = 1 -j* dy -yt;
1325- y1 = y2 - dy;
1341+ auto y2 = 1 - j * dy - yt;
1342+ auto y1 = y2 - dy;
13261343 if (j == 0 ) y2 = 1 -yt;
13271344 if (j == ny-1 ) y1 = 0 ;
13281345 name.Form (" %s_%d" , GetName (), number);
13291346 title.Form (" %s_%d" , GetTitle (), number);
1330- pad = new TPad (name.Data (), title.Data (), x1, y1, x2, y2, color);
1347+ auto pad = new TPad (name.Data (), title.Data (), x1, y1, x2, y2, color);
13311348 pad->SetNumber (number);
13321349 pad->SetBorderMode (0 );
13331350 if (i == 0 ) pad->SetLeftMargin (xl*nx);
0 commit comments