test_sg2d_invalid_models.c (2680B)
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 19 #include <rsys/double3.h> 20 21 #include <stdio.h> 22 23 static const double 24 square_vertices2[4/*#vertices*/ * 2/*#coords per vertex*/] = { 25 0.0, 0.0, 26 2.0, 0.0, 27 0.0, 1.0, 28 2.0, 1.0 29 }; 30 31 int 32 main(int argc, char** argv) 33 { 34 struct mem_allocator allocator; 35 struct sg2d_device* dev; 36 struct sg2d_geometry* geom; 37 struct context ctx = CONTEXT_NULL__; 38 struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__; 39 unsigned count; 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_properties = get_properties; 49 callbacks.get_position = get_position; 50 51 ctx.positions = square_vertices; 52 ctx.indices = box_indices; 53 ctx.front_media = medium0; 54 ctx.back_media = medium1; 55 ctx.intface = intface0; 56 57 /* First square (front: 0, back: 1), right-handed normal outside */ 58 OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx)); 59 60 ctx.positions = square_vertices2; 61 62 /* Second square (front: 0, back: 1), right-handed normal outside 63 * Some segments are indentical and others longer than first square segments */ 64 OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx)); 65 66 OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count)); 67 CHK(count == 0); 68 OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count)); 69 CHK(count == 0); 70 OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count)); 71 CHK(count == 0); 72 OK(sg2d_geometry_dump_as_c_code(geom, stdout, "invalid", 73 SG2D_C_DUMP_CONST | SG2D_C_DUMP_STATIC)); 74 75 SG2D(geometry_ref_put(geom)); 76 77 check_memory_allocator(&allocator); 78 mem_shutdown_proxy_allocator(&allocator); 79 CHK(mem_allocated_size() == 0); 80 return 0; 81 }