commit 5932f3d03b0b88b53fdbbd19d5c20b4fef5e5180
parent 6d5b4dce314034c27e2ec86e4c0a8ccd5a7ef070
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Fri, 17 Jan 2020 16:47:13 +0100
Fix some imprecisions in both code and documentation
Diffstat:
11 files changed, 48 insertions(+), 165 deletions(-)
diff --git a/README.md b/README.md
@@ -6,14 +6,16 @@ geometries. These geometries are suitable to be partitioned into
enclosures using the star-enclosures library. It also provides
mechanisms to construct triangle-related app data, detect
inconsistencies and dump the resulting geometry in various formats (OBJ,
-VTK, C code).
+VTK, C code chunks).
How to build
------------
Star-geometry relies on the [CMake](http://www.cmake.org) and the
-[RCMake](https://gitlab.com/vaplv/rcmake/) package to build. It also
-depends on the [RSys](https://gitlab.com/vaplv/rsys/) library.
+[RCMake](https://gitlab.com/vaplv/rcmake/) package to build and
+depends on the [RSys](https://gitlab.com/vaplv/rsys/) library. Some tests
+also depends on the [SD3UT](https://gitlab.com/meso-star/star-3dut/)
+library.
First ensure that CMake and a C compiler that is compliant with C89 are
installed on your system. Then install the RCMake package as well as all
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -13,7 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.1)
project(star-geometry C)
enable_testing()
@@ -36,7 +36,7 @@ CMAKE_DEPENDENT_OPTION(HUGE_ADDITIONAL_TESTS
find_package(RCMake 0.4 REQUIRED)
find_package(RSys 0.8.1 REQUIRED)
-if(SMALL_ADDITIONAL_TESTS)
+if(SMALL_ADDITIONAL_TESTS OR HUGE_ADDITIONAL_TESTS)
find_package(Star3DUT 0.3.1 REQUIRED)
endif()
@@ -48,7 +48,7 @@ include_directories(
${RSys_INCLUDE_DIR}
${StarEnc_INCLUDE_DIR})
-if(SMALL_ADDITIONAL_TESTS)
+if(SMALL_ADDITIONAL_TESTS OR HUGE_ADDITIONAL_TESTS)
rcmake_append_runtime_dirs(_runtime_dirs RSys StarEnc Star3DUT)
else()
rcmake_append_runtime_dirs(_runtime_dirs RSys StarEnc)
@@ -116,8 +116,11 @@ if(NOT NO_TEST)
function(build_test _name)
add_executable(${_name}
${STAR_GEOM_SOURCE_DIR}/${_name}.c
- ${STAR_GEOM_SOURCE_DIR}/test_sg3_utils.h
- )
+ ${STAR_GEOM_SOURCE_DIR}/test_sg3_utils.h)
+ foreach(other ${ARGN})
+ target_sources(${_name}
+ PUBLIC ${STAR_GEOM_SOURCE_DIR}/${other})
+ endforeach()
target_link_libraries(${_name} RSys sg3)
endfunction()
@@ -127,7 +130,7 @@ if(NOT NO_TEST)
endfunction()
function(new_test _name)
- build_test(${_name})
+ build_test(${_name} ${ARGN})
register_test(${_name} ${_name})
endfunction()
@@ -143,8 +146,8 @@ if(NOT NO_TEST)
new_test(test_sg3_cube_behind_cube)
new_test(test_sg3_cube_in_cube)
new_test(test_sg3_cube_on_cube)
- new_test(test_sg3_some_enclosures)
- new_test(test_sg3_some_triangles)
+ new_test(test_sg3_some_enclosures test_sg3_utils2.h)
+ new_test(test_sg3_some_triangles test_sg3_utils2.h)
new_test(test_sg3_undefined_properties)
target_link_libraries(test_sg3_some_enclosures Star3DUT)
@@ -159,8 +162,8 @@ if(NOT NO_TEST)
endif()
if(HUGE_ADDITIONAL_TESTS)
- new_test(test_sg3_many_enclosures)
- new_test(test_sg3_many_triangles)
+ new_test(test_sg3_many_enclosures test_sg3_utils2.h)
+ new_test(test_sg3_many_triangles test_sg3_utils2.h)
target_link_libraries(test_sg3_many_enclosures Star3DUT)
target_link_libraries(test_sg3_many_triangles Star3DUT)
diff --git a/src/sg3_geometry.c b/src/sg3_geometry.c
@@ -879,7 +879,7 @@ sg3_geometry_dump_as_vtk
}
/* Headers */
fprintf(stream, "# vtk DataFile Version 3.0\n");
- fprintf(stream, "Dump of star-geometry report\n");
+ fprintf(stream, "Dump of star-geometry geometry\n");
fprintf(stream, "ASCII\n");
fprintf(stream, "DATASET POLYDATA\n");
@@ -1047,15 +1047,14 @@ sg3_geometry_dump_as_C_code
"};\n");
/* Dump properties */
- triangles = darray_triangle_cdata_get(&geom->unique_triangles);
fprintf(stream,
"%sunsigned %s_properties[%u] =\n"
"{\n",
- qualifiers, name_prefix, (unsigned)(3 * tsz));
+ qualifiers, name_prefix, (unsigned)(SG3_PROP_TYPES_COUNT__ * tsz));
FOR_EACH(i, 0, tsz) {
int p;
fprintf(stream, " ");
- FOR_EACH(p, 0, 3) {
+ FOR_EACH(p, 0, SG3_PROP_TYPES_COUNT__) {
if(triangles[i].properties[p] == SG3_UNDEFINED_PROPERTY)
fprintf(stream, " SG3_UNDEFINED_PROPERTY");
else fprintf(stream," %u", triangles[i].properties[p]);
diff --git a/src/sg3_geometry.h b/src/sg3_geometry.h
@@ -164,11 +164,13 @@ init_trg_descriptions
{
int i;
ASSERT(alloc && data);
- FOR_EACH(i, 0, 3) darray_definition_init(alloc, data->defs + i);
+ FOR_EACH(i, 0, SG3_PROP_TYPES_COUNT__)
+ darray_definition_init(alloc, data->defs + i);
data->merge_conflict = 0;
data->properties_conflict = 0;
data->defs_include_undefined = 0;
- FOR_EACH(i, 0, 3) data->property_defined[i] = 0;
+ FOR_EACH(i, 0, SG3_PROP_TYPES_COUNT__)
+ data->property_defined[i] = 0;
}
static INLINE res_T
@@ -184,7 +186,8 @@ copy_trg_descriptions
dst->merge_conflict = src->merge_conflict;
dst->properties_conflict = src->properties_conflict;
dst->defs_include_undefined = src->defs_include_undefined;
- FOR_EACH(i, 0, 3) dst->property_defined[i] = src->property_defined[i];
+ FOR_EACH(i, 0, SG3_PROP_TYPES_COUNT__)
+ dst->property_defined[i] = src->property_defined[i];
exit:
return res;
error:
diff --git a/src/sg3_senc_helper.h b/src/sg3_senc_helper.h
@@ -22,7 +22,7 @@
#include <rsys/rsys.h>
/* Get vertex indices for the itri_th triangle.
- * Suitable for use as indices callback in senc_scene_add_geometry calls. */
+ * Suitable for use as get_indices callback in senc_scene_create calls. */
static FINLINE void
sg3_senc_geometry_get_indices__
(const unsigned itri,
@@ -37,7 +37,7 @@ sg3_senc_geometry_get_indices__
}
/* Get vertex indices for the itri_th triangle.
- * Suitable for use as media callback in senc_scene_add_geometry calls. */
+ * Suitable for use as get_media callback in senc_scene_create calls. */
static FINLINE void
sg3_senc_geometry_get_media__
(const unsigned itri,
@@ -57,7 +57,7 @@ sg3_senc_geometry_get_media__
}
/* Get vertex indices for the itri_th triangle.
- * Suitable for use as position callback in senc_scene_add_geometry calls. */
+ * Suitable for use as get_position callback in senc_scene_create calls. */
static FINLINE void
sg3_senc_geometry_get_position__
(const unsigned ivert,
diff --git a/src/test_sg3_geometry.c b/src/test_sg3_geometry.c
@@ -21,7 +21,7 @@
static res_T
validate
(const unsigned itri,
- const unsigned properties[3],
+ const unsigned properties[SG3_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
@@ -35,8 +35,8 @@ merge_trg
(const unsigned user_id,
const unsigned itri,
const int reversed_triangle,
- unsigned triangle_properties[3],
- const unsigned merged_properties[3],
+ unsigned triangle_properties[SG3_PROP_TYPES_COUNT__],
+ const unsigned merged_properties[SG3_PROP_TYPES_COUNT__],
void* context,
int* merge_conflict)
{
diff --git a/src/test_sg3_geometry_2.c b/src/test_sg3_geometry_2.c
@@ -43,8 +43,8 @@ merge_trg
(const unsigned unique_id,
const unsigned itri,
const int reversed_triangle,
- unsigned triangle_properties[3],
- const unsigned merged_properties[3],
+ unsigned triangle_properties[SG3_PROP_TYPES_COUNT__],
+ const unsigned merged_properties[SG3_PROP_TYPES_COUNT__],
void* context,
int* merge_conflict)
{
@@ -56,7 +56,7 @@ merge_trg
(void)triangle_properties; (void)merged_properties;
add_geom_ctx = ctx->custom;
if(add_geom_ctx->merge_res == RES_OK) ++add_geom_ctx->merge_cpt;
- FOR_EACH(i, 0, 3)
+ FOR_EACH(i, 0, SG3_PROP_TYPES_COUNT__)
if(!sg3_compatible_property(triangle_properties[i], merged_properties[i]))
*merge_conflict = 1;
return add_geom_ctx->merge_res;
@@ -65,7 +65,7 @@ merge_trg
static res_T
validate
(const unsigned itri,
- const unsigned properties[3],
+ const unsigned properties[SG3_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
@@ -77,7 +77,7 @@ validate
static res_T
validate2
(const unsigned itri,
- const unsigned properties[3],
+ const unsigned properties[SG3_PROP_TYPES_COUNT__],
void* context,
int* properties_conflict)
{
diff --git a/src/test_sg3_report.c b/src/test_sg3_report.c
@@ -1,130 +0,0 @@
-/* Copyright (C) 2016-2019 |Meso|Star> (contact@meso-star.com)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "star-geometry.h"
-#include "test_sg3_utils.h"
-
-#include <rsys/double3.h>
-
-#include <stdio.h>
-
-static res_T
-validate
- (const unsigned itri,
- const unsigned properties[3],
- void* context,
- int* properties_conflict)
-{
- (void)itri; (void)properties; (void)context;
- *properties_conflict = 0;
- return RES_OK;
-}
-
-static res_T
-merge_trg
- (const unsigned global_id,
- const unsigned itri,
- const int reversed_triangle,
- unsigned triangle_properties[3],
- const unsigned merged_properties[3],
- void* context,
- int* merge_conflict)
-{
- ASSERT(merge_conflict);
- (void)global_id; (void)reversed_triangle; (void)context;
- (void)triangle_properties; (void)merged_properties; (void)merge_conflict;
- *merge_conflict = (int)itri;
- return RES_OK;
-}
-
-int
-main(int argc, char** argv)
-{
- struct mem_allocator allocator;
- struct sg3_device* dev;
- struct sg3_report* report;
- struct sg3_geometry* geometry;
- unsigned count;
- struct context ctx;
- (void)argc, (void)argv;
-
-
-
-
-
- OK(sg3_report_get_unique_triangles_count(report, &count));
- CHK(count == 0);
- OK(sg3_report_get_triangle_with_undefined_side_count(report, &count));
- CHK(count == 0);
- OK(sg3_report_get_triangle_with_undefined_interface_count(report, &count));
- CHK(count == 0);
- OK(sg3_report_get_merge_conflict_count(report, &count));
- CHK(count == 0);
- OK(sg3_report_get_properties_conflict_count(report, &count));
- CHK(count == 0);
- OK(sg3_report_dump_as_obj(report, stdout, SG3_ALL_TRIANGLES));
- /* Empty geometry */
- BA(sg3_report_dump_as_C_code(report, stdout, "test"));
-
- /* A 3D cube.
- * 2 enclosures (inside, outside) sharing the same triangles,
- * but opposite sides */
- ctx.positions = cube_vertices;
- ctx.indices = cube_indices;
- ctx.scale = 1;
- d3(ctx.offset, 0, 0, 0);
- ctx.front_media = medium0;
- ctx.back_media = medium1;
- ctx.intface = intface0;
- ctx.custom = NULL;
-
- OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties,
- nvertices, get_position, NULL, NULL, &ctx));
- OK(sg3_report_dump_as_C_code(report, stdout, "test"));
-
- /* Conflicts with merge_trg callback */
- /* BA because merge_trg detects conflic */
- OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties,
- nvertices, get_position, NULL, merge_trg, &ctx));
- OK(sg3_report_get_merge_conflict_count(report, &count));
- /* Due to merge_trg internals, all but the first triangle report conflict */
- CHK(count == ntriangles - 1);
- BA(sg3_report_dump_as_C_code(report, stdout, "test"));
- OK(sg3_geometry_ref_put(geometry));
- OK(sg3_report_ref_put(report));
-
- /* Conflicts without merge_trg callback */
- OK(sg3_report_create(dev, &report));
- OK(sg3_geometry_create(dev, report, &geometry));
- OK(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties,
- nvertices, get_position, NULL, NULL, &ctx));
- ctx.front_media = medium1_front0;
- /* BA because there are conflicts and no merge_trg callback to overrule */
- BA(sg3_geometry_add(geometry, ntriangles, get_indices, get_properties,
- nvertices, get_position, NULL, NULL, &ctx));
- OK(sg3_report_get_merge_conflict_count(report, &count));
- /* Without merge_trg add stops at the first conflict */
- CHK(count == 1);
- BA(sg3_report_dump_as_C_code(report, stdout, "test"));
- OK(sg3_geometry_ref_put(geometry));
- OK(sg3_report_ref_put(report));
-
- OK(sg3_device_ref_put(dev));
-
- check_memory_allocator(&allocator);
- mem_shutdown_proxy_allocator(&allocator);
- CHK(mem_allocated_size() == 0);
- return 0;
-}
diff --git a/src/test_sg3_undefined_properties.c b/src/test_sg3_undefined_properties.c
@@ -81,7 +81,7 @@ main(int argc, char** argv)
OK(sg3_geometry_get_unique_triangles_count(geom, &count));
CHK(count == ntriangles);
FOR_EACH(i, 0, count) {
- unsigned prop[3];
+ unsigned prop[SG3_PROP_TYPES_COUNT__];
OK(sg3_geometry_get_unique_triangle_properties(geom, i, prop));
CHK(prop[SG3_FRONT] == ((i % 2) ? 0 : SG3_UNDEFINED_PROPERTY)
&& prop[SG3_BACK] == 1
@@ -102,7 +102,7 @@ main(int argc, char** argv)
/* Define properties for remaining triangles, using reversed box */
FOR_EACH(i, 0, sizeof(property) / sizeof(*property))
- property[i] = (i % 2) ?SG3_UNDEFINED_PROPERTY : 0;
+ property[i] = (i % 2) ? SG3_UNDEFINED_PROPERTY : 0;
OK(sg3_geometry_add(geom, ntriangles, nvertices, &callbacks, &ctx));
OK(sg3_geometry_get_triangle_with_undefined_side_count(geom, &count));
CHK(count == 0);
diff --git a/src/test_sg3_utils.h b/src/test_sg3_utils.h
@@ -135,7 +135,10 @@ get_position(const unsigned ivert, double pos[3], void* context)
}
static INLINE void
-get_properties(const unsigned itri, unsigned property[3], void* context)
+get_properties
+ (const unsigned itri,
+ unsigned property[SG3_PROP_TYPES_COUNT__],
+ void* context)
{
const struct context* ctx = context;
ASSERT(property && ctx);
diff --git a/src/test_sg3_utils2.h b/src/test_sg3_utils2.h
@@ -51,7 +51,10 @@ get_s3dut_position(const unsigned ivert, double pos[3], void* context)
}
static INLINE void
-get_s3dut_properties(const unsigned itri, unsigned property[3], void* context)
+get_s3dut_properties
+ (const unsigned itri,
+ unsigned property[SG3_PROP_TYPES_COUNT__],
+ void* context)
{
const struct s3dut_context* ctx = context;
ASSERT(property && ctx);