commit 44b69858c022bb9e641a553282e55fc24b716977
parent a34d6b16d15303755bf904c5bc9e27c484af75ad
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 4 Nov 2022 17:02:57 +0100
Fix rnatm_trace_ray function
The input argument check was wrong and the acceleration structure
queried was not the correct one
Diffstat:
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/rnatm_c.h b/src/rnatm_c.h
@@ -223,6 +223,9 @@ accel_struct_copy_and_release
struct band {
size_t index; /* Index of the spectral band */
size_t nquad_pts; /* Number of quadrature points in the band */
+
+ /* Offset toward the first acceleration structure of the band */
+ size_t offset_accel_struct;
};
/* Define the dynamic array of spectral bands */
diff --git a/src/rnatm_octree.c b/src/rnatm_octree.c
@@ -1364,9 +1364,10 @@ rnatm_trace_ray
{
const struct accel_struct* accel_struct = NULL;
size_t i;
+ size_t iaccel;
res_T res = RES_OK;
- if(atm || !hit) { res = RES_BAD_ARG; goto error; }
+ if(!atm || !hit) { res = RES_BAD_ARG; goto error; }
res = check_trace_ray_args(atm, args);
if(res != RES_OK) goto error;
@@ -1379,16 +1380,16 @@ rnatm_trace_ray
if(args->iquad >= darray_band_cdata_get(&atm->bands)[i].nquad_pts)
return RES_BAD_ARG;
- /* Finalize the calculation of the id of the acceleration structure */
- i += args->iquad;
+ /* Find the id of the acceleration structure */
+ iaccel = darray_band_cdata_get(&atm->bands)[i].offset_accel_struct + args->iquad;
/* Retrieve the acceleration structure */
ASSERT(i < darray_accel_struct_size_get(&atm->accel_structs));
- accel_struct = darray_accel_struct_cdata_get(&atm->accel_structs) + i;
+ accel_struct = darray_accel_struct_cdata_get(&atm->accel_structs) + iaccel;
ASSERT(args->iband == accel_struct->iband);
ASSERT(args->iquad == accel_struct->iquad_pt);
- res = make_sure_octree_is_loaded(atm, i);
+ res = make_sure_octree_is_loaded(atm, iaccel);
if(res != RES_OK) goto error;
*hit = SVX_HIT_NULL;
diff --git a/src/rnatm_properties.c b/src/rnatm_properties.c
@@ -854,6 +854,7 @@ setup_spectral_range(struct rnatm* atm, const struct rnatm_create_args* args)
{
size_t bands[2];
size_t iband, nbands;
+ size_t offset;
size_t i;
res_T res = RES_OK;
ASSERT(atm && args);
@@ -878,6 +879,7 @@ setup_spectral_range(struct rnatm* atm, const struct rnatm_create_args* args)
/* Register the bands */
i = 0;
+ offset = 0;
FOR_EACH(iband, bands[0], bands[1]+1) {
struct band* band = NULL;
struct sck_band sck_band;
@@ -887,6 +889,9 @@ setup_spectral_range(struct rnatm* atm, const struct rnatm_create_args* args)
band = darray_band_data_get(&atm->bands) + i;
band->index = iband;
band->nquad_pts = sck_band.quad_pts_count;
+ band->offset_accel_struct = offset;
+
+ offset += band->nquad_pts;
++i;
}