solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit 75e0fbd776662c4b3ce0e168f8c259a6a518e65a
parent 6bd0bb87706f1b9f1878ddbf4d9fbd567563b51a
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 24 Apr 2017 14:11:27 +0200

Fix & update the spectrum_interpolate function

If the submitted wavelength is not included in the spectrum range, the
returned value is the nearest spectrum bound.

Diffstat:
Msrc/ssol_spectrum.c | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/ssol_spectrum.c b/src/ssol_spectrum.c @@ -92,15 +92,21 @@ spectrum_interpolate double slope; double intensity; size_t id_next, sz; - ASSERT(spectrum && spectrum_includes_point(spectrum, wavelength)); + ASSERT(spectrum); sz = darray_double_size_get(&spectrum->wavelengths); wls = darray_double_cdata_get(&spectrum->wavelengths); ints = darray_double_cdata_get(&spectrum->intensities); next = search_lower_bound(&wavelength, wls, sz, sizeof(double), &eq_dbl); - ASSERT(next); /* because spectrum_includes_point */ + if(!next) { /* Clamp to upper bound */ + return ints[sz-1]; + } id_next = (size_t)(next - wls); + if(!id_next) { /* Clamp to lower bound */ + return ints[0]; + } + ASSERT(id_next); /* because spectrum_includes_point */ ASSERT(ints[id_next] >= ints[id_next - 1]); ASSERT(wls[id_next] >= wls[id_next - 1]);