From b9a51bb2be87c7f5d64ee9223cd4c2018f395d0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 30 Dec 2015 19:29:15 +0100 Subject: [PATCH] Fixed precision problem in daytime management --- src/definition/AtmosphereDefinition.cpp | 2 +- src/tests/AtmosphereDefinition_Test.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/definition/AtmosphereDefinition.cpp b/src/definition/AtmosphereDefinition.cpp index 265f632..ac0e5da 100644 --- a/src/definition/AtmosphereDefinition.cpp +++ b/src/definition/AtmosphereDefinition.cpp @@ -74,7 +74,7 @@ void AtmosphereDefinition::setDayTime(double value) { } void AtmosphereDefinition::setDayTime(int hour, int minute, int second) { - setDayTime(to_double(hour) / 24.0 + to_double(minute) / 1440.0 + to_double(second) / 86400.0); + setDayTime(to_double(hour) / 24.0 + to_double(minute) / 1440.0 + (to_double(second) + 0.1) / 86400.0); } double AtmosphereDefinition::getDaytime() const { diff --git a/src/tests/AtmosphereDefinition_Test.cpp b/src/tests/AtmosphereDefinition_Test.cpp index 5d57f4e..182f3e4 100644 --- a/src/tests/AtmosphereDefinition_Test.cpp +++ b/src/tests/AtmosphereDefinition_Test.cpp @@ -11,6 +11,11 @@ static void check_daytime(const AtmosphereDefinition &atmo, int expected_hour, i EXPECT_EQ(expected_second, second); } +static void check_auto_daytime(AtmosphereDefinition &atmo, int hour, int minute=0, int second=0) { + atmo.setDayTime(hour, minute, second); + check_daytime(atmo, hour, minute, second); +} + TEST(AtmosphereDefinition, setDayTime) { AtmosphereDefinition atmo(NULL); @@ -34,4 +39,8 @@ TEST(AtmosphereDefinition, setDayTime) { atmo.setDayTime(1.5); check_daytime(atmo, 12); + + check_auto_daytime(atmo, 15); + check_auto_daytime(atmo, 15, 12); + check_auto_daytime(atmo, 15, 18, 7); }