star-3dut

Generate meshes of simple geometric shapes
git clone git://git.meso-star.fr/star-3dut.git
Log | Files | Refs | README | LICENSE

test_s3dut_hemisphere.c (3566B)


      1 /* Copyright (C) 2016, 2017, 2020, 2021, 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 "s3dut.h"
     17 #include "test_s3dut_utils.h"
     18 
     19 #include <rsys/double3.h>
     20 #include <rsys/math.h>
     21 
     22 int
     23 main(int argc, char** argv)
     24 {
     25   struct mem_allocator allocator;
     26   struct s3dut_mesh* msh;
     27   struct s3dut_mesh_data data;
     28   size_t i;
     29   (void)argc, (void)argv;
     30 
     31   CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
     32 
     33   CHK(s3dut_create_hemisphere(NULL, 0, 0, 0, NULL) == RES_BAD_ARG);
     34   CHK(s3dut_create_hemisphere(NULL, 1, 0, 0, NULL) == RES_BAD_ARG);
     35   CHK(s3dut_create_hemisphere(NULL, 0, 3, 0, NULL) == RES_BAD_ARG);
     36   CHK(s3dut_create_hemisphere(NULL, 1, 3, 0, NULL) == RES_BAD_ARG);
     37   CHK(s3dut_create_hemisphere(NULL, 0, 0, 2, NULL) == RES_BAD_ARG);
     38   CHK(s3dut_create_hemisphere(NULL, 1, 0, 2, NULL) == RES_BAD_ARG);
     39   CHK(s3dut_create_hemisphere(NULL, 0, 3, 2, NULL) == RES_BAD_ARG);
     40   CHK(s3dut_create_hemisphere(NULL, 1, 3, 2, NULL) == RES_BAD_ARG);
     41   CHK(s3dut_create_hemisphere(NULL, 0, 0, 0, &msh) == RES_BAD_ARG);
     42   CHK(s3dut_create_hemisphere(NULL, 1, 0, 0, &msh) == RES_BAD_ARG);
     43   CHK(s3dut_create_hemisphere(NULL, 0, 3, 0, &msh) == RES_BAD_ARG);
     44   CHK(s3dut_create_hemisphere(NULL, 1, 3, 0, &msh) == RES_BAD_ARG);
     45   CHK(s3dut_create_hemisphere(NULL, 0, 0, 2, &msh) == RES_BAD_ARG);
     46   CHK(s3dut_create_hemisphere(NULL, 1, 0, 2, &msh) == RES_BAD_ARG);
     47   CHK(s3dut_create_hemisphere(NULL, 0, 3, 2, &msh) == RES_BAD_ARG);
     48   CHK(s3dut_create_hemisphere(NULL, 1, 3, 2, &msh) == RES_OK);
     49 
     50   CHK(s3dut_mesh_ref_get(NULL) == RES_BAD_ARG);
     51   CHK(s3dut_mesh_ref_get(msh) == RES_OK);
     52   CHK(s3dut_mesh_ref_put(NULL) == RES_BAD_ARG);
     53   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     54   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     55 
     56   CHK(s3dut_create_hemisphere(&allocator, 1, 3, 2, &msh) == RES_OK);
     57   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     58 
     59   CHK(s3dut_create_hemisphere(&allocator, 1, 1, 2, &msh) == RES_BAD_ARG);
     60   CHK(s3dut_create_hemisphere(&allocator, 1, 3, 1, &msh) == RES_BAD_ARG);
     61   CHK(s3dut_create_hemisphere(&allocator,-1, 3, 2, &msh) == RES_BAD_ARG);
     62   CHK(s3dut_create_hemisphere(&allocator, 1, 32, 16, &msh) == RES_OK);
     63 
     64   CHK(s3dut_mesh_get_data(NULL, NULL) == RES_BAD_ARG);
     65   CHK(s3dut_mesh_get_data(msh, NULL) == RES_BAD_ARG);
     66   CHK(s3dut_mesh_get_data(NULL, &data) == RES_BAD_ARG);
     67   CHK(s3dut_mesh_get_data(msh, &data) == RES_OK);
     68   CHK(data.positions != NULL);
     69   CHK(data.indices != NULL);
     70   CHK(data.nvertices >= (32*(16-1)+1));
     71   CHK(data.nprimitives == (32*(16-1)*2) + 32);
     72 
     73   FOR_EACH(i, 0, data.nvertices) {
     74     double v[3];
     75     d3_set(v, data.positions + i*3);
     76     v[2] = sqrt(MMAX(0, 1 - v[0]*v[0] - v[1]*v[1]));
     77     CHK(d3_eq_eps(v, data.positions + i*3, 1.e-6) == 1);
     78   }
     79 
     80   dump_mesh_data(stdout, &data);
     81 
     82   CHK(s3dut_mesh_ref_put(msh) == RES_OK);
     83 
     84   check_memory_allocator(&allocator);
     85   mem_shutdown_proxy_allocator(&allocator);
     86   CHK(mem_allocated_size() == 0);
     87   return 0;
     88 }
     89