From ebf916edf87a19638c0cdbb8348cdf08bb2a390a Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 22 Apr 2024 20:59:27 -0600 Subject: [PATCH] Refactor ternary into early-returning conditionals Continuing precedent set in ef5ee38 --- examples/island/Island.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 3edc39ff7..8c35d631a 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -346,19 +346,23 @@ sf::Color colorFromFloats(float r, float g, float b) sf::Color getLowlandsTerrainColor(float moisture) { - sf::Color color = moisture < 0.27f ? colorFromFloats(240, 240, 180) - : moisture < 0.3f ? colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f), - 240 - (40 * (moisture - 0.27f) / 0.03f), - 180 - (180 * (moisture - 0.27f) / 0.03f)) - : moisture < 0.4f ? colorFromFloats(0, 200, 0) - : moisture < 0.48f ? colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0) - : moisture < 0.6f ? colorFromFloats(0, 160, 0) - : moisture < 0.7f ? colorFromFloats((34 * (moisture - 0.6f) / 0.1f), - 160 - (60 * (moisture - 0.6f) / 0.1f), - (34 * (moisture - 0.6f) / 0.1f)) - : colorFromFloats(34, 100, 34); - - return color; + if (moisture < 0.27f) + return colorFromFloats(240, 240, 180); + if (moisture < 0.3f) + return colorFromFloats(240 - (240 * (moisture - 0.27f) / 0.03f), + 240 - (40 * (moisture - 0.27f) / 0.03f), + 180 - (180 * (moisture - 0.27f) / 0.03f)); + if (moisture < 0.4f) + return colorFromFloats(0, 200, 0); + if (moisture < 0.48f) + return colorFromFloats(0, 200 - (40 * (moisture - 0.4f) / 0.08f), 0); + if (moisture < 0.6f) + return colorFromFloats(0, 160, 0); + if (moisture < 0.7f) + return colorFromFloats((34 * (moisture - 0.6f) / 0.1f), + 160 - (60 * (moisture - 0.6f) / 0.1f), + (34 * (moisture - 0.6f) / 0.1f)); + return colorFromFloats(34, 100, 34); }