test_solparser6.c (7596B)
1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com) 2 * Copyright (C) 2016-2018 CNRS 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17 #include "solparser.h" 18 #include "solparser_sun.h" 19 #include "test_solstice_utils.h" 20 21 int 22 main(int argc, char** argv) 23 { 24 struct mem_allocator allocator; 25 struct solparser* parser; 26 struct solparser_entity_iterator it, end; 27 struct solparser_entity_id entity_id; 28 struct solparser_object_id obj_id; 29 const struct solparser_entity* entity; 30 const struct solparser_geometry* geom; 31 const struct solparser_material_double_sided* mtl2; 32 const struct solparser_material* mtl; 33 const struct solparser_object* obj; 34 const struct solparser_shape* shape; 35 const struct solparser_shape_sphere* sphere; 36 const struct solparser_shape_paraboloid* parabol; 37 const struct solparser_shape_plane* plane; 38 const struct solparser_shape_hyperboloid* hyperbol; 39 const struct solparser_shape_hemisphere* hemisphere; 40 const struct solparser_polyclip* polyclip; 41 double pos[2]; 42 FILE* stream; 43 (void)argc, (void)argv; 44 45 CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK); 46 solparser_create(&allocator, &parser); 47 48 stream = tmpfile(); 49 CHK(stream != NULL); 50 51 fprintf(stream, "- sun: { dni: 1, spectrum: [{wavelength: 1, data: 1 }] }\n"); 52 fprintf(stream, "- entity:\n"); 53 fprintf(stream, " name: test\n"); 54 fprintf(stream, " primary: 0\n"); 55 fprintf(stream, " geometry:\n"); 56 fprintf(stream, " - sphere: { radius: 1 }\n"); 57 fprintf(stream, " material: { ?virtual }\n"); 58 fprintf(stream, " - parabol:\n"); 59 fprintf(stream, " focal: 10\n"); 60 fprintf(stream, " slices : 10\n"); 61 fprintf(stream, " clip :\n"); 62 fprintf(stream, " - operation : AND\n"); 63 fprintf(stream, " vertices : [[1, 2], [3, 4], [6, 7]]\n"); 64 fprintf(stream, " material: { ?virtual }\n"); 65 fprintf(stream, " - hyperbol:\n"); 66 fprintf(stream, " focals: { real: 10, image: 2 }\n"); 67 fprintf(stream, " slices : 20\n"); 68 fprintf(stream, " clip :\n"); 69 fprintf(stream, " - operation : AND\n"); 70 fprintf(stream, " vertices : [[1, 2], [3, 4], [6, 7]]\n"); 71 fprintf(stream, " material: { ?virtual }\n"); 72 fprintf(stream, " - plane:\n"); 73 fprintf(stream, " clip :\n"); 74 fprintf(stream, " - operation : AND\n"); 75 fprintf(stream, " circle : { radius: 1, center: [-1, 1], segments: 8 }\n"); 76 fprintf(stream, " material: { ?virtual }\n"); 77 fprintf(stream, " - hemisphere:\n"); 78 fprintf(stream, " radius: 100\n"); 79 fprintf(stream, " clip :\n"); 80 fprintf(stream, " - operation : AND\n"); 81 fprintf(stream, " circle : { radius: 1 }\n"); 82 fprintf(stream, " material: { ?virtual }\n"); 83 rewind(stream); 84 85 CHK(solparser_setup(parser, NULL, stream) == RES_OK); 86 CHK(solparser_load(parser) == RES_OK); 87 88 solparser_entity_iterator_begin(parser, &it); 89 solparser_entity_iterator_end(parser, &end); 90 CHK(solparser_entity_iterator_eq(&it, &end) == 0); 91 92 entity_id = solparser_entity_iterator_get(&it); 93 entity = solparser_get_entity(parser, entity_id); 94 95 CHK(strcmp("test", str_cget(&entity->name)) == 0); 96 CHK(solparser_entity_get_children_count(entity) == 0); 97 CHK(entity->type == SOLPARSER_ENTITY_GEOMETRY); 98 geom = solparser_get_geometry(parser, entity->data.geometry); 99 CHK(solparser_geometry_get_objects_count(geom) == 5); 100 101 obj_id = solparser_geometry_get_object(geom, 0); 102 obj = solparser_get_object(parser, obj_id); 103 shape = solparser_get_shape(parser, obj->shape); 104 CHK(shape->type == SOLPARSER_SHAPE_SPHERE); 105 sphere = solparser_get_shape_sphere(parser, shape->data.sphere); 106 CHK(sphere->radius == 1); 107 CHK(sphere->nslices == 16); 108 109 obj_id = solparser_geometry_get_object(geom, 1); 110 obj = solparser_get_object(parser, obj_id); 111 shape = solparser_get_shape(parser, obj->shape); 112 CHK(shape->type == SOLPARSER_SHAPE_PARABOL); 113 parabol = solparser_get_shape_parabol(parser, shape->data.parabol); 114 CHK(parabol->focal == 10); 115 CHK(parabol->nslices == 10); 116 CHK(darray_polyclip_size_get(¶bol->polyclips) == 1); 117 polyclip = darray_polyclip_cdata_get(¶bol->polyclips); 118 CHK(polyclip->op == SOLPARSER_CLIP_OP_AND); 119 CHK(polyclip->contour_type == SOLPARSER_CLIP_CONTOUR_POLY); 120 CHK(solparser_polyclip_get_vertices_count(polyclip) == 3); 121 solparser_polyclip_get_vertex(polyclip, 0, pos); 122 CHK(pos[0] == 1); 123 CHK(pos[1] == 2); 124 solparser_polyclip_get_vertex(polyclip, 1, pos); 125 CHK(pos[0] == 3); 126 CHK(pos[1] == 4); 127 solparser_polyclip_get_vertex(polyclip, 2, pos); 128 CHK(pos[0] == 6); 129 CHK(pos[1] == 7); 130 131 obj_id = solparser_geometry_get_object(geom, 2); 132 obj = solparser_get_object(parser, obj_id); 133 shape = solparser_get_shape(parser, obj->shape); 134 CHK(shape->type == SOLPARSER_SHAPE_HYPERBOL); 135 hyperbol = solparser_get_shape_hyperbol(parser, shape->data.hyperbol); 136 CHK(hyperbol->focals.real == 10); 137 CHK(hyperbol->focals.image == 2); 138 CHK(hyperbol->nslices == 20); 139 140 mtl2 = solparser_get_material_double_sided(parser, obj->mtl2); 141 CHK(mtl2->front.i == mtl2->back.i); 142 mtl = solparser_get_material(parser, mtl2->front); 143 CHK(mtl->type == SOLPARSER_MATERIAL_VIRTUAL); 144 145 obj_id = solparser_geometry_get_object(geom, 3); 146 obj = solparser_get_object(parser, obj_id); 147 shape = solparser_get_shape(parser, obj->shape); 148 CHK(shape->type == SOLPARSER_SHAPE_PLANE); 149 plane = solparser_get_shape_plane(parser, shape->data.plane); 150 CHK(plane->nslices == 1); /* Default value */ 151 CHK(darray_polyclip_size_get(&plane->polyclips) == 1); 152 polyclip = darray_polyclip_cdata_get(&plane->polyclips); 153 CHK(polyclip->contour_type == SOLPARSER_CLIP_CONTOUR_CIRCLE); 154 CHK(polyclip->circle.radius == 1); 155 CHK(polyclip->circle.center[0] == -1); 156 CHK(polyclip->circle.center[1] == 1); 157 CHK(polyclip->circle.segments == 8); 158 159 obj_id = solparser_geometry_get_object(geom, 4); 160 obj = solparser_get_object(parser, obj_id); 161 shape = solparser_get_shape(parser, obj->shape); 162 CHK(shape->type == SOLPARSER_SHAPE_HEMISPHERE); 163 hemisphere = solparser_get_shape_hemisphere(parser, shape->data.hemisphere);; 164 CHK(hemisphere->radius == 100); 165 CHK(hemisphere->nslices == -1); /* Default value: auto */ 166 CHK(darray_polyclip_size_get(&hemisphere->polyclips) == 1); 167 polyclip = darray_polyclip_cdata_get(&hemisphere->polyclips); 168 CHK(polyclip->contour_type == SOLPARSER_CLIP_CONTOUR_CIRCLE); 169 CHK(polyclip->circle.radius == 1); 170 CHK(polyclip->circle.center[0] == 0); /* default value */ 171 CHK(polyclip->circle.center[1] == 0); /* default value */ 172 CHK(polyclip->circle.segments == 64); /* Default value */ 173 174 solparser_entity_iterator_next(&it); 175 CHK(solparser_entity_iterator_eq(&it, &end) == 1); 176 177 CHK(solparser_load(parser) == RES_BAD_OP); 178 solparser_ref_put(parser); 179 180 fclose(stream); 181 182 check_memory_allocator(&allocator); 183 mem_shutdown_proxy_allocator(&allocator); 184 CHK(mem_allocated_size() == 0); 185 return 0; 186 } 187