Skip to content

Replace goto statements #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 28 additions & 13 deletions src/shading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@

#include <penumbra/penumbra.h>


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
Expand Down Expand Up @@ -148,7 +159,9 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded
}
}
if (AREAO >= WAREA) /* if fully shaded */
goto exit68; /* go exit */
{
return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
}

/*----- flap (vertical projection at end of horiz overhang) area AREAV -----*/

Expand All @@ -162,13 +175,17 @@ 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 */
{
return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
}
}

/*----- 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) */
{
return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
} /* (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
Expand All @@ -189,7 +206,9 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded
FBU = rfBotUp; /* bottom distance above windowsill */
}
if (FD <= 0.f) /* if fin depth 0 */
goto exit68; /* no fin, go exit */
{
return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
} /* no fin, go exit */

float X3 = FD * hor; /* how far over (antisunward) shadow comes */

Expand All @@ -210,7 +229,9 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded
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 */
{
return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
} /* no fin shadow */
}
else /* vert edge fin shadow intersects hor edge oh shad */
{ /* count fin shadow area in chopped-off part of window now:
Expand Down Expand Up @@ -307,13 +328,7 @@ float WSHADRAT::SunlitFract( // Calculate sunlit fraction of rectangle shaded
W = W2; /* ... those of 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;

return sunLitFnc(AREAO, AREAV, ARintF, WAREA);
} // WSHADRAT::SunlitFract

///////////////////////////////////////////////////////////////////////////////
Expand Down