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_sXd_helper.h (2042B)


      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_S2D_HELPER_H__
     17 #define SG2D_S2D_HELPER_H__
     18 
     19 #include "sg2d.h"
     20 #include <star/senc2d.h>
     21 
     22 #include <rsys/rsys.h>
     23 
     24 #include <limits.h>
     25 
     26 /* Get vertex indices for the iseg_th segment.
     27  * Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices
     28  * calls. */
     29 static FINLINE void
     30 sg2d_sXd_geometry_get_indices
     31   (const unsigned iseg,
     32    unsigned indices[SG2D_GEOMETRY_DIMENSION],
     33    void* ctx)
     34 {
     35   const struct sg2d_geometry* geometry = ctx;
     36   int i;
     37   size_t tmp[SG2D_GEOMETRY_DIMENSION];
     38   ASSERT(indices && geometry);
     39   SG2D(geometry_get_unique_segment_vertices(geometry, iseg, tmp));
     40   FOR_EACH(i, 0, SG2D_GEOMETRY_DIMENSION) {
     41     ASSERT(tmp[i] <= UINT_MAX);
     42     indices[i] = (unsigned)tmp[i];
     43   }
     44 }
     45 
     46 /* Get coordinates for the ivert_th vertex.
     47  * Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage
     48  * in s2d_mesh_setup_indexed_vertices calls. */
     49 static FINLINE void
     50 sg2d_sXd_geometry_get_position
     51   (const unsigned ivert,
     52    float coord[SG2D_GEOMETRY_DIMENSION],
     53    void* ctx)
     54 {
     55   const struct sg2d_geometry* geometry = ctx;
     56   double tmp[SG2D_GEOMETRY_DIMENSION];
     57   int i;
     58   ASSERT(coord && geometry);
     59   SG2D(geometry_get_unique_vertex(geometry, ivert, tmp));
     60   FOR_EACH(i, 0, SG2D_GEOMETRY_DIMENSION) coord[i] = (float)tmp[i];
     61 }
     62 
     63 #endif /* SG2D_S2D_HELPER_H__ */