test_sg2_square_on_square.c (3335B)
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 "sg2.h" 17 #include "test_sg2d_utils.h" 18 19 #include <rsys/double2.h> 20 21 #include <stdio.h> 22 23 /* 24 +-----------------------+ 25 | 3 26 | +------+ | 27 m2 | m1 | m0 2 | 28 | | |--> N | 29 | +------+ | 30 | | m0 1 | 31 | | |--> N | 32 | +------+ | 33 |--> N | 34 +-----------------------+ 35 */ 36 37 int 38 main(int argc, char** argv) 39 { 40 struct mem_allocator allocator; 41 struct sg2d_device* dev; 42 struct sg2d_geometry* geom; 43 struct context ctx = CONTEXT_NULL__; 44 struct sg2d_geometry_add_callbacks callbacks = SG2D_ADD_CALLBACKS_NULL__; 45 unsigned count; 46 (void)argc, (void)argv; 47 48 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 49 OK(sg2d_device_create(NULL, &allocator, 1, &dev)); 50 OK(sg2d_geometry_create(dev, &geom)); 51 SG2(device_ref_put(dev)); 52 53 callbacks.get_indices = get_indices; 54 callbacks.get_properties = get_properties; 55 callbacks.get_position = get_position; 56 57 ctx.positions = square_vertices; 58 ctx.indices = box_indices; 59 d2(ctx.offset, 1, 1); 60 ctx.front_media = medium1_top0; 61 ctx.back_media = medium0; 62 ctx.intface = intface0; 63 64 /* First square (front: 0 on top face, 1 elsewhere, back: 0), 65 * right-handed normal outside */ 66 OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx)); 67 68 d2(ctx.offset, 1, 2); 69 ctx.front_media = medium1_bottom0; 70 71 /* Second square (front: 0 on bottom face, 1 elsewhere, back: 0), 72 * right-handed normal outside */ 73 OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx)); 74 75 ctx.positions = box_vertices; /* Can use distorded square for square #3 */ 76 d2(ctx.offset, 0, 0); 77 ctx.scale = 4; 78 ctx.reverse_vrtx = 1; 79 ctx.reverse_med = 1; 80 ctx.front_media = medium2; 81 ctx.back_media = medium1; 82 83 /* Third square (front: 2, back: 1), right-handed normal inside */ 84 OK(sg2d_geometry_add(geom, nvertices, nsegments, &callbacks, &ctx)); 85 86 OK(sg2d_geometry_get_unique_segments_with_merge_conflict_count(geom, &count)); 87 CHK(count == 0); 88 OK(sg2d_geometry_get_unique_segments_with_unspecified_interface_count(geom, &count)); 89 CHK(count == 0); 90 OK(sg2d_geometry_get_unique_segments_with_unspecified_side_count(geom, &count)); 91 CHK(count == 0); 92 OK(sg2d_geometry_dump_as_c_code(geom, stdout, "square_on_square", 93 SG2D_C_DUMP_CONST | SG2D_C_DUMP_STATIC)); 94 95 SG2(geometry_ref_put(geom)); 96 97 check_memory_allocator(&allocator); 98 mem_shutdown_proxy_allocator(&allocator); 99 CHK(mem_allocated_size() == 0); 100 return 0; 101 }