Cycles: Fix recently introduced off-by-one error in an assert

This was added in rB95696d09bc07, but I got the index wrong.
This commit is contained in:
Lukas Stockner 2023-01-10 02:07:00 +01:00
parent 7bf75231e8
commit 317a5f61f0
1 changed files with 6 additions and 4 deletions

View File

@ -16,7 +16,9 @@ void util_cdf_invert(const int resolution,
const bool make_symmetric,
vector<float> &inv_cdf)
{
assert(cdf[0] == 0.0f && cdf[resolution] == 1.0f);
const int cdf_size = cdf.size();
assert(cdf[0] == 0.0f && cdf[cdf_size - 1] == 1.0f);
const float inv_resolution = 1.0f / (float)resolution;
const float range = to - from;
inv_cdf.resize(resolution);
@ -26,12 +28,12 @@ void util_cdf_invert(const int resolution,
float x = i / (float)half_size;
int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin();
float t;
if (index < cdf.size() - 1) {
if (index < cdf_size - 1) {
t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
}
else {
t = 0.0f;
index = cdf.size() - 1;
index = cdf_size - 1;
}
float y = ((index + t) / (resolution - 1)) * (2.0f * range);
inv_cdf[half_size + i] = 0.5f * (1.0f + y);
@ -43,7 +45,7 @@ void util_cdf_invert(const int resolution,
float x = (i + 0.5f) * inv_resolution;
int index = upper_bound(cdf.begin(), cdf.end(), x) - cdf.begin() - 1;
float t;
if (index < cdf.size() - 1) {
if (index < cdf_size - 1) {
t = (x - cdf[index]) / (cdf[index + 1] - cdf[index]);
}
else {