test_suvm_utils.h (2177B)
1 /* Copyright (C) 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 #ifndef TEST_SUVM_UTILS_H 17 #define TEST_SUVM_UTILS_H 18 19 #include <rsys/mem_allocator.h> 20 #include <stdlib.h> 21 22 static INLINE float 23 rand_canonic(void) 24 { 25 int r; 26 while((r = rand()) == RAND_MAX); 27 return (float)r / (float)RAND_MAX; 28 } 29 30 static INLINE void 31 dump_volumic_mesh 32 (FILE* stream, 33 const size_t* tetras, 34 const size_t ntetras, 35 const double* pos, 36 const size_t npos) 37 { 38 size_t i; 39 40 FOR_EACH(i, 0, npos) { 41 fprintf(stream, "v %g %g %g\n", 42 pos[i*3+0], 43 pos[i*3+1], 44 pos[i*3+2]); 45 } 46 47 FOR_EACH(i, 0, ntetras) { 48 fprintf(stream, "f %lu %lu %lu\n", 49 (unsigned long)tetras[i*4+0]+1, 50 (unsigned long)tetras[i*4+1]+1, 51 (unsigned long)tetras[i*4+2]+1); 52 fprintf(stream, "f %lu %lu %lu\n", 53 (unsigned long)tetras[i*4+0]+1, 54 (unsigned long)tetras[i*4+3]+1, 55 (unsigned long)tetras[i*4+1]+1); 56 fprintf(stream, "f %lu %lu %lu\n", 57 (unsigned long)tetras[i*4+1]+1, 58 (unsigned long)tetras[i*4+3]+1, 59 (unsigned long)tetras[i*4+2]+1); 60 fprintf(stream, "f %lu %lu %lu\n", 61 (unsigned long)tetras[i*4+2]+1, 62 (unsigned long)tetras[i*4+3]+1, 63 (unsigned long)tetras[i*4+0]+1); 64 } 65 } 66 67 static INLINE void 68 check_memory_allocator(struct mem_allocator* allocator) 69 { 70 if(MEM_ALLOCATED_SIZE(allocator)) { 71 char dump[512]; 72 MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char)); 73 fprintf(stderr, "%s\n", dump); 74 FATAL("Memory leaks\n"); 75 } 76 } 77 78 #endif /* TEST_SUVM_UTILS_H */ 79