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_square_in_square.c (4074B)


      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 
     19 #include <rsys/double2.h>
     20 
     21 #include <stdio.h>
     22 
     23 /*
     24            square_2                            square_3
     25 
     26                                       +-------------------------+
     27                                       |                         B
     28         +-------------+               |     +-------------+     |
     29      m1 |     m0      M            m1 |  m1 |      m0     M     |
     30         | +------+    |               | m0  | +------+    |     |
     31         | |  m1  S    |               |     | |  m1  S    |     |
     32         | | N <--|    |               |     | | N <--|    |     |
     33         | +------+    |               |     | +------+    |     |
     34         |        N <--|               |     |        N <--|     |
     35         +-------------+               |     +-------------+     |
     36                                       |                    N <--|
     37                                       +-------------------------+
     38  */
     39 
     40 int
     41 main(int argc, char** argv)
     42 {
     43   struct mem_allocator allocator;
     44   struct sg2d_device* dev;
     45   struct sg2d_geometry* geom;
     46   struct context ctx = CONTEXT_NULL__;
     47   struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__;
     48   unsigned count;
     49   (void)argc, (void)argv;
     50 
     51   OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator));
     52   OK(sg2d_device_create(NULL, &allocator, 1, &dev));
     53   OK(sg2d_geometry_create(dev, &geom));
     54   SG2(device_ref_put(dev));
     55 
     56   callbacks.get_indices = get_indices;
     57   callbacks.get_properties = get_properties;
     58   callbacks.get_position = get_position;
     59 
     60   ctx.positions = box_vertices;
     61   ctx.indices = box_indices;
     62   ctx.front_media = medium0;
     63   ctx.back_media = medium1;
     64   ctx.intface = intface0;
     65 
     66   /* First square (front: 0, back: 1), right-handed normal outside */
     67   OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx));
     68 
     69   d2(ctx.offset, -1, -1);
     70   ctx.scale = 3;
     71   ctx.reverse_vrtx = 1;
     72 
     73   /* Second square (front: 0, back: 1), right-handed normal inside */
     74   OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx));
     75 
     76   OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count));
     77   CHK(count == 0);
     78   OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count));
     79   CHK(count == 0);
     80   OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count));
     81   CHK(count == 0);
     82   OK(sg2d_geometry_dump_as_c_code(geom, stdout, "square_in_square_2",
     83     SG2D_C_DUMP_CONST | SG2D_C_DUMP_STATIC));
     84 
     85   d2(ctx.offset, -4, -4);
     86   ctx.scale = 10;
     87   ctx.reverse_vrtx = 1;
     88   ctx.reverse_med = 1;
     89   ctx.front_media = medium1;
     90   ctx.back_media = medium0;
     91 
     92   /* Third square (front: 0, back: 1), right-handed normal inside */
     93   OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx));
     94 
     95   OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count));
     96   CHK(count == 0);
     97   OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count));
     98   CHK(count == 0);
     99   OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count));
    100   CHK(count == 0);
    101   OK(sg2d_geometry_dump_as_c_code(geom, stdout, "square_in_square_3",
    102     SG2D_C_DUMP_CONST | SG2D_C_DUMP_STATIC));
    103 
    104   SG2(geometry_ref_put(geom));
    105 
    106   check_memory_allocator(&allocator);
    107   mem_shutdown_proxy_allocator(&allocator);
    108   CHK(mem_allocated_size() == 0);
    109   return 0;
    110 }