star-geometry-2d

Cleaning and decorating 2D geometries
git clone git://git.meso-star.fr/star-geometry-2d.git
Log | Files | Refs | README | LICENSE

sg2d_misc.h (2611B)


      1 /* Copyright (C) 2019, 2020, 2023 |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 SG2D_MISC_H__
     17 #define SG2D_MISC_H__
     18 
     19 #include <rsys/dynamic_array.h>
     20 
     21 #define ERR(Expr) if((res = (Expr)) != RES_OK) goto error;
     22 
     23 /* The following types must be defined accordingly with the types
     24  * used in sg2d.h */
     25 
     26 /* Seg IDs use the same type than Side IDs */
     27 typedef unsigned seg_id_t;
     28 /* SEG_MAX__ is limited to half the max of the base type to allow to count
     29 * sides */
     30 #define SEG_MAX__ (UINT_MAX/2)
     31 #define SEG_NULL__ UINT_MAX
     32 #define PRTF_SEG "%u"
     33 #define SEG_TYPE_NAME "unsigned"
     34 
     35 /* Side IDs type  use the same base type than Seg IDs */
     36 typedef seg_id_t side_id_t;
     37 #define SIDE_MAX__ (2*SEG_MAX__)
     38 #define SIDE_NULL__ SEG_NULL__
     39 
     40 /* Vertex IDs type */
     41 typedef unsigned vrtx_id_t;
     42 #define VRTX_MAX__ (UINT_MAX-1)
     43 #define VRTX_NULL__ UINT_MAX
     44 #define PRTF_VRTX "%u"
     45 #define VRTX_TYPE_NAME "unsigned"
     46 
     47 #define DARRAY_NAME vertice_ids
     48 #define DARRAY_DATA vrtx_id_t
     49 #include <rsys/dynamic_array.h>
     50 
     51 /* Property IDs type.
     52  * Cannot be larger than unsigned, as the API uses it. */
     53 typedef unsigned prop_id_t;
     54 #define PROP_MAX__ (UINT_MAX-1) /* MAX is for unspecified medium */
     55 #define PROP_NULL__ UINT_MAX
     56 #define PRTF_PROP "%u"
     57 #define PROP_TYPE_NAME "unsigned"
     58 
     59 #if (PROP_MAX__+1 != SG2D_UNSPECIFIED_PROPERTY)
     60 #error "Inconsistant values"
     61 #endif
     62 
     63 /* Types of the callbacks.
     64  * Provided callbacks are cast into these types to avoid arguments cast
     65  * and to check types coherency */
     66 typedef void(*get_indices_t) (const seg_id_t, prop_id_t*, void*);
     67 typedef void(*get_properties_t) (const seg_id_t, prop_id_t*, void*);
     68 typedef void(*get_position_t) (const vrtx_id_t, double*, void*);
     69 typedef res_T(*add_segment_t) (const seg_id_t, const seg_id_t, void*);
     70 typedef res_T(*merge_segment_t)
     71   (const seg_id_t, const seg_id_t, const int, prop_id_t*, const prop_id_t*,
     72    void*, int*);
     73 typedef res_T(*degenerated_segment_t) (const seg_id_t, void*, int*);
     74 
     75 #endif /* SG2D_MISC_H__ */