star-geometry-2d

Cleaning and decorating 2D geometries
git clone git://git.meso-star.fr/star-geometry-2d.git
Log | Files | Refs | README | LICENSE

commit 0b6fe88b6f1c6ad3fd6d91d432761de5ee1eb192
parent 846a0d33a411a68eb0c307cf71a11c688deec9dd
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Wed, 19 Feb 2020 15:01:28 +0100

Add stuff to ease a possible change in API types

Diffstat:
Mcmake/CMakeLists.txt | 3++-
Msrc/sg2_geometry.c | 13+++++++------
Msrc/sg2d.h | 103+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/sg2d_device.c | 16++++++++--------
Msrc/sg2d_geometry.c | 326++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Msrc/sg2d_geometry.h | 95+++++++++++++++++++++++++++++++++----------------------------------------------
Msrc/sg2d_misc.h | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/sgX2d_undefs.h | 6+++---
Msrc/test_sg2d_geometry.c | 24++++++++++++------------
Msrc/test_sg2d_geometry_2.c | 32++++++++++++++++----------------
Msrc/test_sg2d_many_enclosures.c | 14++++++++------
Msrc/test_sg2d_many_segments.c | 10++++++----
Msrc/test_sg2d_some_enclosures.c | 14++++++++------
Msrc/test_sg2d_some_segments.c | 10++++++----
Msrc/test_sg2d_square_behind_square.c | 2+-
Msrc/test_sg2d_square_in_square.c | 2+-
Msrc/test_sg2d_square_on_square.c | 2+-
Msrc/test_sg2d_unspecified_properties.c | 14+++++++-------
Msrc/test_sg2d_utils.h | 46+++++++++++++++++++++++-----------------------
Msrc/test_sg2d_utils2.h | 20++++++++++----------
20 files changed, 449 insertions(+), 359 deletions(-)

diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt @@ -99,7 +99,8 @@ add_library(sg2d SHARED target_link_libraries(sg2d RSys ${MATH_LIB}) set_target_properties(sg2d PROPERTIES - C_STANDARD 99 +# C99 needed in case of printf "PRTF_API" used +# C_STANDARD 99 DEFINE_SYMBOL SG2D_SHARED_BUILD VERSION ${VERSION} SOVERSION ${VERSION_MAJOR}) diff --git a/src/sg2_geometry.c b/src/sg2_geometry.c @@ -183,16 +183,17 @@ error: res_T geometry_enlarge_seg_descriptions (struct sg2d_geometry* geom, - const size_t sz) + const seg_id_t sz) { res_T res = RES_OK; 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); + ASSERT(geom->seg_with_unspecified_sides_count + sz - old_sz <= SEG_MAX__); + ASSERT(geom->seg_with_unspecified_intface_count + sz - old_sz <= SEG_MAX__); + geom->seg_with_unspecified_sides_count += (seg_id_t)(sz - old_sz); + geom->seg_with_unspecified_intface_count += (seg_id_t)(sz - old_sz); exit: return res; @@ -362,7 +363,7 @@ sg2d_geometry_add v_idx = *p_vrtx; } else { /* New vertex */ - ASSERT(nuverts + n_new_uverts < UINT_MAX); + ASSERT(nuverts + n_new_uverts <= UINT_MAX); v_idx = (unsigned)(nuverts + n_new_uverts); ASSERT(v_idx == htable_vrtx_size_get(&geom->unique_vertices_ids)); ERR(darray_vertex_push_back(&geom->unique_vertices, &tmp)); @@ -455,7 +456,7 @@ sg2d_geometry_add } } else { /* New segment */ - ASSERT(nuseg + n_new_utris < UINT_MAX); + ASSERT(nuseg + n_new_utris <= UINT_MAX); unique_id = (unsigned)(nuseg + n_new_utris); tmp.user_id = geom->segment_count_including_duplicates + i; if(callbacks->add_segment) diff --git a/src/sg2d.h b/src/sg2d.h @@ -30,8 +30,8 @@ #define SG2D_API extern IMPORT_SYM #endif -/* Helper macro that asserts if the invocation of the star-geometry function - * `Func' returns an error. One should use this macro on star-geometry +/* Helper macro that asserts if the invocation of the star-geometry-2d function + * `Func' returns an error. One should use this macro on star-geometry-2d * function calls for which no explicit error checking is performed. */ #ifndef NDEBUG #define SG2D(Func) ASSERT(sg2d_ ## Func == RES_OK) @@ -43,7 +43,7 @@ struct logger; struct mem_allocator; -/* Forward declaration of the star-geometry-2D opaque data types. These data +/* Forward declaration of the star-geometry-2d opaque data types. These data * types are ref counted. Once created the caller implicitly owns the created * data, i.e. its reference counter is set to 1. The sg2d_<TYPE>_ref_<get|put> * functions get or release a reference on the data, i.e. they increment or @@ -94,32 +94,34 @@ 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 SIZE_MAX +#define SG2D_UNSPECIFIED_PROPERTY UINT_MAX - /***************************************************************************** - * A type to hold callbacks for sg2d_geometry_add. - ****************************************************************************/ +/***************************************************************************** + * A type to hold callbacks for sg2d_geometry_add. + ****************************************************************************/ struct sg2d_geometry_add_callbacks { /* User function that provides vertices ids for added segments */ void(*get_indices) - (const size_t iseg, size_t ids[SG2D_GEOMETRY_DIMENSION], void* context); + (const unsigned iseg, + unsigned 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 size_t iseg, + (const unsigned iseg, /* It is OK to have side and interface properties sharing the same IDs, * i.e. side and interface IDs both starting from 0 */ - size_t properties[SG2D_PROP_TYPES_COUNT__], + unsigned properties[SG2D_PROP_TYPES_COUNT__], void* context); /* User function that provides coordinates for added vertices */ void(*get_position) - (const size_t ivert, double pos[SG2D_GEOMETRY_DIMENSION], void* context); + (const unsigned 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 size_t unique_id, const size_t iseg, void* context); + (const unsigned unique_id, const unsigned 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 +134,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 size_t unique_id, - const size_t iseg, + (const unsigned unique_id, + const unsigned iseg, const int reversed_segment, - size_t segment_properties[SG2D_PROP_TYPES_COUNT__], - const size_t merged_properties[SG2D_PROP_TYPES_COUNT__], + unsigned segment_properties[SG2D_PROP_TYPES_COUNT__], + const unsigned 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 size_t iseg, void* context, int* abort); + (const unsigned iseg, void* context, int* abort); }; #define SG2D_ADD_CALLBACKS_NULL__ { NULL, NULL, NULL, NULL, NULL, NULL } @@ -154,16 +156,17 @@ BEGIN_DECLS *****************************************************************************/ static INLINE int sg2d_compatible_property - (const size_t p1, - const size_t p2) + (const unsigned p1, + const unsigned p2) { - if(p1 == SG2D_UNSPECIFIED_PROPERTY || p2 == SG2D_UNSPECIFIED_PROPERTY) return 1; + if(p1 == SG2D_UNSPECIFIED_PROPERTY || p2 == SG2D_UNSPECIFIED_PROPERTY) + return 1; return (p1 == p2); } /****************************************************************************** - * star-geometry device. It is an handle toward the star-geometry library. - * It manages the star-geometry resources. + * star-geometry-2d device. It is an handle toward the star-geometry-2d + * library. It manages the star-geometry-2d resources. *****************************************************************************/ SG2D_API res_T sg2d_device_create @@ -181,7 +184,7 @@ sg2d_device_ref_put (struct sg2d_device* dev); /****************************************************************************** - * star-geometry geometry. + * star-geometry-2d geometry. * It stores decorated geometry accumulated through calls to sg2d_geometry_add, * information related to this geometry and its creation process, including * merge conflicts. @@ -197,9 +200,9 @@ sg2d_geometry_create SG2D_API res_T sg2d_geometry_reserve (struct sg2d_geometry* geometry, - const size_t vertices_count, - const size_t segments_count, - const size_t properties_count); + const unsigned vertices_count, + const unsigned segments_count, + const unsigned 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 @@ -227,13 +230,13 @@ sg2d_geometry_reserve * non-SG2D_UNSPECIFIED_PROPERTY property is never overridden. * When deduplicating segments, the first occurence remains (with its * original index in user world). After consistency being computed, a final - * step consists in rewriting SG2D_UNSPECIFIED_PROPERTY properties if the merged - * property is defined. */ + * step consists in rewriting SG2D_UNSPECIFIED_PROPERTY properties if the + * merged property is defined. */ SG2D_API res_T sg2d_geometry_add (struct sg2d_geometry* geometry, - const size_t vertices_count, - const size_t segments_count, + const unsigned vertices_count, + const unsigned segments_count, const struct sg2d_geometry_add_callbacks* callbacks, void* context); /* Can be NULL */ @@ -250,8 +253,8 @@ SG2D_API res_T sg2d_geometry_validate_properties (struct sg2d_geometry* geometry, res_T(*validate) - (const size_t iseg, - const size_t properties[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + const unsigned properties[SG2D_PROP_TYPES_COUNT__], void* context, int* properties_conflict_status), void* context); /* Can be NULL */ @@ -260,40 +263,40 @@ sg2d_geometry_validate_properties SG2D_API res_T sg2d_geometry_get_unique_vertices_count (const struct sg2d_geometry* geometry, - size_t* count); + unsigned* count); /* Get the ivtx_th vertex. */ SG2D_API res_T sg2d_geometry_get_unique_vertex (const struct sg2d_geometry* geometry, - const size_t ivtx, + const unsigned 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, - size_t* count); + unsigned* count); /* Get the number of unique segments. */ SG2D_API res_T sg2d_geometry_get_unique_segments_count (const struct sg2d_geometry* geometry, - size_t* count); + unsigned* 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 size_t iseg, - size_t indices[SG2D_GEOMETRY_DIMENSION]); + const unsigned iseg, + unsigned 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 size_t iseg, - size_t properties[SG2D_PROP_TYPES_COUNT__]); + const unsigned iseg, + unsigned 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 +306,33 @@ sg2d_geometry_get_unique_segment_properties SG2D_API res_T sg2d_geometry_get_unique_segment_user_id (const struct sg2d_geometry* geometry, - const size_t iseg, - size_t* user_id); + const unsigned iseg, + unsigned* 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, - size_t* count); + unsigned* 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, - size_t* count); + unsigned* 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, - size_t* count); + unsigned* 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, - size_t* count); + unsigned* 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 +372,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] size_t <name_prefix>_vertices_count = N1; + * - [static] [const] unsigned <name_prefix>_vertices_count = N1; * - [static] [const] double <name_prefix>_vertices[<N1>] = { .... }; - * - [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>] = { .... }; + * - [static] [const] unsigned <name_prefix>_segments_count = N2; + * - [static] [const] unsigned <name_prefix>_segments[<N2>] = { .... }; + * - [static] [const] unsigned <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_device.c b/src/sg2d_device.c @@ -21,9 +21,9 @@ #include <stdarg.h> - /******************************************************************************* - * Helper functions - ******************************************************************************/ +/****************************************************************************** + * Helper functions + *****************************************************************************/ static void log_msg (struct sg2d_device* dev, @@ -48,9 +48,9 @@ device_release(ref_T* ref) MEM_RM(dev->allocator, dev); } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T sg2d_device_create (struct logger* logger, @@ -75,7 +75,7 @@ sg2d_device_create if(verbose) { /* Do not use helper log functions since dev is not initialised */ CHK(logger_print(log, LOG_ERROR, - "%s: could not allocate the star-geometry device.\n", FUNC_NAME) + "%s: could not allocate the star-geometry-2d device.\n", FUNC_NAME) == RES_OK); } res = RES_MEM_ERR; @@ -113,9 +113,9 @@ sg2d_device_ref_put(struct sg2d_device* dev) return RES_OK; } -/******************************************************************************* +/****************************************************************************** * Local functions - ******************************************************************************/ + *****************************************************************************/ void log_err(struct sg2d_device* dev, const char* msg, ...) { diff --git a/src/sg2d_geometry.c b/src/sg2d_geometry.c @@ -21,9 +21,9 @@ #include <limits.h> - /******************************************************************************* - * Helper functions - ******************************************************************************/ +/****************************************************************************** + * Helper functions + *****************************************************************************/ static void geometry_release(ref_T* ref) { @@ -42,7 +42,7 @@ geometry_release(ref_T* ref) } static FINLINE int /* Return 1 if reversed */ -seg_make_key(struct size2* k, const size_t t[2]) +seg_make_key(struct vrtx_id2* k, const vrtx_id_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)) { - size_t property = SG2D_UNSPECIFIED_PROPERTY; + prop_id_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]) { @@ -85,20 +85,21 @@ dump_seg_property tdefs++; /* Next value */ } } - /* In VTK dumps INT_MAX is used for both unspecified and conflict */ + /* In VTK dumps INT_MAX is used for both unspecified and conflict + * (VTK ascii format doesn't allow a greater value) */ fprintf(stream, "%u\n", (int)MMIN(property, INT_MAX)); } } -/******************************************************************************* +/****************************************************************************** * Local functions - ******************************************************************************/ + *****************************************************************************/ res_T geometry_register_segment (struct sg2d_geometry* geom, const struct segment* segment, - const size_t segment_unique_id, - const size_t set_id, + const seg_id_t segment_unique_id, + const unsigned set_id, const int merge_conflict) { res_T res = RES_OK; @@ -126,10 +127,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 size_t* ids = darray_size_t_cdata_get(&defs[j].set_ids); + const unsigned* ids = darray_uint_cdata_get(&defs[j].set_ids); size_t k; /* Search if property_value already includes set_id */ - FOR_EACH(k, 0, darray_size_t_size_get(&defs[j].set_ids)) { + FOR_EACH(k, 0, darray_uint_size_get(&defs[j].set_ids)) { if(ids[k] == set_id) { /* Same value+set_id was there already */ done = 1; @@ -138,7 +139,7 @@ geometry_register_segment } if(!done) { /* Need to add the set_id for this property_value */ - ERR(darray_size_t_push_back(&defs[j].set_ids, &set_id)); + ERR(darray_uint_push_back(&defs[j].set_ids, &set_id)); done = 1; } break; @@ -150,7 +151,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_size_t_push_back(&new_def->set_ids, &set_id)); + ERR(darray_uint_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 */ @@ -183,15 +184,17 @@ error: res_T geometry_enlarge_seg_descriptions (struct sg2d_geometry* geom, - const size_t sz) + const seg_id_t sz) { res_T res = RES_OK; size_t old_sz = darray_seg_descriptions_size_get(&geom->seg_descriptions); if(sz <= old_sz) return RES_OK; ERR(darray_seg_descriptions_resize(&geom->seg_descriptions, sz)); - geom->seg_with_unspecified_sides_count += (sz - old_sz); - geom->seg_with_unspecified_intface_count += (sz - old_sz); + ASSERT(geom->seg_with_unspecified_sides_count + sz - old_sz <= SEG_MAX__); + ASSERT(geom->seg_with_unspecified_intface_count + sz - old_sz <= SEG_MAX__); + geom->seg_with_unspecified_sides_count += (seg_id_t)(sz - old_sz); + geom->seg_with_unspecified_intface_count += (seg_id_t)(sz - old_sz); exit: return res; @@ -230,16 +233,16 @@ dump_partition dump = seg_descriptions[i].properties_conflict; } if(!dump) continue; - fprintf(stream, "l %zu %zu\n", + fprintf(stream, "l "PRTF_SEG" "PRTF_SEG"\n", /* OBJ indexing starts at 1 */ 1 + segments[i].vertex_ids[0], 1 + segments[i].vertex_ids[1]); } } -/******************************************************************************* +/****************************************************************************** * Exported functions - ******************************************************************************/ + *****************************************************************************/ res_T sg2d_geometry_create (struct sg2d_device* dev, @@ -292,9 +295,9 @@ error: res_T sg2d_geometry_reserve (struct sg2d_geometry* geom, - const size_t vertices_count, - const size_t segments_count, - const size_t properties_count) + const vrtx_id_t vertices_count, + const seg_id_t segments_count, + const prop_id_t properties_count) { res_T res = RES_OK; if(!geom) return RES_BAD_ARG; @@ -315,19 +318,26 @@ error: res_T sg2d_geometry_add (struct sg2d_geometry* geom, - const size_t nverts, - const size_t nsegs, + const vrtx_id_t nverts, + const seg_id_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; - size_t i, n_new_uverts = 0, n_new_utris = 0; + size_t nusegs, nuverts; + vrtx_id_t nv, n_new_uverts = 0; + seg_id_t ns, n_new_usegs = 0; struct segment* seg; /* Tmp table of IDs to record unique IDs of the currently added vertices */ - struct darray_size_t unique_vertice_ids; + struct darray_vertice_ids unique_vertice_ids; int unique_vertice_ids_initialized = 0; + get_indices_t get_ind; + get_properties_t get_prop; + get_position_t get_pos; + add_segment_t add_seg; + merge_segment_t mrg_seg; + degenerated_segment_t dege_seg; if(!geom || !callbacks || !callbacks->get_indices || !callbacks->get_position) { @@ -335,53 +345,60 @@ sg2d_geometry_add goto error; } + get_ind = callbacks->get_indices; + get_prop = callbacks->get_properties; + get_pos = callbacks->get_position; + add_seg = callbacks->add_segment; + mrg_seg = callbacks->merge_segment; + dege_seg = callbacks->degenerated_segment; alloc = geom->dev->allocator; nuverts = darray_vertex_size_get(&geom->unique_vertices); - nuseg = darray_segment_size_get(&geom->unique_segments); + nusegs = darray_segment_size_get(&geom->unique_segments); /* Make room for new geometry; suppose no more duplicates */ - darray_size_t_init(alloc, &unique_vertice_ids); + darray_vertice_ids_init(alloc, &unique_vertice_ids); unique_vertice_ids_initialized = 1; - ERR(darray_size_t_reserve(&unique_vertice_ids, nverts)); + ERR(darray_vertice_ids_reserve(&unique_vertice_ids, nverts)); ERR(darray_vertex_reserve(&geom->unique_vertices, nuverts + nverts)); - ERR(darray_segment_reserve(&geom->unique_segments, nuseg + nsegs)); + ERR(darray_segment_reserve(&geom->unique_segments, nusegs + nsegs)); ERR(htable_vrtx_reserve(&geom->unique_vertices_ids, nuverts + nverts)); - ERR(htable_seg_reserve(&geom->unique_segments_ids, nuseg + nsegs)); - ASSERT(nuseg == darray_seg_descriptions_size_get(&geom->seg_descriptions)); - ERR(darray_seg_descriptions_reserve(&geom->seg_descriptions, nuseg + nsegs)); + ERR(htable_seg_reserve(&geom->unique_segments_ids, nusegs + nsegs)); + ASSERT(nusegs == darray_seg_descriptions_size_get(&geom->seg_descriptions)); + ERR(darray_seg_descriptions_reserve(&geom->seg_descriptions, nusegs + nsegs)); /* Get vertices and deduplicate */ - FOR_EACH(i, 0, nverts) { - size_t* p_vrtx; + FOR_EACH(nv, 0, nverts) { + vrtx_id_t* p_vrtx; struct vertex tmp; - size_t v_idx; - callbacks->get_position(i, tmp.coord, ctx); + vrtx_id_t v_idx; + get_pos(nv, tmp.coord, ctx); p_vrtx = htable_vrtx_find(&geom->unique_vertices_ids, &tmp); if(p_vrtx) { /* Duplicate vertex */ v_idx = *p_vrtx; } else { /* New vertex */ - v_idx = nuverts + n_new_uverts; + ASSERT(nuverts + n_new_uverts <= VRTX_MAX__); + v_idx = (vrtx_id_t)(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_size_t_push_back(&unique_vertice_ids, &v_idx)); + /* Keep the unique ID for vertex nv */ + ERR(darray_vertice_ids_push_back(&unique_vertice_ids, &v_idx)); } /* Get segments and deduplicate */ seg = darray_segment_data_get(&geom->unique_segments); - FOR_EACH(i, 0, nsegs) { + FOR_EACH(ns, 0, nsegs) { int j, reversed; - struct size2 seg_key; + struct vrtx_id2 seg_key; struct segment tmp = SEG_UNDEF__; - size_t* p_seg; + seg_id_t* p_seg; struct seg_descriptions* seg_descriptions = NULL; - size_t unique_id; + seg_id_t unique_id; - callbacks->get_indices(i, tmp.vertex_ids, ctx); + get_ind(ns, tmp.vertex_ids, ctx); FOR_EACH(j, 0, 2) { if(tmp.vertex_ids[j] >= nverts) { res = RES_BAD_ARG; @@ -389,16 +406,16 @@ sg2d_geometry_add } /* Replace the vertex ID by its the unique ID */ tmp.vertex_ids[j] - = darray_size_t_cdata_get(&unique_vertice_ids)[tmp.vertex_ids[j]]; + = darray_vertice_ids_cdata_get(&unique_vertice_ids)[tmp.vertex_ids[j]]; } if(tmp.vertex_ids[0] == tmp.vertex_ids[1]) { int abort = 0; - if(callbacks->degenerated_segment) { + if(dege_seg) { /* Let the client app rule. */ - ERR(callbacks->degenerated_segment(i, ctx, &abort)); + ERR(dege_seg(ns, ctx, &abort)); } else { - log_warn(geom->dev, "%s: segment %zu is degenerated.\n", - FUNC_NAME, i); + log_warn(geom->dev, "%s: segment "PRTF_SEG" is degenerated.\n", + FUNC_NAME, ns); } if(abort) { res = RES_BAD_ARG; @@ -407,14 +424,13 @@ sg2d_geometry_add else continue; } /* Get properties */ - if(callbacks->get_properties) - callbacks->get_properties(i, tmp.properties, ctx); + if(get_prop) get_prop(ns, tmp.properties, ctx); /* Find duplicate segments */ reversed = seg_make_key(&seg_key, tmp.vertex_ids); p_seg = htable_seg_find(&geom->unique_segments_ids, &seg_key); if(p_seg) { /* Duplicate segment. Need to check duplicate validity */ - struct size2 useg_key; + struct vrtx_id2 useg_key; int ureversed = seg_make_key(&useg_key, seg[*p_seg].vertex_ids); int same = (reversed == ureversed); int already_conflict; @@ -424,23 +440,23 @@ sg2d_geometry_add seg_descriptions = darray_seg_descriptions_data_get(&geom->seg_descriptions); if(!same) - SWAP(size_t, tmp.properties[SG2D_FRONT], tmp.properties[SG2D_BACK]); - already_conflict = seg_descriptions[i].merge_conflict; - if(callbacks->merge_segment) { + SWAP(prop_id_t, tmp.properties[SG2D_FRONT], tmp.properties[SG2D_BACK]); + already_conflict = seg_descriptions[ns].merge_conflict; + if(mrg_seg) { /* Let the client app rule. */ - ERR(callbacks->merge_segment(*p_seg, i, !same, seg[*p_seg].properties, - tmp.properties, ctx, &seg_descriptions[i].merge_conflict)); + ERR(mrg_seg(unique_id, ns, !same, seg[*p_seg].properties, + tmp.properties, ctx, &seg_descriptions[ns].merge_conflict)); } else { FOR_EACH(j, 0, SG2D_PROP_TYPES_COUNT__) { if(!sg2d_compatible_property(seg[*p_seg].properties[j], tmp.properties[j])) { - seg_descriptions[i].merge_conflict = 1; + seg_descriptions[ns].merge_conflict = 1; break; } } } - if(seg_descriptions[i].merge_conflict && !already_conflict) + if(seg_descriptions[ns].merge_conflict && !already_conflict) geom->merge_conflict_count++; /* Replace SG2D_UNSPECIFIED_PROPERTY properties */ FOR_EACH(j, 0, SG2D_PROP_TYPES_COUNT__) { @@ -453,10 +469,11 @@ sg2d_geometry_add } } else { /* New segment */ - 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)); + ASSERT(nusegs + n_new_usegs <= SEG_MAX__); + unique_id = (seg_id_t)(nusegs + n_new_usegs); + tmp.user_id = geom->segment_count_including_duplicates + ns; + if(add_seg) ERR(add_seg(unique_id, ns, ctx)); + ERR(geometry_enlarge_seg_descriptions(geom, 1 + unique_id)); seg_descriptions = darray_seg_descriptions_data_get(&geom->seg_descriptions); @@ -468,17 +485,17 @@ sg2d_geometry_add } ASSERT(unique_id == htable_seg_size_get(&geom->unique_segments_ids)); ERR(htable_seg_set(&geom->unique_segments_ids, &seg_key, &unique_id)); - n_new_utris++; + n_new_usegs++; } ERR(geometry_register_segment(geom, &tmp, unique_id, geom->set_id, - seg_descriptions[i].properties_conflict)); - if(seg_descriptions[i].properties_conflict) + seg_descriptions[ns].properties_conflict)); + if(seg_descriptions[ns].properties_conflict) geom->merge_conflict_count++; } ASSERT(nuverts + n_new_uverts == htable_vrtx_size_get(&geom->unique_vertices_ids)); - ASSERT(nuseg + n_new_utris + ASSERT(nusegs + n_new_usegs == htable_seg_size_get(&geom->unique_segments_ids)); exit: if(geom) { @@ -486,7 +503,7 @@ exit: geom->segment_count_including_duplicates += nsegs; } if(unique_vertice_ids_initialized) - darray_size_t_release(&unique_vertice_ids); + darray_vertice_ids_release(&unique_vertice_ids); return res; error: goto exit; @@ -495,10 +512,11 @@ error: res_T sg2d_geometry_validate_properties (struct sg2d_geometry* geom, - res_T(*validate)(const size_t, const size_t*, void*, int*), + res_T(*validate)(const seg_id_t, const prop_id_t*, void*, int*), void* ctx) { - size_t i, sz; + size_t sz__; + seg_id_t i, sz; struct seg_descriptions* seg_descriptions; res_T res = RES_OK; @@ -507,13 +525,15 @@ sg2d_geometry_validate_properties goto error; } - sz= darray_seg_descriptions_size_get(&geom->seg_descriptions); + sz__ = darray_seg_descriptions_size_get(&geom->seg_descriptions); + ASSERT(sz__ <= SEG_MAX__); + sz = (seg_id_t)sz__; seg_descriptions = darray_seg_descriptions_data_get(&geom->seg_descriptions); geom->properties_conflict_count = 0; /* Reset count */ FOR_EACH(i, 0, sz) { - size_t p, j; - size_t props[SG2D_PROP_TYPES_COUNT__]; + int p; + prop_id_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) { @@ -522,6 +542,7 @@ sg2d_geometry_validate_properties } /* Get properties for non-conflict segments */ FOR_EACH(p, 0, SG2D_PROP_TYPES_COUNT__) { + size_t j; const struct definition* defs = darray_definition_cdata_get(segd->defs + p); props[p] = SG2D_UNSPECIFIED_PROPERTY; FOR_EACH(j, 0, darray_definition_size_get(segd->defs + p)) { @@ -546,14 +567,17 @@ error: res_T sg2d_geometry_get_unique_vertices_count (const struct sg2d_geometry* geom, - size_t* count) + vrtx_id_t* count) { res_T res = RES_OK; + size_t sz; if(!geom || !count) { res = RES_BAD_ARG; goto error; } - *count = darray_vertex_size_get(&geom->unique_vertices); + sz = darray_vertex_size_get(&geom->unique_vertices); + ASSERT(sz <= VRTX_MAX__); + *count = (vrtx_id_t)sz; exit: return res; error: @@ -563,8 +587,8 @@ error: res_T sg2d_geometry_get_unique_vertex (const struct sg2d_geometry* geom, - const size_t ivtx, - double coord[2]) + const vrtx_id_t ivtx, + double coord[SG2D_GEOMETRY_DIMENSION]) { res_T res = RES_OK; const struct vertex* vertices; @@ -585,10 +609,10 @@ error: res_T sg2d_geometry_get_added_segments_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; - if (!geom || !count) { + if(!geom || !count) { res = RES_BAD_ARG; goto error; } @@ -602,14 +626,17 @@ error: res_T sg2d_geometry_get_unique_segments_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; + size_t sz; if(!geom || !count) { res = RES_BAD_ARG; goto error; } - *count = darray_segment_size_get(&geom->unique_segments); + sz = darray_segment_size_get(&geom->unique_segments); + ASSERT(sz <= SEG_MAX__); + *count = (seg_id_t)sz; exit: return res; error: @@ -619,8 +646,8 @@ error: res_T sg2d_geometry_get_unique_segment_vertices (const struct sg2d_geometry* geom, - const size_t iseg, - size_t indices[2]) + const seg_id_t iseg, + vrtx_id_t indices[SG2D_GEOMETRY_DIMENSION]) { res_T res = RES_OK; const struct segment* segments; @@ -632,7 +659,8 @@ sg2d_geometry_get_unique_segment_vertices goto error; } segments = darray_segment_cdata_get(&geom->unique_segments); - FOR_EACH(i, 0, 2) indices[i] = segments[iseg].vertex_ids[i]; + FOR_EACH(i, 0, SG2D_GEOMETRY_DIMENSION) + indices[i] = segments[iseg].vertex_ids[i]; exit: return res; error: @@ -642,8 +670,8 @@ error: res_T sg2d_geometry_get_unique_segment_properties (const struct sg2d_geometry* geom, - const size_t iseg, - size_t properties[SG2D_PROP_TYPES_COUNT__]) + const seg_id_t iseg, + prop_id_t properties[SG2D_PROP_TYPES_COUNT__]) { res_T res = RES_OK; const struct segment* segments; @@ -666,8 +694,8 @@ error: res_T sg2d_geometry_get_unique_segment_user_id (const struct sg2d_geometry* geom, - const size_t iseg, - size_t* user_id) + const seg_id_t iseg, + seg_id_t* user_id) { res_T res = RES_OK; const struct segment* segments; @@ -688,7 +716,7 @@ error: res_T sg2d_geometry_get_unique_segments_with_unspecified_side_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; if(!geom || !count) { @@ -705,7 +733,7 @@ error: res_T sg2d_geometry_get_unique_segments_with_unspecified_interface_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; if(!geom || !count) { @@ -722,7 +750,7 @@ error: res_T sg2d_geometry_get_unique_segments_with_merge_conflict_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; if(!geom || !count) { @@ -739,7 +767,7 @@ error: res_T sg2d_geometry_get_unique_segments_with_properties_conflict_count (const struct sg2d_geometry* geom, - size_t* count) + seg_id_t* count) { res_T res = RES_OK; if(!geom || !count) { @@ -761,7 +789,7 @@ sg2d_geometry_dump_as_obj { res_T res = RES_OK; const struct vertex* vertices; - size_t vsz, tsz, i; + size_t vsz, ssz, i; if(!geom || !stream || !flags || !geom->segment_count_including_duplicates) { @@ -773,17 +801,19 @@ sg2d_geometry_dump_as_obj goto error; } /* Headers */ - fprintf(stream, "# Dump of star-geometry-2D\n"); + fprintf(stream, "# Dump of star-geometry-2d\n"); fprintf(stream, "# Geometry counts:\n"); vsz = darray_vertex_size_get(&geom->unique_vertices); - fprintf(stream, "# . %zu vertices\n", vsz); - tsz = darray_segment_size_get(&geom->unique_segments); - fprintf(stream, "# . %zu segments\n", tsz); + ASSERT(vsz <= VRTX_MAX__); + fprintf(stream, "# . "PRTF_VRTX" vertices\n", (vrtx_id_t)vsz); + ssz = darray_segment_size_get(&geom->unique_segments); + ASSERT(ssz <= SEG_MAX__); + fprintf(stream, "# . "PRTF_SEG" segments\n", (seg_id_t)ssz); fprintf(stream, - "# . %zu segments flagged with a merge conflict\n", + "# . "PRTF_SEG" segments flagged with a merge conflict\n", geom->merge_conflict_count); fprintf(stream, - "# . %zu segments flagged with a property conflict\n", + "# . "PRTF_SEG" segments flagged with a property conflict\n", geom->merge_conflict_count); /* Dump vertices */ @@ -792,9 +822,12 @@ sg2d_geometry_dump_as_obj fprintf(stream, "v %g %g 0\n", SPLIT2(vertices[i].coord)); /* Dump segments by groups */ - dump_partition(geom, stream, "Valid_segments", SG2D_OBJ_DUMP_VALID_PRIMITIVE); - dump_partition(geom, stream, "Merge_conflicts", SG2D_OBJ_DUMP_MERGE_CONFLICTS); - dump_partition(geom, stream, "Property_conflicts", SG2D_OBJ_DUMP_PROPERTY_CONFLICTS); + dump_partition(geom, stream, + "Valid_segments", SG2D_OBJ_DUMP_VALID_PRIMITIVE); + dump_partition(geom, stream, + "Merge_conflicts", SG2D_OBJ_DUMP_MERGE_CONFLICTS); + dump_partition(geom, stream, + "Property_conflicts", SG2D_OBJ_DUMP_PROPERTY_CONFLICTS); exit: return res; @@ -811,7 +844,7 @@ sg2d_geometry_dump_as_vtk const struct vertex* vertices; const struct segment* segments; const struct seg_descriptions* descriptions; - size_t vsz, tsz, i; + size_t vsz, ssz, i; if(!geom || !stream || !geom->segment_count_including_duplicates) { if(geom && !geom->segment_count_including_duplicates) log_err(geom->dev, @@ -822,26 +855,30 @@ sg2d_geometry_dump_as_vtk } /* Headers */ fprintf(stream, "# vtk DataFile Version 3.0\n"); - fprintf(stream, "Dump of star-geometry-2D geometry\n"); + fprintf(stream, "Dump of star-geometry-2d geometry\n"); fprintf(stream, "ASCII\n"); fprintf(stream, "DATASET POLYDATA\n"); /* Dump vertices */ vsz = darray_vertex_size_get(&geom->unique_vertices); - fprintf(stream, "POINTS %zu double\n", vsz); + ASSERT(vsz <= VRTX_MAX__); + fprintf(stream, "POINTS "PRTF_VRTX" double\n", (vrtx_id_t)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); - fprintf(stream, "LINES %zu %zu\n", tsz, 3 * tsz); + ssz = darray_segment_size_get(&geom->unique_segments); + ASSERT(3 * ssz <= SEG_MAX__); + fprintf(stream, "LINES "PRTF_SEG" "PRTF_SEG"\n", + (seg_id_t)ssz, (seg_id_t)(3 * ssz)); segments = darray_segment_cdata_get(&geom->unique_segments); - FOR_EACH(i, 0, tsz) - fprintf(stream, "2 %zu %zu\n", SPLIT2(segments[i].vertex_ids)); + FOR_EACH(i, 0, ssz) + fprintf(stream, "2 "PRTF_VRTX" "PRTF_VRTX"\n", + SPLIT2(segments[i].vertex_ids)); /* Start segments properties */ - fprintf(stream, "CELL_DATA %zu\n", tsz); + fprintf(stream, "CELL_DATA "PRTF_SEG"\n", (seg_id_t)ssz); descriptions = darray_seg_descriptions_cdata_get(&geom->seg_descriptions); /* Dump front medium */ @@ -862,32 +899,31 @@ sg2d_geometry_dump_as_vtk /* Dump user_id */ fprintf(stream, "SCALARS User_ID int\n"); fprintf(stream, "LOOKUP_TABLE default\n"); - FOR_EACH(i, 0, tsz) - fprintf(stream, "%zu\n", segments[i].user_id); + FOR_EACH(i, 0, ssz) fprintf(stream, PRTF_SEG"\n", segments[i].user_id); /* Dump merge conflict status */ fprintf(stream, "SCALARS Merge_conflict int\n"); fprintf(stream, "LOOKUP_TABLE default\n"); - FOR_EACH(i, 0, tsz) - fprintf(stream, "%d\n", descriptions[i].merge_conflict); + FOR_EACH(i, 0, ssz) + fprintf(stream, PRTF_SEG"\n", descriptions[i].merge_conflict); /* Dump property conflict status */ fprintf(stream, "SCALARS Property_conflict int\n"); fprintf(stream, "LOOKUP_TABLE default\n"); - FOR_EACH(i, 0, tsz) - fprintf(stream, "%d\n", descriptions[i].properties_conflict); + FOR_EACH(i, 0, ssz) + fprintf(stream, PRTF_SEG"\n", descriptions[i].properties_conflict); /* Dump rank of the sg2d_geometry_add that created the segment */ fprintf(stream, "SCALARS Created_at_sg2d_geometry_add int\n"); fprintf(stream, "LOOKUP_TABLE default\n"); - FOR_EACH(i, 0, tsz) { + FOR_EACH(i, 0, ssz) { const struct definition* tdefs; - const size_t* ranks; + const unsigned* 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_size_t_cdata_get(&tdefs[0].set_ids); - fprintf(stream, "%zu\n", ranks[0]); + ranks = darray_uint_cdata_get(&tdefs[0].set_ids); + fprintf(stream, "%u\n", ranks[0]); } exit: @@ -907,7 +943,7 @@ sg2d_geometry_dump_as_c_code const struct vertex* vertices; const struct segment* segments; const char* qualifiers; - size_t vsz, tsz, i; + size_t vsz, ssz, i; if(!geom || !stream || geom->merge_conflict_count || geom->properties_conflict_count @@ -929,13 +965,15 @@ sg2d_geometry_dump_as_c_code if(!name_prefix) name_prefix = ""; /* Headers */ if(name_prefix && name_prefix[0] != '\0') - fprintf(stream, "/* Dump of star-geometry-2D '%s'. */\n", name_prefix); + fprintf(stream, "/* Dump of star-geometry-2d '%s'. */\n", name_prefix); else - fprintf(stream, "/* Dump of star-geometry-2D. */\n"); + fprintf(stream, "/* Dump of star-geometry-2d. */\n"); vsz = darray_vertex_size_get(&geom->unique_vertices); - tsz = darray_segment_size_get(&geom->unique_segments); + ASSERT(2 * vsz <= VRTX_MAX__); + ssz = darray_segment_size_get(&geom->unique_segments); + ASSERT(2 * ssz <= SEG_MAX__); - if(vsz == 0 || tsz == 0) { + if(vsz == 0 || ssz == 0) { log_err(geom->dev, "%s: no geometry to dump\n", FUNC_NAME); @@ -952,14 +990,14 @@ sg2d_geometry_dump_as_c_code else qualifiers = ""; /* Dump vertices */ - fprintf(stream, "%ssize_t %s_vertices_count = %zu;\n", - qualifiers, name_prefix, vsz); + fprintf(stream, "%s"VRTX_TYPE_NAME" %s_vertices_count = "PRTF_VRTX";\n", + qualifiers, name_prefix, (vrtx_id_t)vsz); vertices = darray_vertex_cdata_get(&geom->unique_vertices); fprintf(stream, - "%sdouble %s_vertices[%zu] =\n" + "%sdouble %s_vertices["PRTF_VRTX"] =\n" "{\n", - qualifiers, name_prefix, 2 * vsz); + qualifiers, name_prefix, (vrtx_id_t)(2 * vsz)); FOR_EACH(i, 0, vsz - 1) fprintf(stream, " %g, %g,\n", SPLIT2(vertices[i].coord)); @@ -969,35 +1007,35 @@ sg2d_geometry_dump_as_c_code "};\n"); /* Dump segments */ - fprintf(stream, "%ssize_t %s_segments_count = %zu;\n", - qualifiers, name_prefix, tsz); + fprintf(stream, "%s"SEG_TYPE_NAME" %s_segments_count = "PRTF_SEG";\n", + qualifiers, name_prefix, (seg_id_t)ssz); segments = darray_segment_cdata_get(&geom->unique_segments); fprintf(stream, - "%ssize_t %s_segments[%zu] =\n" + "%s"SEG_TYPE_NAME" %s_segments["PRTF_SEG"] =\n" "{\n", - qualifiers, name_prefix, 2 * tsz); - FOR_EACH(i, 0, tsz - 1) + qualifiers, name_prefix, (seg_id_t)(2 * ssz)); + FOR_EACH(i, 0, ssz - 1) fprintf(stream, - " %zu, %zu,\n", SPLIT2(segments[i].vertex_ids)); + " "PRTF_VRTX", "PRTF_VRTX",\n", SPLIT2(segments[i].vertex_ids)); fprintf(stream, - " %zu, %zu\n", SPLIT2(segments[tsz - 1].vertex_ids)); + " "PRTF_VRTX", "PRTF_VRTX"\n", SPLIT2(segments[ssz - 1].vertex_ids)); fprintf(stream, "};\n"); /* Dump properties */ fprintf(stream, - "%ssize_t %s_properties[%zu] =\n" + "%s"PROP_TYPE_NAME" %s_properties["PRTF_PROP"] =\n" "{\n", - qualifiers, name_prefix, SG2D_PROP_TYPES_COUNT__ * tsz); - FOR_EACH(i, 0, tsz) { + qualifiers, name_prefix, (prop_id_t)(SG2D_PROP_TYPES_COUNT__ * ssz)); + FOR_EACH(i, 0, ssz) { 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," %zu", segments[i].properties[p]); - if(i < tsz-1 || p < 2) fprintf(stream, ","); + else fprintf(stream," "PRTF_PROP, segments[i].properties[p]); + if(i < ssz-1 || p < 2) fprintf(stream, ","); if(p == 2) fprintf(stream, "\n"); } } diff --git a/src/sg2d_geometry.h b/src/sg2d_geometry.h @@ -21,20 +21,20 @@ #include <rsys/ref_count.h> #include <rsys/dynamic_array.h> -#include <rsys/dynamic_array_size_t.h> +#include <rsys/dynamic_array_uint.h> #include <rsys/hash_table.h> /* Forward declaration of external opaque data types */ -/******************************************************************************* +/****************************************************************************** * A type to store segments - ******************************************************************************/ + *****************************************************************************/ struct segment { - size_t vertex_ids[2]; + vrtx_id_t vertex_ids[2]; /* FRONT/BACK/INTERFACE property */ - size_t properties[SG2D_PROP_TYPES_COUNT__]; + prop_id_t properties[SG2D_PROP_TYPES_COUNT__]; /* ID of the segment in user world, i.e. without deduplication */ - size_t user_id; + seg_id_t user_id; }; #define SEG_UNDEF__ {\ { SG2D_UNSPECIFIED_PROPERTY, SG2D_UNSPECIFIED_PROPERTY },\ @@ -45,9 +45,9 @@ struct segment { #define DARRAY_DATA struct segment #include <rsys/dynamic_array.h> -/******************************************************************************* +/****************************************************************************** * A type to store vertices - ******************************************************************************/ + *****************************************************************************/ struct vertex { double coord[2]; }; @@ -55,27 +55,27 @@ struct vertex { #define DARRAY_DATA struct vertex #include <rsys/dynamic_array.h> -/******************************************************************************* +/****************************************************************************** * A type to map segment vertices to IDs in unique_segments - ******************************************************************************/ -struct size2 { size_t x[2]; }; + *****************************************************************************/ +struct vrtx_id2 { vrtx_id_t x[2]; }; static FINLINE int -seg_key_eq(const struct size2* k1, const struct size2* k2) +seg_key_eq(const struct vrtx_id2* k1, const struct vrtx_id2* 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 size2 -#define HTABLE_DATA size_t +#define HTABLE_KEY struct vrtx_id2 +#define HTABLE_DATA seg_id_t #define HTABLE_KEY_FUNCTOR_EQ seg_key_eq #include <rsys/hash_table.h> - /******************************************************************************* - * A type to map vertex coordinates to IDs in unique_vertices - ******************************************************************************/ +/****************************************************************************** + * A type to map vertex coordinates to IDs in unique_vertices + *****************************************************************************/ static FINLINE int vrtx_eq(const struct vertex* v1, const struct vertex* v2) { @@ -87,21 +87,21 @@ vrtx_eq(const struct vertex* v1, const struct vertex* v2) #define HTABLE_NAME vrtx #define HTABLE_KEY struct vertex -#define HTABLE_DATA size_t +#define HTABLE_DATA vrtx_id_t #define HTABLE_KEY_FUNCTOR_EQ vrtx_eq #include <rsys/hash_table.h> -/******************************************************************************* +/****************************************************************************** * Types to record sources and values of segment descriptions. - ******************************************************************************/ + *****************************************************************************/ /* A type to store a value and the files defining this value * (usualy a single file) */ struct definition { /* The value */ - size_t property_value; + prop_id_t property_value; /* The IDs of the geometry sets that defined the value */ - struct darray_size_t set_ids; + struct darray_uint set_ids; }; static FINLINE void @@ -111,7 +111,7 @@ init_definition { ASSERT(alloc && data); data->property_value = SG2D_UNSPECIFIED_PROPERTY; - darray_size_t_init(alloc, &data->set_ids); + darray_uint_init(alloc, &data->set_ids); } static INLINE res_T @@ -122,7 +122,7 @@ copy_definition res_T res = RES_OK; ASSERT(dst && src); dst->property_value = src->property_value; - ERR(darray_size_t_copy(&dst->set_ids, &src->set_ids)); + ERR(darray_uint_copy(&dst->set_ids, &src->set_ids)); exit: return res; error: @@ -134,7 +134,7 @@ release_definition (struct definition* data) { ASSERT(data); - darray_size_t_release(&data->set_ids); + darray_uint_release(&data->set_ids); } #define DARRAY_NAME definition @@ -208,26 +208,9 @@ release_seg_descriptions #define DARRAY_FUNCTOR_RELEASE release_seg_descriptions #include <rsys/dynamic_array.h> -/******************************************************************************* - * A type to store interface IDs, as star-enclosures doesn't manage them. - ******************************************************************************/ -static FINLINE void -init_seg_intfaceid - (struct mem_allocator* alloc, - size_t* data) -{ - ASSERT(data); (void)alloc; - *data = SG2D_UNSPECIFIED_PROPERTY; -} - -#define DARRAY_NAME intface_id -#define DARRAY_DATA size_t -#define DARRAY_FUNCTOR_INIT init_seg_intfaceid -#include <rsys/dynamic_array.h> - -/******************************************************************************* +/****************************************************************************** * Types to store geometry amid sg2d_geometry_add calls. - ******************************************************************************/ + *****************************************************************************/ struct sg2d_geometry { /* Record unique (i.e. deduplicated) segments */ struct darray_segment unique_segments; @@ -243,34 +226,34 @@ struct sg2d_geometry { struct darray_seg_descriptions seg_descriptions; /* Counts */ - 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; + unsigned set_id; + seg_id_t segment_count_including_duplicates; + side_id_t sides_with_defined_medium_count; + seg_id_t seg_with_unspecified_sides_count; + seg_id_t seg_with_unspecified_intface_count; + seg_id_t merge_conflict_count; + seg_id_t properties_conflict_count; struct sg2d_device* dev; ref_T ref; }; -/******************************************************************************* +/****************************************************************************** * Local functions - ******************************************************************************/ + *****************************************************************************/ extern LOCAL_SYM res_T geometry_register_segment (struct sg2d_geometry* geometry, const struct segment* segment, - const size_t segment_unique_id, - const size_t set_id, + const seg_id_t segment_unique_id, + const unsigned set_id, const int merge_conflict); /* Add new undefined segment descriptions to a geometry */ extern LOCAL_SYM res_T geometry_enlarge_seg_descriptions (struct sg2d_geometry* geom, - const size_t sz); + const seg_id_t sz); #endif /* SG2D_GEOMETRY_H__ */ diff --git a/src/sg2d_misc.h b/src/sg2d_misc.h @@ -18,4 +18,60 @@ #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; +#include <rsys/dynamic_array.h> + +#define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; + +/* The following types must be defined accordingly with the types + * used in sg2d.h */ + +/* Seg IDs use the same type than Side IDs */ +typedef unsigned seg_id_t; +/* SEG_MAX__ is limited to half the max of the base type to allow to count +* sides */ +#define SEG_MAX__ (UINT_MAX/2) +#define SEG_NULL__ UINT_MAX +#define PRTF_SEG "%u" +#define SEG_TYPE_NAME "unsigned" + +/* Side IDs type use the same base type than Seg IDs */ +typedef seg_id_t side_id_t; +#define SIDE_MAX__ (2*SEG_MAX__) +#define SIDE_NULL__ SEG_NULL__ + +/* Vertex IDs type */ +typedef unsigned vrtx_id_t; +#define VRTX_MAX__ (UINT_MAX-1) +#define VRTX_NULL__ UINT_MAX +#define PRTF_VRTX "%u" +#define VRTX_TYPE_NAME "unsigned" + +#define DARRAY_NAME vertice_ids +#define DARRAY_DATA vrtx_id_t +#include <rsys/dynamic_array.h> + +/* Property IDs type. + * Cannot be larger than unsigned, as the API uses it. */ +typedef unsigned prop_id_t; +#define PROP_MAX__ (UINT_MAX-1) /* MAX is for unspecified medium */ +#define PROP_NULL__ UINT_MAX +#define PRTF_PROP "%u" +#define PROP_TYPE_NAME "unsigned" + +#if (PROP_MAX__+1 != SG2D_UNSPECIFIED_PROPERTY) +#error "Inconsistant values" +#endif + +/* Types of the callbacks. + * Provided callbacks are cast into these types to avoid arguments cast + * and to check types coherency */ +typedef void(*get_indices_t) (const seg_id_t, prop_id_t*, void*); +typedef void(*get_properties_t) (const seg_id_t, prop_id_t*, void*); +typedef void(*get_position_t) (const vrtx_id_t, double*, void*); +typedef res_T(*add_segment_t) (const seg_id_t, const seg_id_t, void*); +typedef res_T(*merge_segment_t) + (const seg_id_t, const seg_id_t, const int, prop_id_t*, const prop_id_t*, + void*, int*); +typedef res_T(*degenerated_segment_t) (const seg_id_t, void*, int*); + #endif /* SG2D_MISC_H__ */ diff --git a/src/sgX2d_undefs.h b/src/sgX2d_undefs.h @@ -18,9 +18,9 @@ #endif /* Star-geometry-XD macros generic to the SGXD_DIM */ -#undef SENCXD -#undef sencXd -#undef SENCXD_ +#undef SGXD +#undef sgXd +#undef SGXD_ /* Function names that require additional dedicated macros */ #undef sgXd_geometry_get_added_primitives_count diff --git a/src/test_sg2d_geometry.c b/src/test_sg2d_geometry.c @@ -20,8 +20,8 @@ static res_T validate - (const size_t iseg, - const size_t properties[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + const unsigned properties[SG2D_PROP_TYPES_COUNT__], void* context, int* properties_conflict) { @@ -32,11 +32,11 @@ validate static res_T merge_seg - (const size_t user_id, - const size_t iseg, + (const unsigned user_id, + const unsigned iseg, const int reversed_segment, - size_t segment_properties[SG2D_PROP_TYPES_COUNT__], - const size_t merged_properties[SG2D_PROP_TYPES_COUNT__], + unsigned segment_properties[SG2D_PROP_TYPES_COUNT__], + const unsigned merged_properties[SG2D_PROP_TYPES_COUNT__], void* context, int* merge_conflict) { @@ -49,7 +49,7 @@ merge_seg static res_T degenerated_segment - (const size_t iseg, + (const unsigned 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]; - size_t indices[2]; - size_t degenerated[2] = { 0, 0 }; - size_t properties[SG2D_PROP_TYPES_COUNT__]; + unsigned indices[2]; + unsigned degenerated[2] = { 0, 0 }; + unsigned properties[SG2D_PROP_TYPES_COUNT__]; struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__; - size_t user_id; - size_t count, i; + unsigned user_id; + unsigned 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 { - size_t add_cpt, merge_cpt; + unsigned add_cpt, merge_cpt; res_T add_res, merge_res; }; static res_T add_seg - (const size_t unique_id, - const size_t iseg, + (const unsigned unique_id, + const unsigned iseg, void* context) { struct context* ctx = context; @@ -40,11 +40,11 @@ add_seg static res_T merge_seg - (const size_t unique_id, - const size_t iseg, + (const unsigned unique_id, + const unsigned iseg, const int reversed_segment, - size_t segment_properties[SG2D_PROP_TYPES_COUNT__], - const size_t merged_properties[SG2D_PROP_TYPES_COUNT__], + unsigned segment_properties[SG2D_PROP_TYPES_COUNT__], + const unsigned merged_properties[SG2D_PROP_TYPES_COUNT__], void* context, int* merge_conflict) { @@ -64,8 +64,8 @@ merge_seg static res_T validate - (const size_t iseg, - const size_t properties[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + const unsigned properties[SG2D_PROP_TYPES_COUNT__], void* context, int* properties_conflict) { @@ -76,8 +76,8 @@ validate static res_T validate2 - (const size_t iseg, - const size_t properties[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + const unsigned 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; - size_t property[12]; - size_t i; - const size_t property_count = sizeof(property) / sizeof(*property); - size_t count; + unsigned property[12]; + unsigned i; + const unsigned property_count = sizeof(property) / sizeof(*property); + unsigned 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) { - size_t id; + unsigned 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 @@ -33,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__; - size_t circ_seg_count, circ_vrtx_count, count; + unsigned circ_seg_count, circ_vrtx_count, count; int i, j, k; - size_t m_in, m_out, itf = 0; + unsigned m_in, m_out, itf = 0; struct context ctx = CONTEXT_NULL__; (void)argc, (void)argv; @@ -56,8 +56,10 @@ main(int argc, char** argv) create_circle(1, 16, &ctx); 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; + ASSERT(sa_size(ctx.indices) <= UINT_MAX); + ASSERT(sa_size(ctx.positions) <= UINT_MAX); + circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; + circ_vrtx_count = (unsigned)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) { @@ -66,8 +68,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 = (size_t)k; - m_out = (size_t)(k + 1); + m_in = (unsigned)k; + m_out = (unsigned)(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 @@ -30,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__; - size_t circ_seg_count, circ_vrtx_count, i, count; - size_t m0 = 0, m1, itf = 0; + unsigned circ_seg_count, circ_vrtx_count, i, count; + unsigned m0 = 0, m1, itf = 0; struct context ctx = CONTEXT_NULL__; (void)argc, (void)argv; @@ -52,8 +52,10 @@ main(int argc, char** argv) create_circle(1, 1048576, &ctx); 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; + ASSERT(sa_size(ctx.indices) <= UINT_MAX); + ASSERT(sa_size(ctx.positions) <= UINT_MAX); + circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; + circ_vrtx_count = (unsigned)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) { diff --git a/src/test_sg2d_some_enclosures.c b/src/test_sg2d_some_enclosures.c @@ -33,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__; - size_t circ_seg_count, circ_vrtx_count, count; + unsigned circ_seg_count, circ_vrtx_count, count; int i, j, k; - size_t m_in, m_out, itf = 0; + unsigned m_in, m_out, itf = 0; struct context ctx = CONTEXT_NULL__; (void)argc, (void)argv; @@ -56,8 +56,10 @@ main(int argc, char** argv) create_circle(1, 16, &ctx); 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; + ASSERT(sa_size(ctx.indices) <= UINT_MAX); + ASSERT(sa_size(ctx.positions) <= UINT_MAX); + circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; + circ_vrtx_count = (unsigned)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) { @@ -66,8 +68,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 = (size_t)k; - m_out = (size_t)(k + 1); + m_in = (unsigned)k; + m_out = (unsigned)(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 @@ -30,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__; - size_t circ_seg_count, circ_vrtx_count, i, count; - size_t m0 = 0, m1, itf = 0; + unsigned circ_seg_count, circ_vrtx_count, i, count; + unsigned m0 = 0, m1, itf = 0; struct context ctx = CONTEXT_NULL__; (void)argc, (void)argv; @@ -52,8 +52,10 @@ main(int argc, char** argv) create_circle(1, 264, &ctx); 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; + ASSERT(sa_size(ctx.indices) <= UINT_MAX); + ASSERT(sa_size(ctx.positions) <= UINT_MAX); + circ_seg_count = (unsigned)sa_size(ctx.indices) / 2; + circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2; OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count, NB_CIRC * circ_seg_count, 0)); 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__; - size_t count; + unsigned 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__; - size_t count; + unsigned 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__; - size_t count; + unsigned 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__; - size_t property[12]; - size_t i; - const size_t property_count = sizeof(property) / sizeof(*property); - size_t count; + unsigned property[12]; + unsigned i; + const unsigned property_count = sizeof(property) / sizeof(*property); + unsigned 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) { - size_t prop[SG2D_PROP_TYPES_COUNT__]; + unsigned 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 size_t*, ctx.front_media, ctx.back_media); + SWAP(const unsigned*, 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) { - size_t prop[SG2D_PROP_TYPES_COUNT__]; + unsigned 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 @@ -23,9 +23,9 @@ #define BA(Cond) CHK((Cond) == RES_BAD_ARG) #define ME(Cond) CHK((Cond) == RES_MEM_ERR) -/******************************************************************************* +/****************************************************************************** * Memory allocator - ******************************************************************************/ + *****************************************************************************/ static INLINE void check_memory_allocator(struct mem_allocator* allocator) { @@ -37,9 +37,9 @@ check_memory_allocator(struct mem_allocator* allocator) } } -/******************************************************************************* +/****************************************************************************** * Geometry - ******************************************************************************/ + *****************************************************************************/ /* 2D square */ static const double square_vertices[4/*#vertices*/ * 2/*#coords per vertex*/] = { @@ -48,7 +48,7 @@ square_vertices[4/*#vertices*/ * 2/*#coords per vertex*/] = { 0.0, 1.0, 1.0, 1.0 }; -static const size_t +static const unsigned 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 size_t +static unsigned box_indices[4/*#segments*/ * 2/*#indices per segment*/] = { 0, 2, 2, 3, 3, 1, 1, 0 }; -static const size_t +static const unsigned nsegments = sizeof(box_indices) / (2 * sizeof(*box_indices)); struct context { const double* positions; - const size_t* indices; - const size_t* front_media; - const size_t* back_media; - const size_t* intface; + const unsigned* indices; + const unsigned* front_media; + const unsigned* back_media; + const unsigned* 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 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 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 intface0[4] = { 0, 0, 0, 0 }; -static const size_t intface1[4] = { 1, 1, 1, 1 }; +static const unsigned intface0[4] = { 0, 0, 0, 0 }; +static const unsigned intface1[4] = { 1, 1, 1, 1 }; static INLINE void -get_indices(const size_t iseg, size_t ids[2], void* context) +get_indices(const unsigned iseg, unsigned ids[2], void* context) { const struct context* ctx = context; ASSERT(ids && ctx); @@ -114,7 +114,7 @@ get_indices(const size_t iseg, size_t ids[2], void* context) } static INLINE void -get_position(const size_t ivert, double pos[2], void* context) +get_position(const unsigned ivert, double pos[2], void* context) { const struct context* ctx = context; ASSERT(pos && ctx); @@ -124,8 +124,8 @@ get_position(const size_t ivert, double pos[2], void* context) static INLINE void get_properties - (const size_t iseg, - size_t property[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + unsigned 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 @@ -18,20 +18,20 @@ #include <rsys/stretchy_array.h> -/******************************************************************************* +/****************************************************************************** * Circle functions - ******************************************************************************/ + *****************************************************************************/ static INLINE void create_circle (const double radius, - const size_t nslices, + const unsigned nslices, struct context* ctx) { double step_theta; - size_t itheta; - size_t islice; + unsigned itheta; + unsigned islice; double* d = NULL; - size_t* u = NULL; + unsigned* 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 size_t v0 = islice; - const size_t v1 = ((islice + 1) % nslices); + const unsigned v0 = islice; + const unsigned 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 size_t iseg, - size_t property[SG2D_PROP_TYPES_COUNT__], + (const unsigned iseg, + unsigned property[SG2D_PROP_TYPES_COUNT__], void* context) { const struct context* ctx = context;