commit 81dc3fd6a23f9e5541590932cc286d191bc5ad74
parent d24a683d18a634fa1857856c913fbaddd0d0a0bd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 15 Feb 2019 14:41:57 +0100
Add and test the sdis_scene_get_dimension function
Diffstat:
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -83,6 +83,11 @@ enum sdis_estimator_type {
SDIS_ESTIMATOR_TYPES_COUNT__
};
+enum sdis_scene_dimension {
+ SDIS_SCENE_2D,
+ SDIS_SCENE_3D
+};
+
/* Random walk vertex, i.e. a spatiotemporal position at a given step of the
* random walk. */
struct sdis_rwalk_vertex {
@@ -530,6 +535,11 @@ sdis_scene_boundary_project_position
const double pos[3],
double uv[]);
+SDIS_API res_T
+sdis_scene_get_dimension
+ (const struct sdis_scene* scn,
+ enum sdis_scene_dimension* dim);
+
/*******************************************************************************
* An estimator stores the state of a simulation
******************************************************************************/
diff --git a/src/sdis_scene.c b/src/sdis_scene.c
@@ -273,6 +273,15 @@ sdis_scene_boundary_project_position
return RES_OK;
}
+res_T
+sdis_scene_get_dimension
+ (const struct sdis_scene* scn, enum sdis_scene_dimension* dim)
+{
+ if(!scn || !dim) return RES_BAD_ARG;
+ *dim = scene_is_2d(scn) ? SDIS_SCENE_2D : SDIS_SCENE_3D;
+ return RES_OK;
+}
+
/*******************************************************************************
* Local miscellaneous function
******************************************************************************/
diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c
@@ -93,6 +93,7 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
struct context ctx;
size_t ntris, npos;
size_t i;
+ enum sdis_scene_dimension dim;
ctx.positions = box_vertices;
ctx.indices = box_indices;
@@ -118,6 +119,11 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
#undef POS
#undef IFA
+ BA(sdis_scene_get_dimension(NULL, &dim));
+ BA(sdis_scene_get_dimension(scn, NULL));
+ OK(sdis_scene_get_dimension(scn, &dim));
+ CHK(dim == SDIS_SCENE_3D);
+
BA(sdis_scene_get_aabb(NULL, lower, upper));
BA(sdis_scene_get_aabb(scn, NULL, upper));
BA(sdis_scene_get_aabb(scn, lower, NULL));
@@ -178,6 +184,7 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
struct context ctx;
size_t nsegs, npos;
size_t i;
+ enum sdis_scene_dimension dim;
ctx.positions = square_vertices;
ctx.indices = square_indices;
@@ -203,6 +210,11 @@ test_scene_2d(struct sdis_device* dev, struct sdis_interface* interf)
#undef POS
#undef IFA
+ BA(sdis_scene_get_dimension(NULL, &dim));
+ BA(sdis_scene_get_dimension(scn, NULL));
+ OK(sdis_scene_get_dimension(scn, &dim));
+ CHK(dim == SDIS_SCENE_2D);
+
BA(sdis_scene_get_aabb(NULL, lower, upper));
BA(sdis_scene_get_aabb(scn, NULL, upper));
BA(sdis_scene_get_aabb(scn, lower, NULL));