sg3d_misc.h (2864B)
1 /* Copyright (C) 2019, 2020, 2023, 2024 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifndef SG3D_MISC_H__ 17 #define SG3D_MISC_H__ 18 19 #include <rsys/dynamic_array.h> 20 21 #define LIB_NAME "star-geometry-3d" 22 23 #ifdef NDEBUG 24 #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error; 25 #else 26 #define ERR(Expr) \ 27 if((res = (Expr)) != RES_OK) {\ 28 fprintf(stderr, LIB_NAME":%s: error code set to %d at line %d\n",\ 29 FUNC_NAME, res, __LINE__);\ 30 goto error;\ 31 } 32 #endif 33 34 /* The following types must be defined accordingly with the types 35 * used in sg3d.h */ 36 37 /* Trg IDs use the same type than Side IDs */ 38 typedef unsigned trg_id_t; 39 /* TRG_MAX__ is limited to half the max of the base type to allow to count 40 * sides */ 41 #define TRG_MAX__ (UINT_MAX/2) 42 #define TRG_NULL__ UINT_MAX 43 #define PRTF_TRG "%u" 44 #define TRG_TYPE_NAME "unsigned" 45 46 /* Side IDs type use the same base type than Trg IDs */ 47 typedef trg_id_t side_id_t; 48 #define SIDE_MAX__ (2*TRG_MAX__) 49 #define SIDE_NULL__ TRG_NULL__ 50 51 /* Vertex IDs type */ 52 typedef unsigned vrtx_id_t; 53 #define VRTX_MAX__ (UINT_MAX-1) 54 #define VRTX_NULL__ UINT_MAX 55 #define PRTF_VRTX "%u" 56 #define VRTX_TYPE_NAME "unsigned" 57 58 #define DARRAY_NAME vertice_ids 59 #define DARRAY_DATA vrtx_id_t 60 #include <rsys/dynamic_array.h> 61 62 /* Property IDs type. 63 * Cannot be larger than unsigned, as the API uses it. */ 64 typedef unsigned prop_id_t; 65 #define PROP_MAX__ (UINT_MAX-1) /* MAX is for unspecified medium */ 66 #define PROP_NULL__ UINT_MAX 67 #define PRTF_PROP "%u" 68 #define PROP_TYPE_NAME "unsigned" 69 70 #if (PROP_MAX__+1 != SG3D_UNSPECIFIED_PROPERTY) 71 #error "Inconsistant values" 72 #endif 73 74 /* Types of the callbacks. 75 * Provided callbacks are cast into these types to avoid arguments cast 76 * and to check types coherency */ 77 typedef void(*get_indices_t) (const trg_id_t, prop_id_t*, void*); 78 typedef void(*get_properties_t) (const trg_id_t, prop_id_t*, void*); 79 typedef void(*get_position_t) (const vrtx_id_t, double*, void*); 80 typedef res_T(*add_triangle_t) (const trg_id_t, const trg_id_t, void*); 81 typedef res_T(*merge_triangle_t) 82 (const trg_id_t, const trg_id_t, const int, prop_id_t*, const prop_id_t*, 83 void*, int*); 84 typedef res_T(*degenerated_triangle_t) (const trg_id_t, void*, int*); 85 86 #endif /* SG3D_MISC_H__ */