htsky

Load and structure a vertically stratified atmosphere
git clone git://git.meso-star.fr/htsky.git
Log | Files | Refs | README | LICENSE

commit bbc29781f3007b7927f854b1a898ee8e73371a41
parent a5e432778f4d5832e04088cfca3ab262ae8d240e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 16 Apr 2020 21:42:34 +0200

Fix an issue in the world_to_cloud routine

The upper bound of the cloud was inclusive while it must not be.

Diffstat:
Msrc/htsky.c | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/htsky.c b/src/htsky.c @@ -997,6 +997,7 @@ world_to_cloud double out_pos_cs[3]) { double cloud_sz[2]; + double upper[2]; double pos_cs[3]; double pos_cs_n[2]; ASSERT(sky && pos_ws && out_pos_cs); @@ -1015,14 +1016,18 @@ world_to_cloud return d3_set(out_pos_cs, pos_ws); } - cloud_sz[0] = sky->htcp_desc.upper[0] - sky->htcp_desc.lower[0]; - cloud_sz[1] = sky->htcp_desc.upper[1] - sky->htcp_desc.lower[1]; + /* The cloud upper bound is not inclusive. Define the inclusive upper bound + * of the cloud */ + upper[0] = nextafter(sky->htcp_desc.upper[0], sky->htcp_desc.lower[0]); + upper[1] = nextafter(sky->htcp_desc.upper[1], sky->htcp_desc.lower[1]); + cloud_sz[0] = upper[0] - sky->htcp_desc.lower[0]; + cloud_sz[1] = upper[1] - sky->htcp_desc.lower[1]; /* Transform pos in normalize local cloud space */ pos_cs_n[0] = (pos_ws[0] - sky->htcp_desc.lower[0]) / cloud_sz[0]; pos_cs_n[1] = (pos_ws[1] - sky->htcp_desc.lower[1]) / cloud_sz[1]; - pos_cs_n[0] -= (int)pos_cs_n[0]; /* Keep fractional part */ - pos_cs_n[1] -= (int)pos_cs_n[1]; /* Keep fractional part */ + pos_cs_n[0] -= (int)pos_cs_n[0]; /* Get fractional part */ + pos_cs_n[1] -= (int)pos_cs_n[1]; /* Get fractional part */ if(pos_cs_n[0] < 0) pos_cs_n[0] += 1; if(pos_cs_n[1] < 0) pos_cs_n[1] += 1;