From 4df55d851f3cace06c5140ccd57a7a4c02baabb3 Mon Sep 17 00:00:00 2001 From: galanca Date: Wed, 15 Jun 2022 13:42:17 -0600 Subject: [PATCH 1/4] Remove exit68 goto statement. --- src/SHADING.CPP | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/SHADING.CPP b/src/SHADING.CPP index 6d20fc94b..fc41ab1e5 100644 --- a/src/SHADING.CPP +++ b/src/SHADING.CPP @@ -148,7 +148,12 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded } } if (AREAO >= WAREA) /* if fully shaded */ - goto exit68; /* go exit */ + { + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; + } /*----- flap (vertical projection at end of horiz overhang) area AREAV -----*/ @@ -162,13 +167,23 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded { AREAV = H2 * W2; /* area shaded by flap */ if (AREAO + AREAV >= WAREA) /* if now fully shaded */ - goto exit68; /* go exit */ + { + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; + } } /*----- FINS: select sunward fin and set up -----*/ fin37: /* come here if no overhang */ if (gamma == 0.f) /* if sun straight on, no fin shadows, exit */ - goto exit68; /* (and prevent division by hor: is 0) */ + { + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; + } /* (and prevent division by hor: is 0) */ float FD; // fin depth: how far out fin projects float FU; // "fin up": fin top extension above top win @@ -189,7 +204,12 @@ fin37: /* come here if no overhang */ FBU = rfBotUp; /* bottom distance above windowsill */ } if (FD <= 0.f) /* if fin depth 0 */ - goto exit68; /* no fin, go exit */ + { + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; + } /* no fin, go exit */ float X3 = FD * hor; /* how far over (antisunward) shadow comes */ From 71b56d265873d42a96440a434ae6bdb39d146a5e Mon Sep 17 00:00:00 2001 From: galanca Date: Wed, 15 Jun 2022 14:00:38 -0600 Subject: [PATCH 2/4] Remove the exit68 jump. --- src/SHADING.CPP | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/SHADING.CPP b/src/SHADING.CPP index fc41ab1e5..c8c1a3780 100644 --- a/src/SHADING.CPP +++ b/src/SHADING.CPP @@ -328,12 +328,6 @@ fin73: /* come back here with window params changed to match flap shadow, goto fin73; } -exit68: // come here to exit - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; - } // WSHADRAT::SunlitFract /////////////////////////////////////////////////////////////////////////////// From 44a6e01f90cb9ca072a186b54ec845a9b370546e Mon Sep 17 00:00:00 2001 From: galanca Date: Wed, 15 Jun 2022 14:38:49 -0600 Subject: [PATCH 3/4] Replace the last goto exit68. --- src/SHADING.CPP | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SHADING.CPP b/src/SHADING.CPP index c8c1a3780..920df8745 100644 --- a/src/SHADING.CPP +++ b/src/SHADING.CPP @@ -230,7 +230,12 @@ fin37: /* come here if no overhang */ FU = FUO; /* chop off top of fin that shades oh shadow. FU < 0 (large E) appears ok 1-90. */ if (H + FU <= FBU) /* if top of fin now below bottom */ - goto exit68; /* no fin shadow */ + { + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; + } /* no fin shadow */ } else /* vert edge fin shadow intersects hor edge oh shad */ { /* count fin shadow area in chopped-off part of window now: From 60759e6818e9c875ed4e7da6c86ca2fd77660fd5 Mon Sep 17 00:00:00 2001 From: galanca Date: Wed, 15 Jun 2022 15:48:36 -0600 Subject: [PATCH 4/4] Replace goto exit68 for inline function. --- src/SHADING.CPP | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/SHADING.CPP b/src/SHADING.CPP index 920df8745..e0c401f0a 100644 --- a/src/SHADING.CPP +++ b/src/SHADING.CPP @@ -22,7 +22,18 @@ #include - +inline float sunLitFnc( // + float AREAO, + float AREAV, + float ARintF, + float WAREA) +// This function was created to replace the previous goto statement, 6-22 +{ + float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; + // return 0 if result so small that is probably just roundoff errors; + // in particular, return 0 for small negative results. + return fsunlit > 1.e-7f ? fsunlit : 0.f; +} float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded // with fins and/or overhang @@ -149,10 +160,7 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded } if (AREAO >= WAREA) /* if fully shaded */ { - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } /*----- flap (vertical projection at end of horiz overhang) area AREAV -----*/ @@ -168,10 +176,7 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded AREAV = H2 * W2; /* area shaded by flap */ if (AREAO + AREAV >= WAREA) /* if now fully shaded */ { - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } } @@ -179,10 +184,7 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded fin37: /* come here if no overhang */ if (gamma == 0.f) /* if sun straight on, no fin shadows, exit */ { - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } /* (and prevent division by hor: is 0) */ float FD; // fin depth: how far out fin projects @@ -205,10 +207,7 @@ fin37: /* come here if no overhang */ } if (FD <= 0.f) /* if fin depth 0 */ { - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } /* no fin, go exit */ float X3 = FD * hor; /* how far over (antisunward) shadow comes */ @@ -231,10 +230,7 @@ fin37: /* come here if no overhang */ FU < 0 (large E) appears ok 1-90. */ if (H + FU <= FBU) /* if top of fin now below bottom */ { - float fsunlit = 1.f - (AREAO + AREAV + ARintF) / WAREA; - // return 0 if result so small that is probably just roundoff errors; - // in particular, return 0 for small negative results. - return fsunlit > 1.e-7f ? fsunlit : 0.f; + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } /* no fin shadow */ } else /* vert edge fin shadow intersects hor edge oh shad */ @@ -332,7 +328,7 @@ fin73: /* come back here with window params changed to match flap shadow, W = W2; /* ... those of flap shadow */ goto fin73; } - + return sunLitFnc(AREAO, AREAV, ARintF, WAREA); } // WSHADRAT::SunlitFract ///////////////////////////////////////////////////////////////////////////////