commit 846a0d33a411a68eb0c307cf71a11c688deec9dd
parent 301641649c45fec0b83a600b6e35a4efba4bbdf8
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Thu, 13 Feb 2020 16:10:00 +0100
Change API to count with size_t instead of unsigned
Diffstat:
18 files changed, 256 insertions(+), 275 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -29,7 +29,8 @@ cmake_dependent_option(SMALL_ADDITIONAL_TESTS
"NOT NO_TEST" OFF)
cmake_dependent_option(HUGE_ADDITIONAL_TESTS
- "Build additional tests originally written for star-enclosures that involve millions of segments" OFF
+ "Build additional tests originally written for star-enclosures that involve \
+millions of segments" OFF
"NOT NO_TEST" OFF)
################################################################################
@@ -98,6 +99,7 @@ add_library(sg2d SHARED
target_link_libraries(sg2d RSys ${MATH_LIB})
set_target_properties(sg2d PROPERTIES
+ C_STANDARD 99
DEFINE_SYMBOL SG2D_SHARED_BUILD
VERSION ${VERSION}
SOVERSION ${VERSION_MAJOR})
diff --git a/src/sg2d.h b/src/sg2d.h
@@ -94,7 +94,7 @@ enum sg2d_c_dump_qualifiers {
* SG2D_UNSPECIFIED_PROPERTY can be used for a property that has already been
* defined; in this case the previous value will remain.
*****************************************************************************/
-#define SG2D_UNSPECIFIED_PROPERTY UINT_MAX
+#define SG2D_UNSPECIFIED_PROPERTY SIZE_MAX
/*****************************************************************************
* A type to hold callbacks for sg2d_geometry_add.
@@ -102,24 +102,24 @@ enum sg2d_c_dump_qualifiers {
struct sg2d_geometry_add_callbacks {
/* User function that provides vertices ids for added segments */
void(*get_indices)
- (const unsigned iseg, unsigned ids[SG2D_GEOMETRY_DIMENSION], void* context);
+ (const size_t iseg, size_t ids[SG2D_GEOMETRY_DIMENSION], void* context);
/* User function that provides properties for added segments */
void(*get_properties) /* Can be NULL <=> SG2D_UNSPECIFIED_PROPERTY used */
- (const unsigned iseg,
+ (const size_t iseg,
/* It is OK to have side and interface properties sharing the same IDs,
* i.e. side and interface IDs both starting from 0 */
- unsigned properties[SG2D_PROP_TYPES_COUNT__],
+ size_t properties[SG2D_PROP_TYPES_COUNT__],
void* context);
/* User function that provides coordinates for added vertices */
void(*get_position)
- (const unsigned ivert, double pos[SG2D_GEOMETRY_DIMENSION], void* context);
+ (const size_t ivert, double pos[SG2D_GEOMETRY_DIMENSION], void* context);
/* Called if the iseg_th segment of the current sg2d_geometry_add is a new
* segment (i.e. not a duplicate) so that the client app can manage its own
* segment data/properties/attributes.
* If return is not RES_OK, sg2d_geometry_add stops immediately and returns
* whatever value add_segment returned. */
res_T(*add_segment) /* Can be NULL */
- (const unsigned unique_id, const unsigned iseg, void* context);
+ (const size_t unique_id, const size_t iseg, void* context);
/* Called if the iseg_th segment of the current sg2d_geometry_add is a
* duplicate of the unique_id_th unique segment so that the client app can
* merge its own segment data, rule merge validity, and possibly change the
@@ -132,18 +132,18 @@ struct sg2d_geometry_add_callbacks {
* The segment_properties and merged_properties args contain the involved
* properties. */
res_T(*merge_segment) /* Can be NULL */
- (const unsigned unique_id,
- const unsigned iseg,
+ (const size_t unique_id,
+ const size_t iseg,
const int reversed_segment,
- unsigned segment_properties[SG2D_PROP_TYPES_COUNT__],
- const unsigned merged_properties[SG2D_PROP_TYPES_COUNT__],
+ size_t segment_properties[SG2D_PROP_TYPES_COUNT__],
+ const size_t merged_properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* merge_conflict_status);
/* Called if the iseg_th segment is degenerated. According to the value
* of abort, sg2d_geometry_add will stop and return RES_BAD_ARG or continue
* silently. */
res_T(*degenerated_segment) /* Can be NULL <=> Drop segment, don't abort */
- (const unsigned iseg, void* context, int* abort);
+ (const size_t iseg, void* context, int* abort);
};
#define SG2D_ADD_CALLBACKS_NULL__ { NULL, NULL, NULL, NULL, NULL, NULL }
@@ -154,8 +154,8 @@ BEGIN_DECLS
*****************************************************************************/
static INLINE int
sg2d_compatible_property
- (const unsigned p1,
- const unsigned p2)
+ (const size_t p1,
+ const size_t p2)
{
if(p1 == SG2D_UNSPECIFIED_PROPERTY || p2 == SG2D_UNSPECIFIED_PROPERTY) return 1;
return (p1 == p2);
@@ -197,9 +197,9 @@ sg2d_geometry_create
SG2D_API res_T
sg2d_geometry_reserve
(struct sg2d_geometry* geometry,
- const unsigned vertices_count,
- const unsigned segments_count,
- const unsigned properties_count);
+ const size_t vertices_count,
+ const size_t segments_count,
+ const size_t properties_count);
/* Add a new set of 2D vertices and segments to the geometry; segments can
* be decorated with 3 properties (front and back media and interface) that can
@@ -232,8 +232,8 @@ sg2d_geometry_reserve
SG2D_API res_T
sg2d_geometry_add
(struct sg2d_geometry* geometry,
- const unsigned vertices_count,
- const unsigned segments_count,
+ const size_t vertices_count,
+ const size_t segments_count,
const struct sg2d_geometry_add_callbacks* callbacks,
void* context); /* Can be NULL */
@@ -250,8 +250,8 @@ SG2D_API res_T
sg2d_geometry_validate_properties
(struct sg2d_geometry* geometry,
res_T(*validate)
- (const unsigned iseg,
- const unsigned properties[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ const size_t properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict_status),
void* context); /* Can be NULL */
@@ -260,40 +260,40 @@ sg2d_geometry_validate_properties
SG2D_API res_T
sg2d_geometry_get_unique_vertices_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the ivtx_th vertex. */
SG2D_API res_T
sg2d_geometry_get_unique_vertex
(const struct sg2d_geometry* geometry,
- const unsigned ivtx,
+ const size_t ivtx,
double coord[SG2D_GEOMETRY_DIMENSION]);
/* Get the number of segments added to the geometry, regardless of unicity. */
SG2D_API res_T
sg2d_geometry_get_added_segments_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the number of unique segments. */
SG2D_API res_T
sg2d_geometry_get_unique_segments_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the vertex indices of the iseg_th unique segment. */
SG2D_API res_T
sg2d_geometry_get_unique_segment_vertices
(const struct sg2d_geometry* geometry,
- const unsigned iseg,
- unsigned indices[SG2D_GEOMETRY_DIMENSION]);
+ const size_t iseg,
+ size_t indices[SG2D_GEOMETRY_DIMENSION]);
/* Get the properties of the iseg_th unique segment. */
SG2D_API res_T
sg2d_geometry_get_unique_segment_properties
(const struct sg2d_geometry* geometry,
- const unsigned iseg,
- unsigned properties[SG2D_PROP_TYPES_COUNT__]);
+ const size_t iseg,
+ size_t properties[SG2D_PROP_TYPES_COUNT__]);
/* Get the user ID of the iseg_th unique segment, that is the user world's
* index of the segment that first created this unique segment.
@@ -303,33 +303,33 @@ sg2d_geometry_get_unique_segment_properties
SG2D_API res_T
sg2d_geometry_get_unique_segment_user_id
(const struct sg2d_geometry* geometry,
- const unsigned iseg,
- unsigned* user_id);
+ const size_t iseg,
+ size_t* user_id);
/* Get the number of segments with (at least) one unspecified side. */
SG2D_API res_T
sg2d_geometry_get_unique_segments_with_unspecified_side_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the number of segments with unspecified interface. */
SG2D_API res_T
sg2d_geometry_get_unique_segments_with_unspecified_interface_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the number of segments flagged with a merge conflict. */
SG2D_API res_T
sg2d_geometry_get_unique_segments_with_merge_conflict_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Get the number of segments flagged with a property conflict. Only meaningful
* after sg2d_geometry_validate_properties has been called. */
SG2D_API res_T
sg2d_geometry_get_unique_segments_with_properties_conflict_count
(const struct sg2d_geometry* geometry,
- unsigned* count);
+ size_t* count);
/* Dump a geometry in the provided stream in the OBJ format.
* The geometry can include conflicts, but cannot be empty. Note that vertices
@@ -369,11 +369,11 @@ sg2d_geometry_dump_as_vtk
/* Dump the geometry as C code.
* The geometry cannot be empty and must be conflict-free.
* The C code defines the 5 variables:
- * - [static] [const] unsigned <name_prefix>_vertices_count = N1;
+ * - [static] [const] size_t <name_prefix>_vertices_count = N1;
* - [static] [const] double <name_prefix>_vertices[<N1>] = { .... };
- * - [static] [const] unsigned <name_prefix>_segments_count = N2;
- * - [static] [const] unsigned <name_prefix>_segments[<N2>] = { .... };
- * - [static] [const] unsigned <name_prefix>_properties[<N3>] = { .... };
+ * - [static] [const] size_t <name_prefix>_segments_count = N2;
+ * - [static] [const] size_t <name_prefix>_segments[<N2>] = { .... };
+ * - [static] [const] size_t <name_prefix>_properties[<N3>] = { .... };
* Where <N1> is 2 * vertices_count, <N2> is 2 * segments_count and <N3> is
* 3 * segments_count.
* The two qualifiers static and const are output or not according to flags;
diff --git a/src/sg2d_geometry.c b/src/sg2d_geometry.c
@@ -42,7 +42,7 @@ geometry_release(ref_T* ref)
}
static FINLINE int /* Return 1 if reversed */
-seg_make_key(struct unsigned2* k, const unsigned t[2])
+seg_make_key(struct size2* k, const size_t t[2])
{
ASSERT(t);
ASSERT(t[0] != t[1]);
@@ -70,7 +70,7 @@ dump_seg_property
descriptions
= darray_seg_descriptions_cdata_get(&geom->seg_descriptions);
FOR_EACH(i, 0, darray_segment_size_get(&geom->unique_segments)) {
- unsigned property = SG2D_UNSPECIFIED_PROPERTY;
+ size_t property = SG2D_UNSPECIFIED_PROPERTY;
size_t tdefs_count
= darray_definition_size_get(&descriptions[i].defs[type]);
if(tdefs_count && descriptions[i].property_defined[type]) {
@@ -86,7 +86,7 @@ dump_seg_property
}
}
/* In VTK dumps INT_MAX is used for both unspecified and conflict */
- fprintf(stream, "%u\n", MMIN(property, INT_MAX));
+ fprintf(stream, "%u\n", (int)MMIN(property, INT_MAX));
}
}
@@ -97,8 +97,8 @@ res_T
geometry_register_segment
(struct sg2d_geometry* geom,
const struct segment* segment,
- const unsigned segment_unique_id,
- const unsigned set_id,
+ const size_t segment_unique_id,
+ const size_t set_id,
const int merge_conflict)
{
res_T res = RES_OK;
@@ -126,10 +126,10 @@ geometry_register_segment
FOR_EACH(j, 0, darray_definition_size_get(definitions)) {
if(defs[j].property_value == segment->properties[i]) {
/* This property_value is already registered: no conflict */
- const unsigned* ids = darray_uint_cdata_get(&defs[j].set_ids);
+ const size_t* ids = darray_size_t_cdata_get(&defs[j].set_ids);
size_t k;
/* Search if property_value already includes set_id */
- FOR_EACH(k, 0, darray_uint_size_get(&defs[j].set_ids)) {
+ FOR_EACH(k, 0, darray_size_t_size_get(&defs[j].set_ids)) {
if(ids[k] == set_id) {
/* Same value+set_id was there already */
done = 1;
@@ -138,7 +138,7 @@ geometry_register_segment
}
if(!done) {
/* Need to add the set_id for this property_value */
- ERR(darray_uint_push_back(&defs[j].set_ids, &set_id));
+ ERR(darray_size_t_push_back(&defs[j].set_ids, &set_id));
done = 1;
}
break;
@@ -150,7 +150,7 @@ geometry_register_segment
struct definition* new_def;
ERR(darray_definition_resize(definitions, 1 + defs_sz));
new_def = darray_definition_data_get(definitions) + defs_sz;
- ERR(darray_uint_push_back(&new_def->set_ids, &set_id));
+ ERR(darray_size_t_push_back(&new_def->set_ids, &set_id));
new_def->property_value = segment->properties[i];
if(!seg_d->merge_conflict && merge_conflict) {
/* If more than 1 merge_conflict occur, the first one remains */
@@ -189,10 +189,9 @@ geometry_enlarge_seg_descriptions
size_t old_sz =
darray_seg_descriptions_size_get(&geom->seg_descriptions);
if(sz <= old_sz) return RES_OK;
- ASSERT(sz - old_sz < UINT_MAX);
ERR(darray_seg_descriptions_resize(&geom->seg_descriptions, sz));
- geom->seg_with_unspecified_sides_count += (unsigned)(sz - old_sz);
- geom->seg_with_unspecified_intface_count += (unsigned)(sz - old_sz);
+ geom->seg_with_unspecified_sides_count += (sz - old_sz);
+ geom->seg_with_unspecified_intface_count += (sz - old_sz);
exit:
return res;
@@ -231,7 +230,7 @@ dump_partition
dump = seg_descriptions[i].properties_conflict;
}
if(!dump) continue;
- fprintf(stream, "l %u %u\n",
+ fprintf(stream, "l %zu %zu\n",
/* OBJ indexing starts at 1 */
1 + segments[i].vertex_ids[0],
1 + segments[i].vertex_ids[1]);
@@ -293,9 +292,9 @@ error:
res_T
sg2d_geometry_reserve
(struct sg2d_geometry* geom,
- const unsigned vertices_count,
- const unsigned segments_count,
- const unsigned properties_count)
+ const size_t vertices_count,
+ const size_t segments_count,
+ const size_t properties_count)
{
res_T res = RES_OK;
if(!geom) return RES_BAD_ARG;
@@ -316,18 +315,18 @@ error:
res_T
sg2d_geometry_add
(struct sg2d_geometry* geom,
- const unsigned nverts,
- const unsigned nsegs,
+ const size_t nverts,
+ const size_t nsegs,
const struct sg2d_geometry_add_callbacks* callbacks,
void* ctx) /* Can be NULL */
{
res_T res = RES_OK;
struct mem_allocator* alloc;
size_t nuseg, nuverts;
- unsigned i, n_new_uverts = 0, n_new_utris = 0;
+ size_t i, n_new_uverts = 0, n_new_utris = 0;
struct segment* seg;
/* Tmp table of IDs to record unique IDs of the currently added vertices */
- struct darray_uint unique_vertice_ids;
+ struct darray_size_t unique_vertice_ids;
int unique_vertice_ids_initialized = 0;
if(!geom || !callbacks || !callbacks->get_indices || !callbacks->get_position)
@@ -341,9 +340,9 @@ sg2d_geometry_add
nuseg = darray_segment_size_get(&geom->unique_segments);
/* Make room for new geometry; suppose no more duplicates */
- darray_uint_init(alloc, &unique_vertice_ids);
+ darray_size_t_init(alloc, &unique_vertice_ids);
unique_vertice_ids_initialized = 1;
- ERR(darray_uint_reserve(&unique_vertice_ids, nverts));
+ ERR(darray_size_t_reserve(&unique_vertice_ids, nverts));
ERR(darray_vertex_reserve(&geom->unique_vertices, nuverts + nverts));
ERR(darray_segment_reserve(&geom->unique_segments, nuseg + nsegs));
ERR(htable_vrtx_reserve(&geom->unique_vertices_ids, nuverts + nverts));
@@ -352,9 +351,9 @@ sg2d_geometry_add
ERR(darray_seg_descriptions_reserve(&geom->seg_descriptions, nuseg + nsegs));
/* Get vertices and deduplicate */
FOR_EACH(i, 0, nverts) {
- unsigned* p_vrtx;
+ size_t* p_vrtx;
struct vertex tmp;
- unsigned v_idx;
+ size_t v_idx;
callbacks->get_position(i, tmp.coord, ctx);
p_vrtx = htable_vrtx_find(&geom->unique_vertices_ids, &tmp);
if(p_vrtx) {
@@ -362,26 +361,25 @@ sg2d_geometry_add
v_idx = *p_vrtx;
} else {
/* New vertex */
- ASSERT(nuverts + n_new_uverts < UINT_MAX);
- v_idx = (unsigned)(nuverts + n_new_uverts);
+ v_idx = nuverts + n_new_uverts;
ASSERT(v_idx == htable_vrtx_size_get(&geom->unique_vertices_ids));
ERR(darray_vertex_push_back(&geom->unique_vertices, &tmp));
ERR(htable_vrtx_set(&geom->unique_vertices_ids, &tmp, &v_idx));
++n_new_uverts;
}
/* Keep the unique ID for vertex i */
- ERR(darray_uint_push_back(&unique_vertice_ids, &v_idx));
+ ERR(darray_size_t_push_back(&unique_vertice_ids, &v_idx));
}
/* Get segments and deduplicate */
seg = darray_segment_data_get(&geom->unique_segments);
FOR_EACH(i, 0, nsegs) {
int j, reversed;
- struct unsigned2 seg_key;
+ struct size2 seg_key;
struct segment tmp = SEG_UNDEF__;
- unsigned* p_seg;
+ size_t* p_seg;
struct seg_descriptions* seg_descriptions = NULL;
- unsigned unique_id;
+ size_t unique_id;
callbacks->get_indices(i, tmp.vertex_ids, ctx);
FOR_EACH(j, 0, 2) {
@@ -391,7 +389,7 @@ sg2d_geometry_add
}
/* Replace the vertex ID by its the unique ID */
tmp.vertex_ids[j]
- = darray_uint_cdata_get(&unique_vertice_ids)[tmp.vertex_ids[j]];
+ = darray_size_t_cdata_get(&unique_vertice_ids)[tmp.vertex_ids[j]];
}
if(tmp.vertex_ids[0] == tmp.vertex_ids[1]) {
int abort = 0;
@@ -399,7 +397,7 @@ sg2d_geometry_add
/* Let the client app rule. */
ERR(callbacks->degenerated_segment(i, ctx, &abort));
} else {
- log_warn(geom->dev, "%s: segment %u is degenerated.\n",
+ log_warn(geom->dev, "%s: segment %zu is degenerated.\n",
FUNC_NAME, i);
}
if(abort) {
@@ -416,7 +414,7 @@ sg2d_geometry_add
p_seg = htable_seg_find(&geom->unique_segments_ids, &seg_key);
if(p_seg) {
/* Duplicate segment. Need to check duplicate validity */
- struct unsigned2 useg_key;
+ struct size2 useg_key;
int ureversed = seg_make_key(&useg_key, seg[*p_seg].vertex_ids);
int same = (reversed == ureversed);
int already_conflict;
@@ -426,7 +424,7 @@ sg2d_geometry_add
seg_descriptions
= darray_seg_descriptions_data_get(&geom->seg_descriptions);
if(!same)
- SWAP(unsigned, tmp.properties[SG2D_FRONT], tmp.properties[SG2D_BACK]);
+ SWAP(size_t, tmp.properties[SG2D_FRONT], tmp.properties[SG2D_BACK]);
already_conflict = seg_descriptions[i].merge_conflict;
if(callbacks->merge_segment) {
/* Let the client app rule. */
@@ -455,8 +453,7 @@ sg2d_geometry_add
}
} else {
/* New segment */
- ASSERT(nuseg + n_new_utris < UINT_MAX);
- unique_id = (unsigned)(nuseg + n_new_utris);
+ unique_id = nuseg + n_new_utris;
tmp.user_id = geom->segment_count_including_duplicates + i;
if(callbacks->add_segment)
ERR(callbacks->add_segment(unique_id, i, ctx));
@@ -489,7 +486,7 @@ exit:
geom->segment_count_including_duplicates += nsegs;
}
if(unique_vertice_ids_initialized)
- darray_uint_release(&unique_vertice_ids);
+ darray_size_t_release(&unique_vertice_ids);
return res;
error:
goto exit;
@@ -498,11 +495,10 @@ error:
res_T
sg2d_geometry_validate_properties
(struct sg2d_geometry* geom,
- res_T(*validate)(const unsigned, const unsigned*, void*, int*),
+ res_T(*validate)(const size_t, const size_t*, void*, int*),
void* ctx)
{
- size_t sz__;
- unsigned i, sz;
+ size_t i, sz;
struct seg_descriptions* seg_descriptions;
res_T res = RES_OK;
@@ -511,15 +507,13 @@ sg2d_geometry_validate_properties
goto error;
}
- sz__ = darray_seg_descriptions_size_get(&geom->seg_descriptions);
- ASSERT(sz__ <= UINT_MAX);
- sz = (unsigned)sz__;
+ sz= darray_seg_descriptions_size_get(&geom->seg_descriptions);
seg_descriptions
= darray_seg_descriptions_data_get(&geom->seg_descriptions);
geom->properties_conflict_count = 0; /* Reset count */
FOR_EACH(i, 0, sz) {
- unsigned p, j;
- unsigned props[SG2D_PROP_TYPES_COUNT__];
+ size_t p, j;
+ size_t props[SG2D_PROP_TYPES_COUNT__];
struct seg_descriptions* segd = seg_descriptions + i;
/* Validate only segment not flagged with merge_conflict */
if(segd->merge_conflict) {
@@ -552,17 +546,14 @@ error:
res_T
sg2d_geometry_get_unique_vertices_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
- size_t sz;
if(!geom || !count) {
res = RES_BAD_ARG;
goto error;
}
- sz = darray_vertex_size_get(&geom->unique_vertices);
- ASSERT(sz <= UINT_MAX);
- *count = (unsigned)sz;
+ *count = darray_vertex_size_get(&geom->unique_vertices);
exit:
return res;
error:
@@ -572,7 +563,7 @@ error:
res_T
sg2d_geometry_get_unique_vertex
(const struct sg2d_geometry* geom,
- const unsigned ivtx,
+ const size_t ivtx,
double coord[2])
{
res_T res = RES_OK;
@@ -594,7 +585,7 @@ error:
res_T
sg2d_geometry_get_added_segments_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
if (!geom || !count) {
@@ -611,17 +602,14 @@ error:
res_T
sg2d_geometry_get_unique_segments_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
- size_t sz;
if(!geom || !count) {
res = RES_BAD_ARG;
goto error;
}
- sz = darray_segment_size_get(&geom->unique_segments);
- ASSERT(sz <= UINT_MAX);
- *count = (unsigned)sz;
+ *count = darray_segment_size_get(&geom->unique_segments);
exit:
return res;
error:
@@ -631,8 +619,8 @@ error:
res_T
sg2d_geometry_get_unique_segment_vertices
(const struct sg2d_geometry* geom,
- const unsigned iseg,
- unsigned indices[2])
+ const size_t iseg,
+ size_t indices[2])
{
res_T res = RES_OK;
const struct segment* segments;
@@ -654,8 +642,8 @@ error:
res_T
sg2d_geometry_get_unique_segment_properties
(const struct sg2d_geometry* geom,
- const unsigned iseg,
- unsigned properties[SG2D_PROP_TYPES_COUNT__])
+ const size_t iseg,
+ size_t properties[SG2D_PROP_TYPES_COUNT__])
{
res_T res = RES_OK;
const struct segment* segments;
@@ -678,8 +666,8 @@ error:
res_T
sg2d_geometry_get_unique_segment_user_id
(const struct sg2d_geometry* geom,
- const unsigned iseg,
- unsigned* user_id)
+ const size_t iseg,
+ size_t* user_id)
{
res_T res = RES_OK;
const struct segment* segments;
@@ -700,7 +688,7 @@ error:
res_T
sg2d_geometry_get_unique_segments_with_unspecified_side_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
if(!geom || !count) {
@@ -717,7 +705,7 @@ error:
res_T
sg2d_geometry_get_unique_segments_with_unspecified_interface_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
if(!geom || !count) {
@@ -734,7 +722,7 @@ error:
res_T
sg2d_geometry_get_unique_segments_with_merge_conflict_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
if(!geom || !count) {
@@ -751,7 +739,7 @@ error:
res_T
sg2d_geometry_get_unique_segments_with_properties_conflict_count
(const struct sg2d_geometry* geom,
- unsigned* count)
+ size_t* count)
{
res_T res = RES_OK;
if(!geom || !count) {
@@ -788,16 +776,14 @@ sg2d_geometry_dump_as_obj
fprintf(stream, "# Dump of star-geometry-2D\n");
fprintf(stream, "# Geometry counts:\n");
vsz = darray_vertex_size_get(&geom->unique_vertices);
- ASSERT(vsz <= UINT_MAX);
- fprintf(stream, "# . %u vertices\n", (unsigned)vsz);
+ fprintf(stream, "# . %zu vertices\n", vsz);
tsz = darray_segment_size_get(&geom->unique_segments);
- ASSERT(tsz <= UINT_MAX);
- fprintf(stream, "# . %u segments\n", (unsigned)tsz);
+ fprintf(stream, "# . %zu segments\n", tsz);
fprintf(stream,
- "# . %u segments flagged with a merge conflict\n",
+ "# . %zu segments flagged with a merge conflict\n",
geom->merge_conflict_count);
fprintf(stream,
- "# . %u segments flagged with a property conflict\n",
+ "# . %zu segments flagged with a property conflict\n",
geom->merge_conflict_count);
/* Dump vertices */
@@ -842,22 +828,20 @@ sg2d_geometry_dump_as_vtk
/* Dump vertices */
vsz = darray_vertex_size_get(&geom->unique_vertices);
- ASSERT(vsz <= UINT_MAX);
- fprintf(stream, "POINTS %u double\n", (unsigned)vsz);
+ fprintf(stream, "POINTS %zu double\n", vsz);
vertices = darray_vertex_cdata_get(&geom->unique_vertices);
FOR_EACH(i, 0, vsz)
fprintf(stream, "%g %g 0\n", SPLIT2(vertices[i].coord));
/* Dump segments */
tsz = darray_segment_size_get(&geom->unique_segments);
- ASSERT(4 * tsz <= UINT_MAX);
- fprintf(stream, "LINES %u %u\n", (unsigned)tsz, (unsigned)(3 * tsz));
+ fprintf(stream, "LINES %zu %zu\n", tsz, 3 * tsz);
segments = darray_segment_cdata_get(&geom->unique_segments);
FOR_EACH(i, 0, tsz)
- fprintf(stream, "2 %u %u\n", SPLIT2(segments[i].vertex_ids));
+ fprintf(stream, "2 %zu %zu\n", SPLIT2(segments[i].vertex_ids));
/* Start segments properties */
- fprintf(stream, "CELL_DATA %u\n", (unsigned)tsz);
+ fprintf(stream, "CELL_DATA %zu\n", tsz);
descriptions = darray_seg_descriptions_cdata_get(&geom->seg_descriptions);
/* Dump front medium */
@@ -879,7 +863,7 @@ sg2d_geometry_dump_as_vtk
fprintf(stream, "SCALARS User_ID int\n");
fprintf(stream, "LOOKUP_TABLE default\n");
FOR_EACH(i, 0, tsz)
- fprintf(stream, "%u\n", segments[i].user_id);
+ fprintf(stream, "%zu\n", segments[i].user_id);
/* Dump merge conflict status */
fprintf(stream, "SCALARS Merge_conflict int\n");
@@ -898,12 +882,12 @@ sg2d_geometry_dump_as_vtk
fprintf(stream, "LOOKUP_TABLE default\n");
FOR_EACH(i, 0, tsz) {
const struct definition* tdefs;
- const unsigned* ranks;
+ const size_t* ranks;
ASSERT(darray_definition_size_get(&descriptions[i].defs[SG2D_FRONT]) > 0);
/* Rank is the first set_id of the first definition of any property */
tdefs = darray_definition_cdata_get(&descriptions[i].defs[SG2D_FRONT]);
- ranks = darray_uint_cdata_get(&tdefs[0].set_ids);
- fprintf(stream, "%u\n", ranks[0]);
+ ranks = darray_size_t_cdata_get(&tdefs[0].set_ids);
+ fprintf(stream, "%zu\n", ranks[0]);
}
exit:
@@ -949,9 +933,7 @@ sg2d_geometry_dump_as_c_code
else
fprintf(stream, "/* Dump of star-geometry-2D. */\n");
vsz = darray_vertex_size_get(&geom->unique_vertices);
- ASSERT(3 * vsz <= UINT_MAX);
tsz = darray_segment_size_get(&geom->unique_segments);
- ASSERT(3 * tsz <= UINT_MAX);
if(vsz == 0 || tsz == 0) {
log_err(geom->dev,
@@ -970,14 +952,14 @@ sg2d_geometry_dump_as_c_code
else qualifiers = "";
/* Dump vertices */
- fprintf(stream, "%sunsigned %s_vertices_count = %u;\n",
- qualifiers, name_prefix, (unsigned)vsz);
+ fprintf(stream, "%ssize_t %s_vertices_count = %zu;\n",
+ qualifiers, name_prefix, vsz);
vertices = darray_vertex_cdata_get(&geom->unique_vertices);
fprintf(stream,
- "%sdouble %s_vertices[%u] =\n"
+ "%sdouble %s_vertices[%zu] =\n"
"{\n",
- qualifiers, name_prefix, (unsigned)(2 * vsz));
+ qualifiers, name_prefix, 2 * vsz);
FOR_EACH(i, 0, vsz - 1)
fprintf(stream,
" %g, %g,\n", SPLIT2(vertices[i].coord));
@@ -987,34 +969,34 @@ sg2d_geometry_dump_as_c_code
"};\n");
/* Dump segments */
- fprintf(stream, "%sunsigned %s_segments_count = %u;\n",
- qualifiers, name_prefix, (unsigned)tsz);
+ fprintf(stream, "%ssize_t %s_segments_count = %zu;\n",
+ qualifiers, name_prefix, tsz);
segments = darray_segment_cdata_get(&geom->unique_segments);
fprintf(stream,
- "%sunsigned %s_segments[%u] =\n"
+ "%ssize_t %s_segments[%zu] =\n"
"{\n",
- qualifiers, name_prefix, (unsigned)(2 * tsz));
+ qualifiers, name_prefix, 2 * tsz);
FOR_EACH(i, 0, tsz - 1)
fprintf(stream,
- " %u, %u,\n", SPLIT2(segments[i].vertex_ids));
+ " %zu, %zu,\n", SPLIT2(segments[i].vertex_ids));
fprintf(stream,
- " %u, %u\n", SPLIT2(segments[tsz - 1].vertex_ids));
+ " %zu, %zu\n", SPLIT2(segments[tsz - 1].vertex_ids));
fprintf(stream,
"};\n");
/* Dump properties */
fprintf(stream,
- "%sunsigned %s_properties[%u] =\n"
+ "%ssize_t %s_properties[%zu] =\n"
"{\n",
- qualifiers, name_prefix, (unsigned)(SG2D_PROP_TYPES_COUNT__ * tsz));
+ qualifiers, name_prefix, SG2D_PROP_TYPES_COUNT__ * tsz);
FOR_EACH(i, 0, tsz) {
int p;
fprintf(stream, " ");
FOR_EACH(p, 0, SG2D_PROP_TYPES_COUNT__) {
if(segments[i].properties[p] == SG2D_UNSPECIFIED_PROPERTY)
fprintf(stream, " SG2D_UNSPECIFIED_PROPERTY");
- else fprintf(stream," %u", segments[i].properties[p]);
+ else fprintf(stream," %zu", segments[i].properties[p]);
if(i < tsz-1 || p < 2) fprintf(stream, ",");
if(p == 2) fprintf(stream, "\n");
}
diff --git a/src/sg2d_geometry.h b/src/sg2d_geometry.h
@@ -21,6 +21,7 @@
#include <rsys/ref_count.h>
#include <rsys/dynamic_array.h>
+#include <rsys/dynamic_array_size_t.h>
#include <rsys/hash_table.h>
/* Forward declaration of external opaque data types */
@@ -29,11 +30,11 @@
* A type to store segments
******************************************************************************/
struct segment {
- unsigned vertex_ids[2];
+ size_t vertex_ids[2];
/* FRONT/BACK/INTERFACE property */
- unsigned properties[SG2D_PROP_TYPES_COUNT__];
+ size_t properties[SG2D_PROP_TYPES_COUNT__];
/* ID of the segment in user world, i.e. without deduplication */
- unsigned user_id;
+ size_t user_id;
};
#define SEG_UNDEF__ {\
{ SG2D_UNSPECIFIED_PROPERTY, SG2D_UNSPECIFIED_PROPERTY },\
@@ -57,18 +58,18 @@ struct vertex {
/*******************************************************************************
* A type to map segment vertices to IDs in unique_segments
******************************************************************************/
-struct unsigned2 { unsigned x[2]; };
+struct size2 { size_t x[2]; };
static FINLINE int
-seg_key_eq(const struct unsigned2* k1, const struct unsigned2* k2)
+seg_key_eq(const struct size2* k1, const struct size2* k2)
{
ASSERT(k1 && k2 && k1->x[0] < k1->x[1] && k2->x[0] < k2->x[1]);
return (k1->x[0] == k2->x[0]) && (k1->x[1] == k2->x[1]);
}
#define HTABLE_NAME seg
-#define HTABLE_KEY struct unsigned2
-#define HTABLE_DATA unsigned
+#define HTABLE_KEY struct size2
+#define HTABLE_DATA size_t
#define HTABLE_KEY_FUNCTOR_EQ seg_key_eq
#include <rsys/hash_table.h>
@@ -86,7 +87,7 @@ vrtx_eq(const struct vertex* v1, const struct vertex* v2)
#define HTABLE_NAME vrtx
#define HTABLE_KEY struct vertex
-#define HTABLE_DATA unsigned
+#define HTABLE_DATA size_t
#define HTABLE_KEY_FUNCTOR_EQ vrtx_eq
#include <rsys/hash_table.h>
@@ -98,9 +99,9 @@ vrtx_eq(const struct vertex* v1, const struct vertex* v2)
* (usualy a single file) */
struct definition {
/* The value */
- unsigned property_value;
+ size_t property_value;
/* The IDs of the geometry sets that defined the value */
- struct darray_uint set_ids;
+ struct darray_size_t set_ids;
};
static FINLINE void
@@ -110,7 +111,7 @@ init_definition
{
ASSERT(alloc && data);
data->property_value = SG2D_UNSPECIFIED_PROPERTY;
- darray_uint_init(alloc, &data->set_ids);
+ darray_size_t_init(alloc, &data->set_ids);
}
static INLINE res_T
@@ -121,7 +122,7 @@ copy_definition
res_T res = RES_OK;
ASSERT(dst && src);
dst->property_value = src->property_value;
- ERR(darray_uint_copy(&dst->set_ids, &src->set_ids));
+ ERR(darray_size_t_copy(&dst->set_ids, &src->set_ids));
exit:
return res;
error:
@@ -133,7 +134,7 @@ release_definition
(struct definition* data)
{
ASSERT(data);
- darray_uint_release(&data->set_ids);
+ darray_size_t_release(&data->set_ids);
}
#define DARRAY_NAME definition
@@ -213,14 +214,14 @@ release_seg_descriptions
static FINLINE void
init_seg_intfaceid
(struct mem_allocator* alloc,
- unsigned* data)
+ size_t* data)
{
ASSERT(data); (void)alloc;
*data = SG2D_UNSPECIFIED_PROPERTY;
}
#define DARRAY_NAME intface_id
-#define DARRAY_DATA unsigned
+#define DARRAY_DATA size_t
#define DARRAY_FUNCTOR_INIT init_seg_intfaceid
#include <rsys/dynamic_array.h>
@@ -242,13 +243,13 @@ struct sg2d_geometry {
struct darray_seg_descriptions seg_descriptions;
/* Counts */
- unsigned set_id;
- unsigned segment_count_including_duplicates;
- unsigned sides_with_defined_medium_count;
- unsigned seg_with_unspecified_sides_count;
- unsigned seg_with_unspecified_intface_count;
- unsigned merge_conflict_count;
- unsigned properties_conflict_count;
+ size_t set_id;
+ size_t segment_count_including_duplicates;
+ size_t sides_with_defined_medium_count;
+ size_t seg_with_unspecified_sides_count;
+ size_t seg_with_unspecified_intface_count;
+ size_t merge_conflict_count;
+ size_t properties_conflict_count;
struct sg2d_device* dev;
ref_T ref;
@@ -262,8 +263,8 @@ extern LOCAL_SYM res_T
geometry_register_segment
(struct sg2d_geometry* geometry,
const struct segment* segment,
- const unsigned segment_unique_id,
- const unsigned set_id,
+ const size_t segment_unique_id,
+ const size_t set_id,
const int merge_conflict);
/* Add new undefined segment descriptions to a geometry */
diff --git a/src/sg2d_sXd_helper.h b/src/sg2d_sXd_helper.h
@@ -22,6 +22,8 @@
#include <rsys/rsys.h>
#include <rsys/float2.h>
+#include <limits.h>
+
/* Get vertex indices for the iseg_th segment.
* Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices
* calls. */
@@ -32,10 +34,16 @@ sg2d_sXd_geometry_get_indices
void* ctx)
{
const struct sg2d_geometry* geometry = ctx;
+ int i;
+ size_t tmp[3];
res_T r;
ASSERT(indices && geometry);
- r = sg2d_geometry_get_unique_segment_vertices(geometry, iseg, indices);
+ r = sg2d_geometry_get_unique_segment_vertices(geometry, iseg, tmp);
ASSERT(r == RES_OK); (void)r;
+ FOR_EACH(i, 0, 3) {
+ ASSERT(tmp[i] <= UINT_MAX);
+ indices[i] = (unsigned)tmp[i];
+ }
}
/* Get coordinates for the ivert_th vertex.
diff --git a/src/sg2d_sencXd_helper.h b/src/sg2d_sencXd_helper.h
@@ -25,8 +25,8 @@
* Suitable for use as get_indices callback in senc2d_scene_create calls. */
static FINLINE void
sg2d_sencXd_geometry_get_indices
- (const unsigned iseg,
- unsigned indices[SG2D_GEOMETRY_DIMENSION],
+ (const size_t iseg,
+ size_t indices[SG2D_GEOMETRY_DIMENSION],
void* ctx)
{
const struct sg2d_geometry* geometry = ctx;
@@ -40,12 +40,12 @@ sg2d_sencXd_geometry_get_indices
* Suitable for use as get_media callback in senc2d_scene_create calls. */
static FINLINE void
sg2d_sencXd_geometry_get_media
- (const unsigned iseg,
- unsigned media[2],
+ (const size_t iseg,
+ size_t media[2],
void* ctx)
{
const struct sg2d_geometry* geometry = ctx;
- unsigned tmp[SG2D_PROP_TYPES_COUNT__];
+ size_t tmp[SG2D_PROP_TYPES_COUNT__];
res_T r;
ASSERT(media && geometry);
r = sg2d_geometry_get_unique_segment_properties(geometry, iseg, tmp);
@@ -60,7 +60,7 @@ sg2d_sencXd_geometry_get_media
* Suitable for use as get_position callback in senc2d_scene_create calls. */
static FINLINE void
sg2d_sencXd_geometry_get_position
- (const unsigned ivert,
+ (const size_t ivert,
double coord[SG2D_GEOMETRY_DIMENSION],
void* ctx)
{
diff --git a/src/test_sg2d_geometry.c b/src/test_sg2d_geometry.c
@@ -20,8 +20,8 @@
static res_T
validate
- (const unsigned iseg,
- const unsigned properties[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ const size_t properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
@@ -32,11 +32,11 @@ validate
static res_T
merge_seg
- (const unsigned user_id,
- const unsigned iseg,
+ (const size_t user_id,
+ const size_t iseg,
const int reversed_segment,
- unsigned segment_properties[SG2D_PROP_TYPES_COUNT__],
- const unsigned merged_properties[SG2D_PROP_TYPES_COUNT__],
+ size_t segment_properties[SG2D_PROP_TYPES_COUNT__],
+ const size_t merged_properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* merge_conflict)
{
@@ -49,7 +49,7 @@ merge_seg
static res_T
degenerated_segment
- (const unsigned iseg,
+ (const size_t iseg,
void* context,
int* abort)
{
@@ -67,12 +67,12 @@ main(int argc, char** argv)
struct sg2d_device* dev;
struct sg2d_geometry* geom;
double coord[2];
- unsigned indices[2];
- unsigned degenerated[2] = { 0, 0 };
- unsigned properties[SG2D_PROP_TYPES_COUNT__];
+ size_t indices[2];
+ size_t degenerated[2] = { 0, 0 };
+ size_t properties[SG2D_PROP_TYPES_COUNT__];
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned user_id;
- unsigned count, i;
+ size_t user_id;
+ size_t count, i;
struct context ctx = CONTEXT_NULL__;
(void)argc, (void)argv;
diff --git a/src/test_sg2d_geometry_2.c b/src/test_sg2d_geometry_2.c
@@ -20,14 +20,14 @@
/* Manage add_geometry behaviour */
struct add_geom_ctx {
- unsigned add_cpt, merge_cpt;
+ size_t add_cpt, merge_cpt;
res_T add_res, merge_res;
};
static res_T
add_seg
- (const unsigned unique_id,
- const unsigned iseg,
+ (const size_t unique_id,
+ const size_t iseg,
void* context)
{
struct context* ctx = context;
@@ -40,11 +40,11 @@ add_seg
static res_T
merge_seg
- (const unsigned unique_id,
- const unsigned iseg,
+ (const size_t unique_id,
+ const size_t iseg,
const int reversed_segment,
- unsigned segment_properties[SG2D_PROP_TYPES_COUNT__],
- const unsigned merged_properties[SG2D_PROP_TYPES_COUNT__],
+ size_t segment_properties[SG2D_PROP_TYPES_COUNT__],
+ const size_t merged_properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* merge_conflict)
{
@@ -64,8 +64,8 @@ merge_seg
static res_T
validate
- (const unsigned iseg,
- const unsigned properties[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ const size_t properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
@@ -76,8 +76,8 @@ validate
static res_T
validate2
- (const unsigned iseg,
- const unsigned properties[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ const size_t properties[SG2D_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
@@ -95,10 +95,10 @@ main(int argc, char** argv)
struct context ctx = CONTEXT_NULL__;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
struct add_geom_ctx add_geom_ctx;
- unsigned property[12];
- unsigned i;
- const unsigned property_count = sizeof(property) / sizeof(*property);
- unsigned count;
+ size_t property[12];
+ size_t i;
+ const size_t property_count = sizeof(property) / sizeof(*property);
+ size_t count;
(void)argc, (void)argv;
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
@@ -303,7 +303,7 @@ main(int argc, char** argv)
OK(sg2d_geometry_dump_as_vtk(geom, stdout));
/* Second add was half duplicated, so numbering is shifted */
FOR_EACH(i, 0, nsegments) {
- unsigned id;
+ size_t id;
OK(sg2d_geometry_get_unique_segment_user_id(geom, i, &id));
CHK(i < nsegments / 2 ? id == i : id == i + nsegments / 2);
}
diff --git a/src/test_sg2d_many_enclosures.c b/src/test_sg2d_many_enclosures.c
@@ -20,7 +20,6 @@
#include <rsys/double2.h>
#include <stdio.h>
-#include <limits.h>
#define NB_CIRC_X 32
#define NB_CIRC_Y 32
@@ -34,9 +33,9 @@ main(int argc, char** argv)
struct sg2d_device* dev;
struct sg2d_geometry* geom;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned circ_seg_count, circ_vrtx_count, count;
+ size_t circ_seg_count, circ_vrtx_count, count;
int i, j, k;
- unsigned m_in, m_out, itf = 0;
+ size_t m_in, m_out, itf = 0;
struct context ctx = CONTEXT_NULL__;
(void)argc, (void)argv;
@@ -55,12 +54,10 @@ main(int argc, char** argv)
/* A 16 segments circle template */
create_circle(1, 16, &ctx);
- ASSERT(sa_size(ctx.positions) % 2 == 0
- && sa_size(ctx.positions) / 2 < UINT_MAX);
- ASSERT(sa_size(ctx.indices) % 2 == 0
- && sa_size(ctx.indices) / 2 < UINT_MAX);
- circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
- circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
+ ASSERT(sa_size(ctx.positions) % 2 == 0);
+ ASSERT(sa_size(ctx.indices) % 2 == 0);
+ circ_seg_count = sa_size(ctx.indices) / 2;
+ circ_vrtx_count = sa_size(ctx.positions) / 2;
OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
NB_CIRC * circ_seg_count, 0));
FOR_EACH(i, 0, NB_CIRC_X) {
@@ -69,8 +66,8 @@ main(int argc, char** argv)
double center_y = 2 * (1 + NB_CIRC_Z) * (j - NB_CIRC_Y / 2);
double misalignment = 0;
FOR_EACH(k, 0, NB_CIRC_Z) {
- m_in = (unsigned)k;
- m_out = (unsigned)(k + 1);
+ m_in = (size_t)k;
+ m_out = (size_t)(k + 1);
ctx.scale = k + 1;
#ifdef MITIGATE_EMBREE_181
/* Mitigate Embree issue #181
diff --git a/src/test_sg2d_many_segments.c b/src/test_sg2d_many_segments.c
@@ -20,7 +20,6 @@
#include <rsys/double2.h>
#include <stdio.h>
-#include <limits.h>
#define NB_CIRC 2
@@ -31,8 +30,8 @@ main(int argc, char** argv)
struct sg2d_device* dev;
struct sg2d_geometry* geom;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned circ_seg_count, circ_vrtx_count, i, count;
- unsigned m0 = 0, m1, itf = 0;
+ size_t circ_seg_count, circ_vrtx_count, i, count;
+ size_t m0 = 0, m1, itf = 0;
struct context ctx = CONTEXT_NULL__;
(void)argc, (void)argv;
@@ -51,17 +50,15 @@ main(int argc, char** argv)
/* A 1,048,576 segments circle template */
create_circle(1, 1048576, &ctx);
- ASSERT(sa_size(ctx.positions) % 2 == 0
- && sa_size(ctx.positions) / 2 < UINT_MAX);
- ASSERT(sa_size(ctx.indices) % 2 == 0
- && sa_size(ctx.indices) / 2 < UINT_MAX);
- circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
- circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
+ ASSERT(sa_size(ctx.positions) % 2 == 0);
+ ASSERT(sa_size(ctx.indices) % 2 == 0);
+ circ_seg_count = sa_size(ctx.indices) / 2;
+ circ_vrtx_count = sa_size(ctx.positions) / 2;
OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
NB_CIRC * circ_seg_count, 0));
FOR_EACH(i, 0, NB_CIRC) {
m1 = i;
- d2(ctx.offset, 0, i * 10);
+ d2(ctx.offset, 0, (double)i * 10);
OK(sg2d_geometry_add(geom, circ_vrtx_count, circ_seg_count, &callbacks,
&ctx));
}
diff --git a/src/test_sg2d_some_enclosures.c b/src/test_sg2d_some_enclosures.c
@@ -20,7 +20,6 @@
#include <rsys/double2.h>
#include <stdio.h>
-#include <limits.h>
#define NB_CIRC_X 4
#define NB_CIRC_Y 4
@@ -34,9 +33,9 @@ main(int argc, char** argv)
struct sg2d_device* dev;
struct sg2d_geometry* geom;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned circ_seg_count, circ_vrtx_count, count;
+ size_t circ_seg_count, circ_vrtx_count, count;
int i, j, k;
- unsigned m_in, m_out, itf = 0;
+ size_t m_in, m_out, itf = 0;
struct context ctx = CONTEXT_NULL__;
(void)argc, (void)argv;
@@ -55,12 +54,10 @@ main(int argc, char** argv)
/* A 16 segments circle template */
create_circle(1, 16, &ctx);
- ASSERT(sa_size(ctx.positions) % 2 == 0
- && sa_size(ctx.positions) / 2 < UINT_MAX);
- ASSERT(sa_size(ctx.indices) % 2 == 0
- && sa_size(ctx.indices) / 2 < UINT_MAX);
- circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
- circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
+ ASSERT(sa_size(ctx.positions) % 2 == 0);
+ ASSERT(sa_size(ctx.indices) % 2 == 0);
+ circ_seg_count = sa_size(ctx.indices) / 2;
+ circ_vrtx_count = sa_size(ctx.positions) / 2;
OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
NB_CIRC * circ_seg_count, 0));
FOR_EACH(i, 0, NB_CIRC_X) {
@@ -69,8 +66,8 @@ main(int argc, char** argv)
double center_y = 2 * (1 + NB_CIRC_Z) * (j - NB_CIRC_Y / 2);
double misalignment = 0;
FOR_EACH(k, 0, NB_CIRC_Z) {
- m_in = (unsigned)k;
- m_out = (unsigned)(k + 1);
+ m_in = (size_t)k;
+ m_out = (size_t)(k + 1);
ctx.scale = k + 1;
#ifdef MITIGATE_EMBREE_181
/* Mitigate Embree issue #181
diff --git a/src/test_sg2d_some_segments.c b/src/test_sg2d_some_segments.c
@@ -20,7 +20,6 @@
#include <rsys/double2.h>
#include <stdio.h>
-#include <limits.h>
#define NB_CIRC 4
@@ -31,8 +30,8 @@ main(int argc, char** argv)
struct sg2d_device* dev;
struct sg2d_geometry* geom;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned circ_seg_count, circ_vrtx_count, i, count;
- unsigned m0 = 0, m1, itf = 0;
+ size_t circ_seg_count, circ_vrtx_count, i, count;
+ size_t m0 = 0, m1, itf = 0;
struct context ctx = CONTEXT_NULL__;
(void)argc, (void)argv;
@@ -51,18 +50,16 @@ main(int argc, char** argv)
/* A 264 segments circle template */
create_circle(1, 264, &ctx);
- ASSERT(sa_size(ctx.positions) % 2 == 0
- && sa_size(ctx.positions) / 2 < UINT_MAX);
- ASSERT(sa_size(ctx.indices) % 2 == 0
- && sa_size(ctx.indices) / 2 < UINT_MAX);
- circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
- circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
+ ASSERT(sa_size(ctx.positions) % 2 == 0);
+ ASSERT(sa_size(ctx.indices) % 2 == 0);
+ circ_seg_count = sa_size(ctx.indices) / 2;
+ circ_vrtx_count = sa_size(ctx.positions) / 2;
OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
NB_CIRC * circ_seg_count, 0));
FOR_EACH(i, 0, NB_CIRC) {
m1 = i;
- d2(ctx.offset, 0, i * 10);
+ d2(ctx.offset, 0, (double)i * 10);
OK(sg2d_geometry_add(geom, circ_vrtx_count, circ_seg_count, &callbacks,
&ctx));
}
diff --git a/src/test_sg2d_square_behind_square.c b/src/test_sg2d_square_behind_square.c
@@ -55,7 +55,7 @@ main(int argc, char** argv)
struct sg2d_geometry* geom;
struct context ctx = CONTEXT_NULL__;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned count;
+ size_t count;
(void)argc, (void)argv;
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
diff --git a/src/test_sg2d_square_in_square.c b/src/test_sg2d_square_in_square.c
@@ -45,7 +45,7 @@ main(int argc, char** argv)
struct sg2d_geometry* geom;
struct context ctx = CONTEXT_NULL__;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned count;
+ size_t count;
(void)argc, (void)argv;
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
diff --git a/src/test_sg2d_square_on_square.c b/src/test_sg2d_square_on_square.c
@@ -42,7 +42,7 @@ main(int argc, char** argv)
struct sg2d_geometry* geom;
struct context ctx = CONTEXT_NULL__;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned count;
+ size_t count;
(void)argc, (void)argv;
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
diff --git a/src/test_sg2d_unspecified_properties.c b/src/test_sg2d_unspecified_properties.c
@@ -26,10 +26,10 @@ main(int argc, char** argv)
struct sg2d_geometry* geom;
struct context ctx = CONTEXT_NULL__;
struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
- unsigned property[12];
- unsigned i;
- const unsigned property_count = sizeof(property) / sizeof(*property);
- unsigned count;
+ size_t property[12];
+ size_t i;
+ const size_t property_count = sizeof(property) / sizeof(*property);
+ size_t count;
(void)argc, (void)argv;
OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
@@ -81,7 +81,7 @@ main(int argc, char** argv)
OK(sg2d_geometry_get_unique_segments_count(geom, &count));
CHK(count == nsegments);
FOR_EACH(i, 0, count) {
- unsigned prop[SG2D_PROP_TYPES_COUNT__];
+ size_t prop[SG2D_PROP_TYPES_COUNT__];
OK(sg2d_geometry_get_unique_segment_properties(geom, i, prop));
CHK(prop[SG2D_FRONT] == ((i % 2) ? 0 : SG2D_UNSPECIFIED_PROPERTY)
&& prop[SG2D_BACK] == 1
@@ -90,7 +90,7 @@ main(int argc, char** argv)
/* Same information again, using a reversed box */
ctx.reverse_vrtx = 1;
- SWAP(const unsigned*, ctx.front_media, ctx.back_media);
+ SWAP(const size_t*, ctx.front_media, ctx.back_media);
OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx));
OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count));
CHK(count == nsegments / 2);
@@ -113,7 +113,7 @@ main(int argc, char** argv)
OK(sg2d_geometry_get_unique_segments_count(geom, &count));
CHK(count == nsegments);
FOR_EACH(i, 0, count) {
- unsigned prop[SG2D_PROP_TYPES_COUNT__];
+ size_t prop[SG2D_PROP_TYPES_COUNT__];
OK(sg2d_geometry_get_unique_segment_properties(geom, i, prop));
CHK(prop[SG2D_FRONT] == 0 && prop[SG2D_BACK] == 1
&& prop[SG2D_INTFACE] == 0);
diff --git a/src/test_sg2d_utils.h b/src/test_sg2d_utils.h
@@ -48,7 +48,7 @@ square_vertices[4/*#vertices*/ * 2/*#coords per vertex*/] = {
0.0, 1.0,
1.0, 1.0
};
-static const unsigned
+static const size_t
nvertices = sizeof(square_vertices) / (2 * sizeof(*square_vertices));
/* Distorded square */
static const double
@@ -69,22 +69,22 @@ box_vertices[4/*#vertices*/ * 2/*#coords per vertex*/] = {
*
* The right-handed geometrical normal is outside the square
*/
-static unsigned
+static size_t
box_indices[4/*#segments*/ * 2/*#indices per segment*/] = {
0, 2,
2, 3,
3, 1,
1, 0
};
-static const unsigned
+static const size_t
nsegments = sizeof(box_indices) / (2 * sizeof(*box_indices));
struct context {
const double* positions;
- const unsigned* indices;
- const unsigned* front_media;
- const unsigned* back_media;
- const unsigned* intface;
+ const size_t* indices;
+ const size_t* front_media;
+ const size_t* back_media;
+ const size_t* intface;
void* custom;
double offset[2];
double scale;
@@ -94,18 +94,18 @@ struct context {
NULL, NULL, NULL, NULL, NULL, NULL, {0,0}, 1, 0, 0\
}
-static const unsigned medium0[4] = { 0, 0, 0, 0 };
-static const unsigned medium1[4] = { 1, 1, 1, 1 };
-static const unsigned medium2[4] = { 2, 2, 2, 2 };
-static const unsigned medium1_3[4] = { 1, 1, 3, 1 };
-static const unsigned medium1_bottom0[4] = { 1, 1, 1, 0 };
-static const unsigned medium1_top0[4] = { 1, 0, 1, 1 };
+static const size_t medium0[4] = { 0, 0, 0, 0 };
+static const size_t medium1[4] = { 1, 1, 1, 1 };
+static const size_t medium2[4] = { 2, 2, 2, 2 };
+static const size_t medium1_3[4] = { 1, 1, 3, 1 };
+static const size_t medium1_bottom0[4] = { 1, 1, 1, 0 };
+static const size_t medium1_top0[4] = { 1, 0, 1, 1 };
-static const unsigned intface0[4] = { 0, 0, 0, 0 };
-static const unsigned intface1[4] = { 1, 1, 1, 1 };
+static const size_t intface0[4] = { 0, 0, 0, 0 };
+static const size_t intface1[4] = { 1, 1, 1, 1 };
static INLINE void
-get_indices(const unsigned iseg, unsigned ids[2], void* context)
+get_indices(const size_t iseg, size_t ids[2], void* context)
{
const struct context* ctx = context;
ASSERT(ids && ctx);
@@ -114,7 +114,7 @@ get_indices(const unsigned iseg, unsigned ids[2], void* context)
}
static INLINE void
-get_position(const unsigned ivert, double pos[2], void* context)
+get_position(const size_t ivert, double pos[2], void* context)
{
const struct context* ctx = context;
ASSERT(pos && ctx);
@@ -124,8 +124,8 @@ get_position(const unsigned ivert, double pos[2], void* context)
static INLINE void
get_properties
- (const unsigned iseg,
- unsigned property[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ size_t property[SG2D_PROP_TYPES_COUNT__],
void* context)
{
const struct context* ctx = context;
diff --git a/src/test_sg2d_utils2.h b/src/test_sg2d_utils2.h
@@ -24,14 +24,14 @@
static INLINE void
create_circle
(const double radius,
- const unsigned nslices,
+ const size_t nslices,
struct context* ctx)
{
double step_theta;
- unsigned itheta;
- unsigned islice;
+ size_t itheta;
+ size_t islice;
double* d = NULL;
- unsigned* u = NULL;
+ size_t* u = NULL;
ASSERT(radius > 0 && nslices >= 3 && ctx);
step_theta = 2 * PI / (double)nslices;
@@ -45,8 +45,8 @@ create_circle
ctx->positions = d;
FOR_EACH(islice, 0, nslices) {
- const unsigned v0 = islice;
- const unsigned v1 = ((islice + 1) % nslices);
+ const size_t v0 = islice;
+ const size_t v1 = ((islice + 1) % nslices);
sa_push(u, v0);
sa_push(u, v1);
}
@@ -65,8 +65,8 @@ circle_release(struct context* ctx)
static INLINE void
get_uniform_properties
- (const unsigned iseg,
- unsigned property[SG2D_PROP_TYPES_COUNT__],
+ (const size_t iseg,
+ size_t property[SG2D_PROP_TYPES_COUNT__],
void* context)
{
const struct context* ctx = context;