star-geometry-2d

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

test_sg2d_utils2.h (2326B)


      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 TEST_SG2D_UTILS2_H
     17 #define TEST_SG2D_UTILS2_H
     18 
     19 #include <rsys/stretchy_array.h>
     20 
     21 /******************************************************************************
     22  * Circle functions
     23  *****************************************************************************/
     24 static INLINE void
     25 create_circle
     26   (const double radius,
     27    const unsigned nslices,
     28    struct context* ctx)
     29 {
     30   double step_theta;
     31   unsigned itheta;
     32   unsigned islice;
     33   double* d = NULL;
     34   unsigned* u = NULL;
     35   ASSERT(radius > 0 && nslices >= 3 && ctx);
     36 
     37   step_theta = 2 * PI / (double)nslices;
     38   FOR_EACH(itheta, 0, nslices) {
     39     const double theta = (double)itheta * step_theta;
     40     const double x = cos(theta);
     41     const double y = sin(theta);
     42     sa_push(d, x * radius);
     43     sa_push(d, y * radius);
     44   }
     45   ctx->positions = d;
     46 
     47   FOR_EACH(islice, 0, nslices) {
     48     const unsigned v0 = islice;
     49     const unsigned v1 = ((islice + 1) % nslices);
     50     sa_push(u, v0);
     51     sa_push(u, v1);
     52   }
     53   ctx->indices = u;
     54 }
     55 
     56 static INLINE void
     57 circle_release(struct context* ctx)
     58 {
     59   ASSERT(ctx);
     60   sa_release(ctx->positions);
     61   sa_release(ctx->indices);
     62   ctx->positions = NULL;
     63   ctx->indices = NULL;
     64 }
     65 
     66 static INLINE void
     67 get_uniform_properties
     68   (const unsigned iseg,
     69     unsigned property[SG2D_PROP_TYPES_COUNT__],
     70    void* context)
     71 {
     72   const struct context* ctx = context;
     73   ASSERT(property && ctx); (void)iseg;
     74   property[ctx->reverse_med ? SG2D_BACK : SG2D_FRONT] = *ctx->front_media;
     75   property[ctx->reverse_med ? SG2D_FRONT : SG2D_BACK] = *ctx->back_media;
     76   property[SG2D_INTFACE] = *ctx->intface;
     77 }
     78 
     79 #endif /* TEST_SG2D_UTILS2_H */