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_many_enclosures.c (3538B)


      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_X 32
     26 #define NB_CIRC_Y 32
     27 #define NB_CIRC_Z 64
     28 #define NB_CIRC (NB_CIRC_X * NB_CIRC_Y * NB_CIRC_Z)
     29 
     30 int
     31 main(int argc, char** argv)
     32 {
     33   struct mem_allocator allocator;
     34   struct sg2d_device* dev;
     35   struct sg2d_geometry* geom;
     36   struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
     37   unsigned circ_seg_count, circ_vrtx_count, count;
     38   int i, j, k;
     39   unsigned m_in, m_out, itf = 0;
     40   struct context ctx = CONTEXT_NULL__;
     41   (void)argc, (void)argv;
     42 
     43   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     44   OK(sg2d_device_create(NULL, &allocator, 1, &dev));
     45   OK(sg2d_geometry_create(dev, &geom));
     46   SG2(device_ref_put(dev));
     47 
     48   callbacks.get_indices = get_indices;
     49   callbacks.get_position = get_position;
     50   callbacks.get_properties = get_uniform_properties;
     51 
     52   ctx.front_media = &m_in;
     53   ctx.back_media = &m_out;
     54   ctx.intface = &itf;
     55 
     56   /* A 16 segments circle template */
     57   create_circle(1, 16, &ctx);
     58   ASSERT(sa_size(ctx.positions) % 2 == 0
     59     && sa_size(ctx.positions) / 2 < UINT_MAX);
     60   ASSERT(sa_size(ctx.indices) % 2 == 0
     61     && sa_size(ctx.indices) / 2 < UINT_MAX);
     62   circ_seg_count = (unsigned)sa_size(ctx.indices) / 2;
     63   circ_vrtx_count = (unsigned)sa_size(ctx.positions) / 2;
     64   OK(sg2d_geometry_reserve(geom, NB_CIRC * circ_vrtx_count,
     65     NB_CIRC * circ_seg_count, 0));
     66   FOR_EACH(i, 0, NB_CIRC_X) {
     67     double center_x = 2 * (1 + NB_CIRC_Z) * (i - NB_CIRC_X / 2);
     68     FOR_EACH(j, 0, NB_CIRC_Y) {
     69       double center_y = 2 * (1 + NB_CIRC_Z) * (j - NB_CIRC_Y / 2);
     70       double misalignment = 0;
     71       FOR_EACH(k, 0, NB_CIRC_Z) {
     72         m_in = (unsigned)k;
     73         m_out = (unsigned)(k + 1);
     74         ctx.scale = k + 1;
     75 #ifdef MITIGATE_EMBREE_181
     76         /* Mitigate Embree issue #181
     77          * We cannot keep perfect alignment of circles
     78          * or some hits are missed in some raytracing tasks */
     79         misalignment = (k % 2) ? -0.01 : +0.01;
     80 #endif
     81         d2(ctx.offset, center_x + misalignment, center_y + misalignment);
     82         OK(sg2d_geometry_add(geom, circ_vrtx_count, circ_seg_count, &callbacks,
     83           &ctx));
     84       }
     85     }
     86   }
     87   circle_release(&ctx);
     88 
     89   OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count));
     90   CHK(count == 0);
     91   OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count));
     92   CHK(count == 0);
     93   OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count));
     94   CHK(count == 0);
     95   OK(sg2d_geometry_dump_as_obj(geom, stdout, SG2D_OBJ_DUMP_ALL));
     96   
     97   SG2(geometry_ref_put(geom));
     98 
     99   check_memory_allocator(&allocator);
    100   mem_shutdown_proxy_allocator(&allocator);
    101   CHK(mem_allocated_size() == 0);
    102   return 0;
    103 }