commit eb546964a0db89d88d2ce4bd56b27c4083ec07a9
parent f55f1b6436f282848a2227b81558af7f4f220a98
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 12 Oct 2017 18:57:54 +0200
Test the super shape
Diffstat:
3 files changed, 126 insertions(+), 4 deletions(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -87,8 +87,9 @@ if(NOT NO_TEST)
new_test(test_s3dut_thick_cylinder)
new_test(test_s3dut_hemisphere)
new_test(test_s3dut_sphere)
- new_test(test_s3dut_truncated_sphere)
+ new_test(test_s3dut_super_shape)
new_test(test_s3dut_thick_truncated_sphere)
+ new_test(test_s3dut_truncated_sphere)
rcmake_copy_runtime_libraries(test_s3dut_cuboid)
endif()
diff --git a/src/s3dut_super_shape.c b/src/s3dut_super_shape.c
@@ -16,6 +16,7 @@
#include "s3dut.h"
#include "s3dut_mesh.h"
+#include <rsys/double2.h>
#include <rsys/double3.h>
#include <math.h>
@@ -32,9 +33,10 @@ static FINLINE void
cartesian_to_spherical(const double* xyz, struct spherical* spherical)
{
ASSERT(spherical && xyz);
- spherical->r = d3_dot(xyz, xyz);
- spherical->theta = acos(xyz[2]/spherical->r);
- spherical->phi = atan(xyz[1]/xyz[0]);
+ spherical->r = d3_len(xyz);
+ spherical->phi = asin(xyz[2]/spherical->r);
+ spherical->theta = xyz[0] == 0 ? PI/2 : atan(xyz[1]/xyz[0]) - PI/2;
+ if(xyz[0] < 0) spherical->theta += PI;
}
static FINLINE double
diff --git a/src/test_s3dut_super_shape.c b/src/test_s3dut_super_shape.c
@@ -0,0 +1,119 @@
+/* Copyright (C) |Meso|Star> 2016-2017 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "s3dut.h"
+#include "test_s3dut_utils.h"
+
+int
+main(int argc, char** argv)
+{
+ struct mem_allocator allocator;
+ struct s3dut_mesh* msh;
+ struct s3dut_mesh_data data;
+ struct s3dut_super_formula f0, f1;
+ (void)argc, (void)argv;
+
+ CHECK(mem_init_proxy_allocator(&allocator, &mem_default_allocator), RES_OK);
+
+ f0.A = 1; f0.B = 1; f0.M = 5; f0.N0 = 1; f0.N1 = 1; f0.N2 = 2;
+ f1.A = 1; f1.B = 1; f1.M = 5; f1.N0 = 1; f1.N1 = 1; f1.N2 = 3;
+
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 0, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 3, 0, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 0, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 3, 2, NULL), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 0, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 3, 0, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 0, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 0, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 0, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 0, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 0, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, NULL, 1, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, NULL, 1, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, NULL, &f1, 1, 3, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(NULL, &f0, &f1, 1, 3, 2, &msh), RES_OK);
+ CHECK(s3dut_mesh_ref_put(msh), RES_OK);
+
+ CHECK(s3dut_create_super_shape(&allocator, &f0, &f1, 1, 3, 2, &msh), RES_OK);
+ CHECK(s3dut_mesh_ref_put(msh), RES_OK);
+
+ CHECK(s3dut_create_super_shape(&allocator, &f0, &f1, 1, 2, 2, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(&allocator, &f0, &f1, 1, 3, 1, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(&allocator, &f0, &f1,-1, 3, 1, &msh), RES_BAD_ARG);
+ CHECK(s3dut_create_super_shape(&allocator, &f0, &f1, 1, 32, 16, &msh), RES_OK);
+
+ CHECK(s3dut_mesh_get_data(msh, &data), RES_OK);
+ NCHECK(data.positions, NULL);
+ NCHECK(data.indices, NULL);
+
+ dump_mesh_data(stdout, &data);
+
+ CHECK(s3dut_mesh_ref_put(msh), RES_OK);
+
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}