star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

commit 118c3de3d010ca6424c0c0587d4cf9d43e7dcfd2
parent 40ffb3cef3e8d42d916f6e2efcc5f7b619cbf69e
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Tue,  7 Jan 2020 15:35:13 +0100

Refactor duplicated code

Diffstat:
Msrc/test_sg3_many_enclosures.c | 43+------------------------------------------
Msrc/test_sg3_many_triangles.c | 43+------------------------------------------
Asrc/test_sg3_utils2.h | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 84 deletions(-)

diff --git a/src/test_sg3_many_enclosures.c b/src/test_sg3_many_enclosures.c @@ -15,6 +15,7 @@ #include "sg3.h" #include "test_sg3_utils.h" +#include "test_sg3_utils2.h" #include <rsys/double3.h> @@ -26,48 +27,6 @@ #define NB_CYL_1 64 #define NB_CYL (NB_CYL_1 * NB_CYL_1 * NB_CYL_1) -struct s3dut_context { - struct s3dut_mesh_data data; - struct context ctx; -}; - -static INLINE void -get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context) -{ - const struct s3dut_context* ctx = context; - ASSERT(ids && ctx); - ASSERT(itri < ctx->data.nprimitives); - ASSERT(ctx->data.indices[itri * 3 + 0] < UINT_MAX - && ctx->data.indices[itri * 3 + 1] < UINT_MAX - && ctx->data.indices[itri * 3 + 2] < UINT_MAX); - ids[0] = (unsigned)ctx->data.indices[itri * 3 + 0]; - ids[ctx->ctx.reverse_vrtx ? 2 : 1] = (unsigned)ctx->data.indices[itri * 3 + 1]; - ids[ctx->ctx.reverse_vrtx ? 1 : 2] = (unsigned)ctx->data.indices[itri * 3 + 2]; -} - -static INLINE void -get_s3dut_position(const unsigned ivert, double pos[3], void* context) -{ - const struct s3dut_context* ctx = context; - double tmp[3]; - ASSERT(pos && ctx); - ASSERT(ivert < ctx->data.nvertices); - (void)ivert; - d3_add(pos, d3_muld(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale), - ctx->ctx.offset); -} - -static INLINE void -get_s3dut_properties(const unsigned itri, unsigned property[3], void* context) -{ - const struct s3dut_context* ctx = context; - ASSERT(property && ctx); - (void)itri; - property[ctx->ctx.reverse_med ? SG3_BACK : SG3_FRONT] = *ctx->ctx.front_media; - property[ctx->ctx.reverse_med ? SG3_FRONT : SG3_BACK] = *ctx->ctx.back_media; - property[SG3_INTFACE] = *ctx->ctx.intface; -} - int main(int argc, char** argv) { diff --git a/src/test_sg3_many_triangles.c b/src/test_sg3_many_triangles.c @@ -15,6 +15,7 @@ #include "sg3.h" #include "test_sg3_utils.h" +#include "test_sg3_utils2.h" #include <rsys/double3.h> @@ -25,48 +26,6 @@ #define NB_CYL 4 -struct s3dut_context { - struct s3dut_mesh_data data; - struct context ctx; -}; - -static INLINE void -get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context) -{ - const struct s3dut_context* ctx = context; - ASSERT(ids && ctx); - ASSERT(itri < ctx->data.nprimitives); - ASSERT(ctx->data.indices[itri * 3 + 0] < UINT_MAX - && ctx->data.indices[itri * 3 + 1] < UINT_MAX - && ctx->data.indices[itri * 3 + 2] < UINT_MAX); - ids[0] = (unsigned)ctx->data.indices[itri * 3 + 0]; - ids[ctx->ctx.reverse_vrtx ? 2 : 1] = (unsigned)ctx->data.indices[itri * 3 + 1]; - ids[ctx->ctx.reverse_vrtx ? 1 : 2] = (unsigned)ctx->data.indices[itri * 3 + 2]; -} - -static INLINE void -get_s3dut_position(const unsigned ivert, double pos[3], void* context) -{ - const struct s3dut_context* ctx = context; - double tmp[3]; - ASSERT(pos && ctx); - ASSERT(ivert < ctx->data.nvertices); - (void)ivert; - d3_add(pos, d3_muld(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale), - ctx->ctx.offset); -} - -static INLINE void -get_s3dut_properties(const unsigned itri, unsigned property[3], void* context) -{ - const struct s3dut_context* ctx = context; - ASSERT(property && ctx); - (void)itri; - property[ctx->ctx.reverse_med ? SG3_BACK : SG3_FRONT] = *ctx->ctx.front_media; - property[ctx->ctx.reverse_med ? SG3_FRONT : SG3_BACK] = *ctx->ctx.back_media; - property[SG3_INTFACE] = *ctx->ctx.intface; -} - int main(int argc, char** argv) { diff --git a/src/test_sg3_utils2.h b/src/test_sg3_utils2.h @@ -0,0 +1,64 @@ +/* Copyright (C) 2019-2020 |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/>. */ + +#ifndef TEST_SG3_UTILS2_H +#define TEST_SG3_UTILS2_H + +#include <rsys/double3.h> +#include <star/s3dut.h> + +struct s3dut_context { + struct s3dut_mesh_data data; + struct context ctx; +}; + +static INLINE void +get_s3dut_indices(const unsigned itri, unsigned ids[3], void* context) +{ + const struct s3dut_context* ctx = context; + ASSERT(ids && ctx); + ASSERT(itri < ctx->data.nprimitives); + ASSERT(ctx->data.indices[itri * 3 + 0] < UINT_MAX + && ctx->data.indices[itri * 3 + 1] < UINT_MAX + && ctx->data.indices[itri * 3 + 2] < UINT_MAX); + ids[0] = (unsigned)ctx->data.indices[itri * 3 + 0]; + ids[ctx->ctx.reverse_vrtx ? 2 : 1] = (unsigned)ctx->data.indices[itri * 3 + 1]; + ids[ctx->ctx.reverse_vrtx ? 1 : 2] = (unsigned)ctx->data.indices[itri * 3 + 2]; +} + +static INLINE void +get_s3dut_position(const unsigned ivert, double pos[3], void* context) +{ + const struct s3dut_context* ctx = context; + double tmp[3]; + ASSERT(pos && ctx); + ASSERT(ivert < ctx->data.nvertices); + (void)ivert; + d3_add(pos, d3_muld(tmp, ctx->data.positions + ivert * 3, ctx->ctx.scale), + ctx->ctx.offset); +} + +static INLINE void +get_s3dut_properties(const unsigned itri, unsigned property[3], void* context) +{ + const struct s3dut_context* ctx = context; + ASSERT(property && ctx); + (void)itri; + property[ctx->ctx.reverse_med ? SG3_BACK : SG3_FRONT] = *ctx->ctx.front_media; + property[ctx->ctx.reverse_med ? SG3_FRONT : SG3_BACK] = *ctx->ctx.back_media; + property[SG3_INTFACE] = *ctx->ctx.intface; +} + +#endif /* TEST_SG3_UTILS2_H */