polygon

Polygon triangulation
git clone git://git.meso-star.fr/polygon.git
Log | Files | Refs | README | LICENSE

polygon.h (2251B)


      1 /* Copyright (C) 2014-2017, 2021-2023 Vincent Forest (vaplv@free.fr)
      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 POLYGON_H
     17 #define POLYGON_H
     18 
     19 #include <rsys/rsys.h>
     20 
     21 #ifdef POLYGON_SHARED_BUILD
     22   #define POLYGON_API extern EXPORT_SYM
     23 #elif defined(POLYGON_STATIC_BUILD)
     24   #define POLYGON_API extern LOCAL_SYM
     25 #else
     26   #define POLYGON_API extern IMPORT_SYM
     27 #endif
     28 
     29 #ifndef NDEBUG
     30   #define POLYGON(Func) ASSERT(polygon_##Func == RES_OK)
     31 #else
     32   #define POLYGON(Func) polygon_##Func
     33 #endif
     34 
     35 struct mem_allocator;
     36 struct polygon;
     37 
     38 BEGIN_DECLS
     39 
     40 POLYGON_API res_T
     41 polygon_create
     42   (struct mem_allocator* allocator, /* May be NULL <=> default allocator */
     43    struct polygon** polygon);
     44 
     45 POLYGON_API res_T
     46 polygon_ref_get
     47   (struct polygon* polygon);
     48 
     49 POLYGON_API res_T
     50 polygon_ref_put
     51   (struct polygon* polygon);
     52 
     53 POLYGON_API res_T
     54 polygon_clear
     55   (struct  polygon* polygon);
     56 
     57 /* Append a vertex to the polygon contour. Note that this vertex may replace
     58  * the previous one if it is aligned with the two last ones */
     59 POLYGON_API res_T
     60 polygon_vertex_add
     61   (struct polygon* polygon,
     62    const float pos[3]);
     63 
     64 POLYGON_API res_T
     65 polygon_vertices_count_get
     66   (const struct polygon* polygon,
     67    uint32_t* nvertices);
     68 
     69 POLYGON_API res_T
     70 polygon_vertex_get
     71   (const struct polygon* polygon,
     72    const uint32_t ivertex,
     73    float position[3]);
     74 
     75 /* This function assumes that the polygon vertices lie on the same plane and
     76  * that they define a unique contour that is not intersected itself */
     77 POLYGON_API res_T
     78 polygon_triangulate
     79   (struct polygon* polygon,
     80    const uint32_t** indices,
     81    uint32_t* indices_count);
     82 
     83 END_DECLS
     84 
     85 #endif /* POLYGON_H */
     86