test_senc2d_square_behind_square.c (6649B)
1 /* Copyright (C) 2018-2021, 2023, 2024 |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 /* This test has been created using the sg2_geometry_dump_as_C_code feature 17 * of star-geometry-2D. It uses output from test_sg2_square_behind_square. */ 18 19 #include "senc2d.h" 20 #include "test_senc2d_utils.h" 21 22 #include <rsys/double2.h> 23 24 /* 25 cube_2 cube_3 26 27 +-----------------------+ 28 | 3 29 | | 30 m1 | m0 | 31 | | 32 | | 33 | | 34 | |--> N 35 | | 36 | | 37 +-----------------------+ 38 +------------+ +------------+ 39 | 2 | 2 40 m0 | m1 | m0 | m1 | 41 | | | | 42 | |--> N | |--> N 43 | | | | 44 +------------+ +------------+ 45 +-----+ +-----+ 46 m0 | m1 1 m0 | m1 1 47 | |--> N | |--> N 48 +-----+ +-----+ 49 */ 50 51 /* Dump of star-geometry-2D 'square_behind_square_2'. */ 52 static const unsigned square_behind_square_2_vertices_count = 8; 53 static const double square_behind_square_2_vertices[16] = 54 { 55 0.1, 0, 56 1, 0, 57 0, 1.1, 58 1, 1, 59 -0.2, 2, 60 2.5, 2, 61 -0.5, 5.3, 62 2.5, 5 63 }; 64 static const unsigned square_behind_square_2_segments_count = 8; 65 static const unsigned square_behind_square_2_segments[16] = 66 { 67 0, 2, 68 2, 3, 69 3, 1, 70 1, 0, 71 4, 6, 72 6, 7, 73 7, 5, 74 5, 4 75 }; 76 static const unsigned square_behind_square_2_properties[24] = 77 { 78 0, 1, 0, 79 0, 1, 0, 80 0, 1, 0, 81 0, 1, 0, 82 0, 1, 0, 83 0, 1, 0, 84 0, 1, 0, 85 0, 1, 0 86 }; 87 /* Dump of star-geometry-2D 'square_behind_square_3'. */ 88 static const unsigned square_behind_square_3_vertices_count = 12; 89 static const double square_behind_square_3_vertices[24] = 90 { 91 0.1, 0, 92 1, 0, 93 0, 1.1, 94 1, 1, 95 -0.2, 2, 96 2.5, 2, 97 -0.5, 5.3, 98 2.5, 5, 99 -0.5, 6, 100 4, 6, 101 -1, 11.5, 102 4, 11 103 }; 104 static const unsigned square_behind_square_3_segments_count = 12; 105 static const unsigned square_behind_square_3_segments[24] = 106 { 107 0, 2, 108 2, 3, 109 3, 1, 110 1, 0, 111 4, 6, 112 6, 7, 113 7, 5, 114 5, 4, 115 8, 10, 116 10, 11, 117 11, 9, 118 9, 8 119 }; 120 static const unsigned square_behind_square_3_properties[36] = 121 { 122 0, 1, 0, 123 0, 1, 0, 124 0, 1, 0, 125 0, 1, 0, 126 0, 1, 0, 127 0, 1, 0, 128 0, 1, 0, 129 0, 1, 0, 130 1, 0, 0, 131 1, 0, 0, 132 1, 0, 0, 133 1, 0, 0 134 }; 135 136 int 137 main(int argc, char** argv) 138 { 139 struct mem_allocator allocator; 140 struct senc2d_device* dev = NULL; 141 struct senc2d_scene* scn = NULL; 142 struct context ctx = CONTEXT_NULL__; 143 unsigned i, ecount, maxm; 144 (void)argc, (void)argv; 145 146 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 147 OK(senc2d_device_create(NULL, &allocator, SENC2D_NTHREADS_DEFAULT, 1, &dev)); 148 149 /* Create a scene with the first and second squares. 150 * Both squares have medium 1 inside and medium 0 outside, 151 * the second square is +Y from the first square and is big enough 152 * to prevent rays from the first square to miss it. */ 153 ctx.positions = square_behind_square_2_vertices; 154 ctx.indices = square_behind_square_2_segments; 155 ctx.properties = square_behind_square_2_properties; 156 OK(senc2d_scene_create(dev, 157 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 158 square_behind_square_2_segments_count, get_indices, 159 get_media_from_properties, square_behind_square_2_vertices_count, 160 get_position, &ctx, &scn)); 161 162 OK(senc2d_scene_get_enclosure_count(scn, &ecount)); 163 CHK(ecount == 3); 164 165 FOR_EACH(i, 0, ecount) { 166 struct senc2d_enclosure* enclosure; 167 struct senc2d_enclosure_header header; 168 OK(senc2d_scene_get_enclosure(scn, i, &enclosure)); 169 OK(senc2d_enclosure_get_header(enclosure, &header)); 170 ASSERT(header.enclosed_media_count == 1); 171 OK(senc2d_enclosure_ref_put(enclosure)); 172 } 173 174 OK(senc2d_scene_get_max_medium(scn, &maxm)); 175 CHK(maxm == 1); 176 OK(senc2d_scene_ref_put(scn)); 177 178 /* Create a scene with the 3 squares, same 2 first squares as above 179 * The third square has medium 0 inside and medium 1 outside and is further 180 * in +Y and bigger */ 181 ctx.positions = square_behind_square_3_vertices; 182 ctx.indices = square_behind_square_3_segments; 183 ctx.properties = square_behind_square_3_properties; 184 OK(senc2d_scene_create(dev, 185 SENC2D_CONVENTION_NORMAL_FRONT | SENC2D_CONVENTION_NORMAL_INSIDE, 186 square_behind_square_3_segments_count, get_indices, 187 get_media_from_properties, square_behind_square_3_vertices_count, 188 get_position, &ctx, &scn)); 189 190 OK(senc2d_scene_get_enclosure_count(scn, &ecount)); 191 CHK(ecount == 4); 192 193 FOR_EACH(i, 0, ecount) { 194 struct senc2d_enclosure* enclosure; 195 struct senc2d_enclosure_header header; 196 OK(senc2d_scene_get_enclosure(scn, i, &enclosure)); 197 OK(senc2d_enclosure_get_header(enclosure, &header)); 198 /* Inside enclosures contain 1 single media */ 199 ASSERT(header.enclosed_media_count == (header.is_infinite ? 2u : 1u)); 200 OK(senc2d_enclosure_ref_put(enclosure)); 201 } 202 203 OK(senc2d_scene_get_max_medium(scn, &maxm)); 204 CHK(maxm == 1); 205 206 OK(senc2d_scene_ref_put(scn)); 207 OK(senc2d_device_ref_put(dev)); 208 209 check_memory_allocator(&allocator); 210 mem_shutdown_proxy_allocator(&allocator); 211 CHK(mem_allocated_size() == 0); 212 return 0; 213 }