star-geometry-2d

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

sg2_s2d_helper.h (1927B)


      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_SENC_2D_HELPER_H__
     17 #define SG2D_SENC_2D_HELPER_H__
     18 
     19 #include "sg2.h"
     20 #include <star/senc2d.h>
     21 
     22 #include <rsys/rsys.h>
     23 #include <rsys/float2.h>
     24 
     25 /* Get vertex indices for the iseg_th segment.
     26  * Suitable for use as get_indice callback in s2d_mesh_setup_indexed_vertices
     27  * calls. */
     28 static FINLINE void
     29 sg2d_s2d_geometry_get_indices
     30   (const unsigned iseg,
     31    unsigned indices[SG2D_GEOMETRY_DIMENSION],
     32    void* ctx)
     33 {
     34   const struct sg2d_geometry* geometry = ctx;
     35   res_T r;
     36   ASSERT(indices && geometry);
     37   r = sg2d_geometry_get_unique_segment_vertices(geometry, iseg, indices);
     38   ASSERT(r == RES_OK); (void)r;
     39 }
     40 
     41 /* Get coordinates for the ivert_th vertex.
     42  * Suitable for use as s2d_vertex_data getter for S2D_POSITION s2d_attrib_usage
     43  * in s2d_mesh_setup_indexed_vertices calls. */
     44 static FINLINE void
     45 sg2d_s2d_geometry_get_position
     46   (const unsigned ivert,
     47    float coord[SG2D_GEOMETRY_DIMENSION],
     48    void* ctx)
     49 {
     50   const struct sg2d_geometry* geometry = ctx;
     51   double tmp[2];
     52   res_T r;
     53   ASSERT(coord && geometry);
     54   r = sg2d_geometry_get_unique_vertex(geometry, ivert, tmp);
     55   ASSERT(r == RES_OK); (void)r;
     56   f2_set_d2(coord, tmp);
     57 }
     58 
     59 END_DECLS
     60 
     61 #endif /* SG2D_SENC_2D_HELPER_H__ */