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_sg2_some_segments.c (2858B)


      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 #include "sg2.h"
     17 #include "test_sg2d_utils.h"
     18 #include "test_sg2d_utils2.h"
     19 
     20 #include <rsys/double2.h>
     21 
     22 #include <stdio.h>
     23 #include <limits.h>
     24 
     25 #define NB_CIRC 4
     26 
     27 int
     28 main(int argc, char** argv)
     29 {
     30   struct mem_allocator allocator;
     31   struct sg2d_device* dev;
     32   struct sg2d_geometry* geom;
     33   struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
     34   unsigned circ_seg_count, circ_vrtx_count, i, count;
     35   unsigned m0 = 0, m1, itf = 0;
     36   struct context ctx = CONTEXT_NULL__;
     37   (void)argc, (void)argv;
     38 
     39   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     40   OK(sg2d_device_create(NULL, &allocator, 1, &dev));
     41   OK(sg2d_geometry_create(dev, &geom));
     42   SG2(device_ref_put(dev));
     43 
     44   callbacks.get_indices = get_indices;
     45   callbacks.get_position = get_position;
     46   callbacks.get_properties = get_uniform_properties;
     47 
     48   ctx.front_media = &m1;
     49   ctx.back_media = &m0;
     50   ctx.intface = &itf;
     51 
     52   /* A 264 segments circle template */
     53   create_circle(1, 264, &ctx);
     54   ASSERT(sa_size(ctx.positions) % 2 == 0
     55     && sa_size(ctx.positions) / 2 < UINT_MAX);
     56   ASSERT(sa_size(ctx.indices) % 2 == 0
     57     && sa_size(ctx.indices) / 2 < UINT_MAX);
     58   circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
     59   circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
     60 
     61   OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
     62     NB_CIRC * circ_seg_count, 0));
     63   FOR_EACH(i, 0, NB_CIRC) {
     64     m1 = i;
     65     d2(ctx.offset, 0, i * 10);
     66     OK(sg2d_geometry_add(geom, circ_vrtx_count, circ_seg_count, &callbacks,
     67       &ctx));
     68   }
     69   circle_release(&ctx);
     70 
     71   OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count));
     72   CHK(count == 0);
     73   OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count));
     74   CHK(count == 0);
     75   OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count));
     76   CHK(count == 0);
     77 
     78   OK(sg2d_geometry_dump_as_c_code(geom, stdout, "some_segments",
     79     SG2D_C_DUMP_CONST | SG2D_C_DUMP_STATIC));
     80 
     81   SG2(geometry_ref_put(geom));
     82 
     83   check_memory_allocator(&allocator);
     84   mem_shutdown_proxy_allocator(&allocator);
     85   CHK(mem_allocated_size() == 0);
     86   return 0;
     87 }