Sun: set progress with custom time (#689)

This commit is contained in:
Gustl22 2019-03-05 14:23:18 +01:00 committed by Emux
parent 9809398517
commit 311cc19134
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3

View File

@ -151,7 +151,7 @@ public class Sun {
}
/**
* Customize day of the year
* Customize day of the year.
*/
public void setDayOfYear(int day) {
mDayOfYear = day;
@ -171,6 +171,28 @@ public class Sun {
mProgress = progress;
}
/**
* Customize progress with specified time.
*
* @param hour the hour [0..23]
* @param minute the minute [0..59]
* @param second the second [0..59]
* @return the progress in range 0 to 2
*/
public float setProgress(int hour, int minute, int second) {
float time = hour;
time += minute / 60f;
time += second / 3600f;
float progress = (time - mSunrise) / (mSunset - mSunrise);
if (progress > 1f || progress < 0f) {
progress = ((time + 24 - mSunset) % 24) / (mSunrise + 24 - mSunset);
progress += 1;
}
mProgress = MathUtils.clamp(progress, 0f, 2f);
return mProgress;
}
/**
* @param h the offset of horizon (in radians) e.g. bend of earth / atmosphere etc.
* @return the difference of sunrise or sunset to noon
@ -238,23 +260,7 @@ public class Sun {
* @return the progress in range 0 to 2
*/
public float updateProgress() {
// TODO Java8 replace with LocalDateTime
// LocalDateTime date = new LocalDateTime();
// float time = date.getHour();
// time += date.getMinute() / 60f;
// time += date.getSecond() / 3600f;
float time = date.getHour();
time += date.getMinute() / 60f;
time += date.getSecond() / 3600f;
float progress = (time - mSunrise) / (mSunset - mSunrise);
if (progress > 1f || progress < 0f) {
progress = ((time + 24 - mSunset) % 24) / (mSunrise + 24 - mSunset);
progress += 1;
}
mProgress = MathUtils.clamp(progress, 0f, 2f);
return mProgress;
return setProgress(date.getHour(), date.getMinute(), date.getSecond());
}
/**