commit 4213d7c20246bf1538f5817e88ec9ad5336e279c
parent 7d26600da727859c243288f93b9096020c09b710
Author: vaplv <vaplv@free.fr>
Date: Tue, 12 Dec 2017 15:15:49 +0100
Merge branch 'release_0.1.2'
Diffstat:
5 files changed, 129 insertions(+), 135 deletions(-)
diff --git a/README.md b/README.md
@@ -15,6 +15,13 @@ project from the cmake/CMakeLists.txt file by appending the RCMake and RSys
install directories to the `CMAKE_PREFIX_PATH` variable. The resulting project
can be edited, built, tested and installed as any CMake project.
+## Release notes
+
+### Version 0.1.2
+
+- Update the version of the RSys dependency to 0.6: replace the deprecated
+ `[N]CHECK` macros by the new macro `CHK`.
+
## License
Polygon is Copyright (C) 2014-2017 Vincent Forest (vaplv@free.fr). It is a free
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -17,7 +17,6 @@ cmake_minimum_required(VERSION 2.8)
project(polygon C)
enable_testing()
-option(BUILD_STATIC "Build library as static rather than shared" OFF)
option(NO_TEST "Do not compile the test pograms" OFF)
set(POLYGON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
@@ -25,9 +24,8 @@ set(POLYGON_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
################################################################################
# Dependencies
################################################################################
-find_package(RCMake REQUIRED)
-find_package(RSys 0.2 REQUIRED)
-include_directories(${RSys_INCLUDE_DIR})
+find_package(RCMake 0.4 REQUIRED)
+find_package(RSys 0.6 REQUIRED)
set(CMAKE_MODULE_PATH ${RCMAKE_SOURCE_DIR})
include(rcmake)
@@ -40,7 +38,7 @@ rcmake_append_runtime_dirs(_runtime_dirs RSys)
################################################################################
set(VERSION_MAJOR 0)
set(VERSION_MINOR 1)
-set(VERSION_PATCH 1)
+set(VERSION_PATCH 2)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(POLYGON_FILES_SRC polygon.c)
@@ -54,19 +52,12 @@ if(CMAKE_COMPILER_IS_GNUCC)
set(MATH_LIB m)
endif()
-if(BUILD_STATIC)
- add_library(polygon STATIC ${POLYGON_FILES_SRC} ${POLYGON_FILES_INC})
- set_target_properties(polygon PROPERTIES DEFINE_SYMBOL POLYGON_STATIC_BUILD)
-else()
-
- add_library(polygon SHARED ${POLYGON_FILES_SRC} ${POLYGON_FILES_INC})
- set_target_properties(polygon PROPERTIES
- DEFINE_SYMBOL POLYGON_SHARED_BUILD
- VERSION ${VERSION}
- SOVERSION ${VERSION_MAJOR})
- target_link_libraries(polygon ${MATH_LIB})
-endif()
-target_link_libraries(polygon RSys)
+add_library(polygon SHARED ${POLYGON_FILES_SRC} ${POLYGON_FILES_INC})
+set_target_properties(polygon PROPERTIES
+ DEFINE_SYMBOL POLYGON_SHARED_BUILD
+ VERSION ${VERSION}
+ SOVERSION ${VERSION_MAJOR})
+target_link_libraries(polygon RSys ${MATH_LIB})
rcmake_setup_devel(polygon Polygon ${VERSION} polygon_version.h)
@@ -75,7 +66,7 @@ rcmake_setup_devel(polygon Polygon ${VERSION} polygon_version.h)
################################################################################
if(NOT NO_TEST)
function(new_test _name)
- add_executable(${_name}
+ add_executable(${_name}
${POLYGON_SOURCE_DIR}/${_name}.c
${POLYGON_SOURCE_DIR}/test_polygon_utils.h)
target_link_libraries(${_name} polygon ${MATH_LIB})
diff --git a/src/polygon.h b/src/polygon.h
@@ -20,7 +20,7 @@
#ifdef POLYGON_SHARED_BUILD
#define POLYGON_API extern EXPORT_SYM
-#elif defined(POLYGONAL_STATIC_BUILD)
+#elif defined(POLYGON_STATIC_BUILD)
#define POLYGON_API extern LOCAL_SYM
#else
#define POLYGON_API extern IMPORT_SYM
diff --git a/src/test_polygon.c b/src/test_polygon.c
@@ -36,40 +36,40 @@ check_triangulation
ASSERT(poly && indices && nindices && nedges_contour);
contour = mem_calloc(nedges_contour, sizeof(char));
- NCHECK(contour, NULL);
+ CHK(contour != NULL);
memset(contour, 0, nedges_contour * sizeof(char));
- CHECK(nindices % 3, 0);
+ CHK(nindices % 3 == 0);
FOR_EACH(i, 0, nindices/3) {
const uint32_t* tri = indices + (i*3);
float e0[3], e1[3], N[3];
float v0[3], v1[3], v2[3];
float len;
- CHECK(polygon_vertex_get(poly, tri[0], v0), RES_OK);
- CHECK(polygon_vertex_get(poly, tri[1], v1), RES_OK);
- CHECK(polygon_vertex_get(poly, tri[2], v2), RES_OK);
+ CHK(polygon_vertex_get(poly, tri[0], v0) == RES_OK);
+ CHK(polygon_vertex_get(poly, tri[1], v1) == RES_OK);
+ CHK(polygon_vertex_get(poly, tri[2], v2) == RES_OK);
/* Compute the triangle area and add it to the overall polygon area */
f3_sub(e0, v1, v0);
f3_sub(e1, v2, v0);
len = f3_normalize(N, f3_cross(N, e0, e1));
- CHECK(eq_eps(len, 0.f, 1.e-6f), 0);
+ CHK(eq_eps(len, 0.f, 1.e-6f) == 0);
area += len * 0.5f;
/* Update the contour edge flag */
if(tri[1] == (tri[0] + 1) % nedges_contour) {
- CHECK(contour[tri[0]], 0);
+ CHK(contour[tri[0]] == 0);
contour[tri[0]] = 1;
}
if(tri[2] == (tri[1] + 1) % nedges_contour) {
- CHECK(contour[tri[1]], 0);
+ CHK(contour[tri[1]] == 0);
contour[tri[1]] = 1;
}
if(tri[0] == (tri[2] + 1) % nedges_contour) {
- CHECK(contour[tri[2]], 0);
+ CHK(contour[tri[2]] == 0);
contour[tri[2]] = 1;
}
}
FOR_EACH(i, 0, nedges_contour) /* All the contour edges may be found */
- CHECK(contour[i], 1);
+ CHK(contour[i] == 1);
mem_rm(contour);
return area;
@@ -109,138 +109,134 @@ main(int argc, char** argv)
mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator);
- CHECK(polygon_create(NULL, NULL), RES_BAD_ARG);
- CHECK(polygon_create(&allocator_proxy, NULL), RES_BAD_ARG);
- CHECK(polygon_create(NULL, &poly), RES_OK);
+ CHK(polygon_create(NULL, NULL) == RES_BAD_ARG);
+ CHK(polygon_create(&allocator_proxy, NULL) == RES_BAD_ARG);
+ CHK(polygon_create(NULL, &poly) == RES_OK);
- CHECK(polygon_ref_get(NULL), RES_BAD_ARG);
- CHECK(polygon_ref_get(poly), RES_OK);
- CHECK(polygon_ref_put(NULL), RES_BAD_ARG);
- CHECK(polygon_ref_put(poly), RES_OK);
- CHECK(polygon_ref_put(poly), RES_OK);
+ CHK(polygon_ref_get(NULL) == RES_BAD_ARG);
+ CHK(polygon_ref_get(poly) == RES_OK);
+ CHK(polygon_ref_put(NULL) == RES_BAD_ARG);
+ CHK(polygon_ref_put(poly) == RES_OK);
+ CHK(polygon_ref_put(poly) == RES_OK);
- CHECK(polygon_create(&allocator_proxy, &poly), RES_OK);
+ CHK(polygon_create(&allocator_proxy, &poly) == RES_OK);
- CHECK(polygon_vertices_count_get(NULL, NULL), RES_BAD_ARG);
- CHECK(polygon_vertices_count_get(poly, NULL), RES_BAD_ARG);
- CHECK(polygon_vertices_count_get(NULL, &nvertices), RES_BAD_ARG);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 0);
+ CHK(polygon_vertices_count_get(NULL, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertices_count_get(poly, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertices_count_get(NULL, &nvertices) == RES_BAD_ARG);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 0);
- CHECK(polygon_vertex_add(NULL, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_add(poly, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_add(NULL, vertices + 3), RES_BAD_ARG);
- CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
+ CHK(polygon_vertex_add(NULL, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_add(poly, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_add(NULL, vertices + 3) == RES_BAD_ARG);
+ CHK(polygon_vertex_add(poly, vertices + 3) == RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 1);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 1);
/* The last vertex is equal to the new one => skip it */
- CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 1);
+ CHK(polygon_vertex_add(poly, vertices + 3) == RES_OK);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 1);
- CHECK(polygon_vertex_add(poly, vertices + 6), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 2);
+ CHK(polygon_vertex_add(poly, vertices + 6) == RES_OK);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 2);
/* The new vertex is aligned with the 2 previous one => replace the last
* vertex by the new one */
- CHECK(polygon_vertex_add(poly, vertices + 15), RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 2);
+ CHK(polygon_vertex_add(poly, vertices + 15) == RES_OK);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 2);
- CHECK(polygon_vertex_get(NULL, UINT32_MAX, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_get(poly, UINT32_MAX, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, 0, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_get(poly, 0, NULL), RES_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, UINT32_MAX, pos), RES_BAD_ARG);
- CHECK(polygon_vertex_get(poly, UINT32_MAX, pos), RES_BAD_ARG);
- CHECK(polygon_vertex_get(NULL, 0, pos), RES_BAD_ARG);
- CHECK(polygon_vertex_get(poly, 0, pos), RES_OK);
- CHECK(f3_eq_eps(pos, vertices + 3, 1.e-6f), 1);
+ CHK(polygon_vertex_get(NULL, UINT32_MAX, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(poly, UINT32_MAX, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(NULL, 0, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(poly, 0, NULL) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(NULL, UINT32_MAX, pos) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(poly, UINT32_MAX, pos) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(NULL, 0, pos) == RES_BAD_ARG);
+ CHK(polygon_vertex_get(poly, 0, pos) == RES_OK);
+ CHK(f3_eq_eps(pos, vertices + 3, 1.e-6f) == 1);
- CHECK(polygon_vertex_get(poly, 1, pos), RES_OK);
- CHECK(f3_eq_eps(pos, vertices + 15, 1.e-6f), 1);
+ CHK(polygon_vertex_get(poly, 1, pos) == RES_OK);
+ CHK(f3_eq_eps(pos, vertices + 15, 1.e-6f) == 1);
- CHECK(polygon_vertex_get(poly, 2, pos), RES_BAD_ARG);
+ CHK(polygon_vertex_get(poly, 2, pos) == RES_BAD_ARG);
- CHECK(polygon_clear(NULL), RES_BAD_ARG);
- CHECK(polygon_clear(poly), RES_OK);
+ CHK(polygon_clear(NULL) == RES_BAD_ARG);
+ CHK(polygon_clear(poly) == RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, 0);
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == 0);
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3]))
- CHECK(polygon_vertex_add(poly, vertices + ivertex * 3), RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + ivertex * 3) == RES_OK);
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, sizeof(vertices)/sizeof(float[3]));
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == sizeof(vertices)/sizeof(float[3]));
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3])) {
- CHECK(polygon_vertex_get(poly, ivertex, pos), RES_OK);
- CHECK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f), 1);
+ CHK(polygon_vertex_get(poly, ivertex, pos) == RES_OK);
+ CHK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f) == 1);
}
- CHECK(polygon_triangulate(NULL, NULL, NULL), RES_BAD_ARG);
- CHECK(polygon_triangulate(poly, NULL, NULL), RES_BAD_ARG);
- CHECK(polygon_triangulate(NULL, &indices, NULL), RES_BAD_ARG);
- CHECK(polygon_triangulate(poly, &indices, NULL), RES_BAD_ARG);
- CHECK(polygon_triangulate(NULL, NULL, &nindices), RES_BAD_ARG);
- CHECK(polygon_triangulate(poly, NULL, &nindices), RES_BAD_ARG);
- CHECK(polygon_triangulate(NULL, &indices, &nindices), RES_BAD_ARG);
+ CHK(polygon_triangulate(NULL, NULL, NULL) == RES_BAD_ARG);
+ CHK(polygon_triangulate(poly, NULL, NULL) == RES_BAD_ARG);
+ CHK(polygon_triangulate(NULL, &indices, NULL) == RES_BAD_ARG);
+ CHK(polygon_triangulate(poly, &indices, NULL) == RES_BAD_ARG);
+ CHK(polygon_triangulate(NULL, NULL, &nindices) == RES_BAD_ARG);
+ CHK(polygon_triangulate(poly, NULL, &nindices) == RES_BAD_ARG);
+ CHK(polygon_triangulate(NULL, &indices, &nindices) == RES_BAD_ARG);
/* Check full triangulation */
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 30);
- CHECK(eq_eps(check_triangulation
- (poly, indices, nindices, 12), 1.f, 1.e-6f), 1);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 30);
+ CHK(eq_eps(check_triangulation(poly, indices, nindices, 12), 1.f, 1.e-6f));
/* After the triangulation the input polygon may be unchanged */
- CHECK(polygon_vertices_count_get(poly, &nvertices), RES_OK);
- CHECK(nvertices, sizeof(vertices)/sizeof(float[3]));
+ CHK(polygon_vertices_count_get(poly, &nvertices) == RES_OK);
+ CHK(nvertices == sizeof(vertices)/sizeof(float[3]));
FOR_EACH(ivertex, 0, sizeof(vertices)/sizeof(float[3])) {
- CHECK(polygon_vertex_get(poly, ivertex, pos), RES_OK);
- CHECK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f), 1);
+ CHK(polygon_vertex_get(poly, ivertex, pos) == RES_OK);
+ CHK(f3_eq_eps(pos, vertices + ivertex*3, 1.e-6f) == 1);
}
/* Check that the input polygon can be retriangulated */
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 30);
- CHECK(eq_eps(check_triangulation
- (poly, indices, nindices, 12), 1.f, 1.e-6f), 1);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 30);
+ CHK(eq_eps(check_triangulation(poly, indices, nindices, 12), 1.f, 1.e-6f));
/* One can triangulate empty polygon */
- CHECK(polygon_clear(poly), RES_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 0);
+ CHK(polygon_clear(poly) == RES_OK);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 0);
/* Check the triangulation of an updated polygon */
- CHECK(polygon_vertex_add(poly, vertices + 0), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 3), RES_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 0);
- CHECK(polygon_vertex_add(poly, vertices + 6), RES_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 3);
- CHECK(eq_eps(check_triangulation
- (poly, indices, nindices, 3), 0.5f, 1.e-6f), 1);
- CHECK(polygon_vertex_add(poly, vertices + 9), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 12), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 15), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 18), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 21), RES_OK);
- CHECK(polygon_vertex_add(poly, vertices + 21), RES_OK);
- CHECK(polygon_triangulate(poly, &indices, &nindices), RES_OK);
- CHECK(nindices, 18);
- CHECK(eq_eps(check_triangulation
- (poly, indices, nindices, 8), 1.375f, 1.e-6f), 1);
-
- CHECK(polygon_ref_put(poly), RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 0) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 3) == RES_OK);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 0);
+ CHK(polygon_vertex_add(poly, vertices + 6) == RES_OK);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 3);
+ CHK(eq_eps(check_triangulation(poly, indices, nindices, 3), 0.5f, 1.e-6f));
+ CHK(polygon_vertex_add(poly, vertices + 9) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 12) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 15) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 18) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 21) == RES_OK);
+ CHK(polygon_vertex_add(poly, vertices + 21) == RES_OK);
+ CHK(polygon_triangulate(poly, &indices, &nindices) == RES_OK);
+ CHK(nindices == 18);
+ CHK(eq_eps(check_triangulation(poly, indices, nindices, 8), 1.375f, 1.e-6f));
+
+ CHK(polygon_ref_put(poly) == RES_OK);
check_memory_allocator(&allocator_proxy);
mem_shutdown_proxy_allocator(&allocator_proxy);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}
diff --git a/src/test_polygon1.c b/src/test_polygon1.c
@@ -28,32 +28,32 @@ main(int argc, char** argv)
uint32_t nids;
(void)argc, (void)argv;
- CHECK(mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator), RES_OK);
+ CHK(mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator) == RES_OK);
- CHECK(polygon_create(&allocator_proxy, &poly), RES_OK);
+ CHK(polygon_create(&allocator_proxy, &poly) == RES_OK);
pos[0] = (ucast.i = 0xbeb504f3, ucast.f);
pos[1] = (ucast.i = 0x3eb504f3, ucast.f);
- CHECK(polygon_vertex_add(poly, pos), RES_OK);
+ CHK(polygon_vertex_add(poly, pos) == RES_OK);
pos[0] = (ucast.i = 0xbe977d76, ucast.f);
pos[1] = (ucast.i = 0x3ec14031, ucast.f);
- CHECK(polygon_vertex_add(poly, pos), RES_OK);
+ CHK(polygon_vertex_add(poly, pos) == RES_OK);
pos[0] = (ucast.i = 0xbe5dab96, ucast.f);
pos[1] = (ucast.i = 0x3f05ca33, ucast.f);
- CHECK(polygon_vertex_add(poly, pos), RES_OK);
+ CHK(polygon_vertex_add(poly, pos) == RES_OK);
pos[0] = (ucast.i = 0xbecccbef, ucast.f);
pos[1] = (ucast.i = 0x3ecccbef, ucast.f);
- CHECK(polygon_vertex_add(poly, pos), RES_OK);
+ CHK(polygon_vertex_add(poly, pos) == RES_OK);
pos[0] = (ucast.i = 0xbeb504f3, ucast.f);
pos[1] = (ucast.i = 0x3eb504f3, ucast.f);
- CHECK(polygon_vertex_add(poly, pos), RES_OK);
+ CHK(polygon_vertex_add(poly, pos) == RES_OK);
- CHECK(polygon_triangulate(poly, &ids, &nids), RES_OK);
- CHECK(nids, 6);
- CHECK(polygon_ref_put(poly), RES_OK);
+ CHK(polygon_triangulate(poly, &ids, &nids) == RES_OK);
+ CHK(nids == 6);
+ CHK(polygon_ref_put(poly) == RES_OK);
check_memory_allocator(&allocator_proxy);
mem_shutdown_proxy_allocator(&allocator_proxy);
- CHECK(mem_allocated_size(), 0);
+ CHK(mem_allocated_size() == 0);
return 0;
}