test_senc3d_bad_grouping3.c (7416B)
1 /* Copyright (C) 2018-2020, 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 sg3_geometry_dump_as_C_code feature 17 * of star-geometry. It uses a star-cad scene that crashed. */ 18 19 #include "senc3d.h" 20 #include "test_senc3d_utils.h" 21 22 #include <rsys/double3.h> 23 24 #include <stdio.h> 25 26 /* 27 * +-------------+ 28 * | | 29 * | + | 30 * | /|\ | 31 * | / | \ | 32 * | + | + | 33 * | | | | | 34 * | | | | | 35 * | +--+--+ | 36 * | | 37 * +-------------+ 38 */ 39 40 static const unsigned bad3_vertices_count = 24; 41 static const double bad3_vertices[72] = 42 { 43 0, 10, 10, 44 0, 0, 0, 45 0, 0, 10, 46 0, 10, 0, 47 10, 10, 10, 48 10, 0, 10, 49 10, 0, 0, 50 10, 10, 0, 51 52 1, 5, 5, 53 1, 1, 1, 54 1, 1, 5, 55 1, 5, 1, 56 5, 5, 6, 57 5, 1, 6, 58 5, 1, 1, 59 5, 5, 1, 60 61 5, 5, 6.12, /* Duplicate, use #12 instead */ 62 5, 1, 1.14, /* Duplicate, use #14 instead */ 63 5, 1, 6.13, /* Duplicate, use #13 instead */ 64 5, 5, 1.15, /* Duplicate, use #15 instead */ 65 9, 5, 5, 66 9, 1, 5, 67 9, 1, 1, 68 9, 5, 1 69 }; 70 unsigned bad3_triangles_count = 34; 71 unsigned bad3_triangles[582] = 72 { 73 0, 1, 2, 74 0, 3, 1, 75 4, 5, 6, 76 4, 6, 7, 77 6, 2, 1, 78 5, 2, 6, 79 7, 3, 0, 80 4, 7, 0, 81 3, 6, 1, 82 7, 6, 3, 83 0, 2, 5, 84 4, 0, 5, 85 86 8, 9, 10, 87 8, 11, 9, 88 12, 13, 14, 89 12, 14, 15, 90 14, 10, 9, 91 13, 10, 14, 92 15, 11, 8, 93 12, 15, 8, 94 11, 14, 9, 95 15, 14, 11, 96 8, 10, 13, 97 12, 8, 13, 98 99 /* 12, 14, 13, */ /* Duplicate */ 100 /* 12, 15, 14, */ /* Duplicate */ 101 20, 21, 22, 102 20, 22, 23, 103 22, 13, 14, 104 21, 13, 22, 105 23, 15, 12, 106 20, 23, 12, 107 15, 22, 14, 108 23, 22, 15, 109 12, 13, 21, 110 20, 12, 21 111 }; 112 unsigned bad3_properties[102] = 113 { 114 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 115 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 116 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 117 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 118 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 119 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 120 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 121 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 122 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 123 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 124 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 125 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 126 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 127 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 128 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 129 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 130 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 131 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 132 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 133 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 134 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 135 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 136 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 137 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 138 /* SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, */ 139 /* SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, */ 140 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 141 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 142 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 143 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 144 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 145 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 146 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 147 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 148 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, 149 SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM, SENC3D_UNSPECIFIED_MEDIUM 150 }; 151 152 int 153 main(int argc, char** argv) 154 { 155 struct mem_allocator allocator; 156 struct senc3d_device* dev = NULL; 157 struct senc3d_scene* scn = NULL; 158 struct context ctx = CONTEXT_NULL__; 159 unsigned count, e; 160 const double volumes[] = { -1000, 856, 72, 72}; 161 int volume_used[] = {0, 0, 0, 0}; 162 (void)argc, (void)argv; 163 164 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 165 OK(senc3d_device_create(NULL, &allocator, SENC3D_NTHREADS_DEFAULT, 1, &dev)); 166 167 /* Create a scene with the cubes. 168 * The enclosures in the small cubes contain medium 0, the external enclosure 169 * contains medium 2, the enclosure between the small and big cubes 170 * contains medium 1. */ 171 ctx.positions = bad3_vertices; 172 ctx.indices = bad3_triangles; 173 ctx.properties = bad3_properties; 174 OK(senc3d_scene_create(dev, 175 SENC3D_CONVENTION_NORMAL_BACK | SENC3D_CONVENTION_NORMAL_OUTSIDE, 176 bad3_triangles_count, get_indices, get_media_from_properties, 177 bad3_vertices_count, get_position, &ctx, &scn)); 178 179 OK(senc3d_scene_get_vertices_count(scn, &count)); 180 CHK(count == bad3_vertices_count); 181 182 OK(senc3d_scene_get_triangles_count(scn, &count)); 183 CHK(count == bad3_triangles_count); 184 185 OK(senc3d_scene_get_enclosure_count(scn, &count)); 186 CHK(count == 4); 187 FOR_EACH(e, 0, count) { 188 struct senc3d_enclosure* enclosure; 189 struct senc3d_enclosure_header header; 190 size_t i; 191 int found = 0; 192 OK(senc3d_scene_get_enclosure(scn, e, &enclosure)); 193 OK(senc3d_enclosure_get_header(enclosure, &header)); 194 OK(senc3d_enclosure_ref_put(enclosure)); 195 for(i = 0; i < sizeof(volumes)/sizeof(*volumes); i++) { 196 if(!volume_used[i] && fabs(volumes[i] - header.volume) < DBL_EPSILON) { 197 volume_used[i] = 1; 198 found = 1; 199 break; 200 } 201 } 202 if(!found) return 1; 203 } 204 205 OK(senc3d_scene_ref_put(scn)); 206 OK(senc3d_device_ref_put(dev)); 207 208 check_memory_allocator(&allocator); 209 mem_shutdown_proxy_allocator(&allocator); 210 CHK(mem_allocated_size() == 0); 211 return 0; 212 }