commit 9d764a6e73f88e317d3fd049e41fa7714d140b81
parent 788fdfee10de11d63a0e0ebe92b807b58bbd7dfb
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 5 Feb 2020 11:39:46 +0100
Add some cross dimension helper functions
Diffstat:
4 files changed, 97 insertions(+), 18 deletions(-)
diff --git a/src/sg2_geometry.h b/src/sg2_geometry.h
@@ -258,7 +258,7 @@ struct sg2_geometry {
* Local functions
******************************************************************************/
-extern res_T
+extern LOCAL_SYM res_T
geometry_register_segment
(struct sg2_geometry* geometry,
const struct segment* segment,
@@ -267,7 +267,7 @@ geometry_register_segment
const int merge_conflict);
/* Add new undefined segment descriptions to a geometry */
-extern res_T
+extern LOCAL_SYM res_T
geometry_enlarge_seg_descriptions
(struct sg2_geometry* geom,
const size_t sz);
diff --git a/src/sg2_s2d_helper.h b/src/sg2_s2d_helper.h
@@ -13,8 +13,8 @@
* 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 SG2_SENC_HELPER_H__
-#define SG2_SENC_HELPER_H__
+#ifndef SG2_SENC_2D_HELPER_H__
+#define SG2_SENC_2D_HELPER_H__
#include "sg2.h"
#include <star/senc2d.h>
@@ -26,9 +26,9 @@
* Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices
* calls. */
static FINLINE void
-sg2_s2d_geometry_get_indices__
+sg2_s2d_geometry_get_indices
(const unsigned iseg,
- unsigned indices[2],
+ unsigned indices[SG2_GEOMETRY_DIMENSION],
void* ctx)
{
const struct sg2_geometry* geometry = ctx;
@@ -42,9 +42,9 @@ sg2_s2d_geometry_get_indices__
* Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage
* in s2d_mesh_setup_indexed_vertices calls. */
static FINLINE void
-sg2_s2d_geometry_get_position__
+sg2_s2d_geometry_get_position
(const unsigned ivert,
- float coord[2],
+ float coord[SG2_GEOMETRY_DIMENSION],
void* ctx)
{
const struct sg2_geometry* geometry = ctx;
@@ -58,4 +58,4 @@ sg2_s2d_geometry_get_position__
END_DECLS
-#endif /* SG2_SENC_HELPER_H__ */
+#endif /* SG2_SENC_2D_HELPER_H__ */
diff --git a/src/sg2_senc2d_helper.h b/src/sg2_senc2d_helper.h
@@ -13,8 +13,8 @@
* 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 SG2_SENC_HELPER_H__
-#define SG2_SENC_HELPER_H__
+#ifndef SG2_SENC_2D_HELPER_H__
+#define SG2_SENC_2D_HELPER_H__
#include "sg2.h"
#include <star/senc2d.h>
@@ -24,9 +24,9 @@
/* Get vertex indices for the iseg_th segment.
* Suitable for use as get_indices callback in senc2d_scene_create calls. */
static FINLINE void
-sg2_senc_geometry_get_indices__
+sg2_senc_geometry_get_indices
(const unsigned iseg,
- unsigned indices[2],
+ unsigned indices[SG2_GEOMETRY_DIMENSION],
void* ctx)
{
const struct sg2_geometry* geometry = ctx;
@@ -39,7 +39,7 @@ sg2_senc_geometry_get_indices__
/* Get vertex indices for the iseg_th segment.
* Suitable for use as get_media callback in senc2d_scene_create calls. */
static FINLINE void
-sg2_senc_geometry_get_media__
+sg2_senc_geometry_get_media
(const unsigned iseg,
unsigned media[2],
void* ctx)
@@ -59,9 +59,9 @@ sg2_senc_geometry_get_media__
/* Get vertex indices for the iseg_th segment.
* Suitable for use as get_position callback in senc2d_scene_create calls. */
static FINLINE void
-sg2_senc_geometry_get_position__
+sg2_senc_geometry_get_position
(const unsigned ivert,
- double coord[2],
+ double coord[SG2_GEOMETRY_DIMENSION],
void* ctx)
{
const struct sg2_geometry* geometry = ctx;
@@ -73,4 +73,4 @@ sg2_senc_geometry_get_position__
END_DECLS
-#endif /* SG2_SENC_HELPER_H__ */
+#endif /* SG2_SENC_2D_HELPER_H__ */
diff --git a/src/sgX2.h b/src/sgX2.h
@@ -17,6 +17,8 @@
#define STAR_GEOMETRY_X_2D_H__
#include <star/sg2.h>
+#include <star/sg2_senc2d_helper.h>
+#include <star/sg2_s2d_helper.h>
#include <rsys/rsys.h>
#include <stdio.h>
@@ -34,8 +36,20 @@
* #endif
*
* Then use the sgX_... types and functions in your code.
+ *
+ * Definitions from sgX2.h and sgX3.h cannot be visible at the same time
+ * as some of them conflict.
*/
+/* Helper macro that asserts if the invocation of the StarGeometry2D function
+ * `Func' returns an error. One should use this macro on StarEnc function calls
+ * for which no explicit error checking is performed. */
+#ifndef NDEBUG
+#define SGX(Func) ASSERT(sgX_ ## Func == RES_OK)
+#else
+#define SGX(Func) sgX_ ## Func
+#endif
+
/* Forward declaration of external opaque data types */
struct logger;
struct mem_allocator;
@@ -400,7 +414,7 @@ sgX_geometry_dump_as_c_code
const char* name_prefix, /* Can be NULL or "" */
const int flags)
{
- return sg2_geometry_dump_as_c_code(geometry, stream, flags);
+ return sg2_geometry_dump_as_c_code(geometry, stream, name_prefix, flags);
}
static FINLINE res_T
@@ -417,6 +431,71 @@ sgX_geometry_ref_put
return sg2_geometry_ref_put(geometry);
}
+/******************************************************************************
+ * StarGeometryXD to StarEnclosuresXD helper.
+ *****************************************************************************/
+
+/* Get vertex indices for the itri_th triangle.
+ * Suitable for use as get_indices callback in senc2d_scene_create calls. */
+static FINLINE void
+sgX_sencX_geometry_get_indices
+ (const unsigned itri,
+ unsigned indices[SGX_GEOMETRY_DIMENSION],
+ void* ctx)
+{
+ sg2_senc_geometry_get_indices(itri, indices, ctx);
+}
+
+/* Get vertex indices for the itri_th triangle.
+ * Suitable for use as get_media callback in senc2d_scene_create calls. */
+static FINLINE void
+sgX_sencX_geometry_get_media
+ (const unsigned itri,
+ unsigned media[2],
+ void* ctx)
+{
+ sg2_senc_geometry_get_media(itri, media, ctx);
+}
+
+/* Get vertex indices for the itri_th triangle.
+ * Suitable for use as get_position callback in senc2d_scene_create calls. */
+static FINLINE void
+sgX_sencX_geometry_get_position
+ (const unsigned ivert,
+ double coord[SGX_GEOMETRY_DIMENSION],
+ void* ctx)
+{
+ sg2_senc_geometry_get_position(ivert, coord, ctx);
+}
+
+/******************************************************************************
+ * StarGeometryXD to StarXD helper.
+ *****************************************************************************/
+
+/* Get vertex indices for the itri_th triangle.
+ * Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices
+ * calls. */
+static FINLINE void
+sgX_sXd_geometry_get_indices
+ (const unsigned itri,
+ unsigned indices[SGX_GEOMETRY_DIMENSION],
+ void* ctx)
+{
+ sg2_s2d_geometry_get_indices(itri, indices, ctx);
+}
+
+/* Get coordinates for the ivert_th vertex.
+ * Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage
+ * in s2d_mesh_setup_indexed_vertices calls. */
+static FINLINE void
+sgX_sXd_geometry_get_position
+ (const unsigned ivert,
+ float coord[SGX_GEOMETRY_DIMENSION],
+ void* ctx)
+{
+ sg2_s2d_geometry_get_position(ivert, coord, ctx);
+}
+
END_DECLS
#endif /* STAR_GEOMETRY_X_2D_H__ */