test_polygon1.c (2123B)
1 /* Copyright (C) 2014-2017, 2021-2023 Vincent Forest (vaplv@free.fr) 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 "polygon.h" 17 #include "test_polygon_utils.h" 18 #include <rsys/mem_allocator.h> 19 20 int 21 main(int argc, char** argv) 22 { 23 struct mem_allocator allocator_proxy; 24 struct polygon* poly; 25 union { uint32_t i; float f; } ucast; 26 float pos[3] = {0, 0, 0}; 27 const uint32_t* ids; 28 uint32_t nids; 29 (void)argc, (void)argv; 30 31 CHK(mem_init_proxy_allocator(&allocator_proxy, &mem_default_allocator) == RES_OK); 32 33 CHK(polygon_create(&allocator_proxy, &poly) == RES_OK); 34 35 pos[0] = (ucast.i = 0xbeb504f3, ucast.f); 36 pos[1] = (ucast.i = 0x3eb504f3, ucast.f); 37 CHK(polygon_vertex_add(poly, pos) == RES_OK); 38 pos[0] = (ucast.i = 0xbe977d76, ucast.f); 39 pos[1] = (ucast.i = 0x3ec14031, ucast.f); 40 CHK(polygon_vertex_add(poly, pos) == RES_OK); 41 pos[0] = (ucast.i = 0xbe5dab96, ucast.f); 42 pos[1] = (ucast.i = 0x3f05ca33, ucast.f); 43 CHK(polygon_vertex_add(poly, pos) == RES_OK); 44 pos[0] = (ucast.i = 0xbecccbef, ucast.f); 45 pos[1] = (ucast.i = 0x3ecccbef, ucast.f); 46 CHK(polygon_vertex_add(poly, pos) == RES_OK); 47 pos[0] = (ucast.i = 0xbeb504f3, ucast.f); 48 pos[1] = (ucast.i = 0x3eb504f3, ucast.f); 49 CHK(polygon_vertex_add(poly, pos) == RES_OK); 50 51 CHK(polygon_triangulate(poly, &ids, &nids) == RES_OK); 52 CHK(nids == 6); 53 CHK(polygon_ref_put(poly) == RES_OK); 54 55 check_memory_allocator(&allocator_proxy); 56 mem_shutdown_proxy_allocator(&allocator_proxy); 57 CHK(mem_allocated_size() == 0); 58 return 0; 59 }