~kennylevinsen/wlsunset

09c5e9a8dd147775d03f8a0e58d4e306c7902f67 — Kenny Levinsen 22 days ago 2e7d793
Ensure step time is at least 1 second

When configured to perform a very quick transition, the step time for 25
kelvin may end up being less than 1 second, rounding to zero. A zero
step time does not make any sense.
1 files changed, 8 insertions(+), 4 deletions(-)

M main.c
M main.c => main.c +8 -4
@@ 82,6 82,10 @@ static time_t longitude_time_offset(double longitude) {
	return longitude * 43200 / M_PI;
}

static int max(int a, int b) {
	return a > b ? a : b;
}

struct config {
	int high_temp;
	int low_temp;


@@ 241,10 245,10 @@ done:
	ctx->condition = cond;

	int temp_diff = ctx->config.high_temp - ctx->config.low_temp;
	ctx->dawn_step_time = (ctx->sun.sunrise - ctx->sun.dawn) *
		anim_kelvin_step / temp_diff;
	ctx->dusk_step_time = (ctx->sun.dusk - ctx->sun.sunset) *
		anim_kelvin_step / temp_diff;
	ctx->dawn_step_time = max(1, (ctx->sun.sunrise - ctx->sun.dawn) *
		anim_kelvin_step / temp_diff);
	ctx->dusk_step_time = max(1, (ctx->sun.dusk - ctx->sun.sunset) *
		anim_kelvin_step / temp_diff);

	print_trajectory(ctx);
}