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