Commit a9a5005c authored by Brice Videau's avatar Brice Videau
Browse files

Conform roulette distribution API.

parent 41da517e
......@@ -121,7 +121,8 @@ ccs_roulette_distribution_get_num_areas(ccs_distribution_t distribution,
extern ccs_error_t
ccs_roulette_distribution_get_areas(ccs_distribution_t distribution,
size_t num_areas,
ccs_float_t *areas);
ccs_float_t *areas,
size_t *num_areas_ret);
// Sampling Interface
extern ccs_error_t
......
......@@ -144,18 +144,24 @@ ccs_roulette_distribution_get_num_areas(ccs_distribution_t distribution,
ccs_error_t
ccs_roulette_distribution_get_areas(ccs_distribution_t distribution,
size_t num_areas,
ccs_float_t *areas) {
ccs_float_t *areas,
size_t *num_areas_ret) {
if (!distribution || distribution->obj.type != CCS_DISTRIBUTION)
return -CCS_INVALID_OBJECT;
if (!distribution->data || ((_ccs_distribution_common_data_t*)distribution->data)->type != CCS_ROULETTE)
return -CCS_INVALID_OBJECT;
if (!areas)
if (!areas && !num_areas_ret)
return -CCS_INVALID_VALUE;
_ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data;
if ((ccs_int_t)num_areas != data->num_areas)
if (num_areas && !areas)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < num_areas; i++)
areas[i] = data->areas[i+1] - data->areas[i];
_ccs_distribution_roulette_data_t * data = (_ccs_distribution_roulette_data_t *)distribution->data;
if (areas) {
if ((ccs_int_t)num_areas != data->num_areas)
return -CCS_INVALID_VALUE;
for (size_t i = 0; i < num_areas; i++)
areas[i] = data->areas[i+1] - data->areas[i];
}
if (num_areas_ret)
*num_areas_ret = data->num_areas;
return CCS_SUCCESS;
}
......@@ -64,8 +64,10 @@ void test_create_roulette_distribution() {
assert( err == CCS_SUCCESS );
assert( num_areas_ret == num_areas );
err = ccs_roulette_distribution_get_areas(distrib, num_areas_ret, areas_ret);
err = ccs_roulette_distribution_get_areas(distrib, num_areas, areas_ret, &num_areas_ret);
assert( err == CCS_SUCCESS );
assert( num_areas_ret == num_areas );
ccs_float_t inv_sum = 2.0 / (num_areas * (num_areas + 1));
for (size_t i = 0; i < num_areas; i++) {
assert( areas_ret[i] <= areas[i] * inv_sum + epsilon &&
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment