diff --git a/src/csg/impl/levelset_3d.cpp b/src/csg/impl/levelset_3d.cpp index 243714aa82193807761f52a0d4185e0a0bc48412..8f6821d52041d79501f3b0381daa271a48b4d17e 100644 --- a/src/csg/impl/levelset_3d.cpp +++ b/src/csg/impl/levelset_3d.cpp @@ -131,7 +131,8 @@ double signed_distance_3d(const Cylinder &cyl, double xx, double yy, double signed_distance_3d(const LinearExtrude &lin_ext, double xx, double yy, double zz) { // TODO: support height, center and twist - return signed_distance_2d(lin_ext.group, xx, yy); + double sign_z = (0 <= zz && zz <= lin_ext.height) ? 1.0 : 1.0; // unused zz warning workaround + return sign_z*signed_distance_2d(lin_ext.group, xx, yy); } double signed_distance_3d(const RotateExtrude &rot_ext, double xx, double yy, diff --git a/src/csg/impl/parser.cpp b/src/csg/impl/parser.cpp index 7bfb0528a642855abb873e7c5efff596f02e8932..d2454deb2f4732f6a2fb561a9b98615071bd30ec 100644 --- a/src/csg/impl/parser.cpp +++ b/src/csg/impl/parser.cpp @@ -179,6 +179,7 @@ template struct action {}; template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); // std::cout << " { " << std::endl; std::vector new_3d_group; st.current_3d_objs.push_back(new_3d_group); @@ -188,6 +189,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); std::vector new_2d_group; st.current_2d_objs.push_back(new_2d_group); } @@ -196,6 +198,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); // std::cout << " } " << std::endl; st.current_3d_group.clear(); for (auto obj : st.current_3d_objs.back()) { @@ -208,6 +211,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.current_2d_group.clear(); for (auto obj : st.current_2d_objs.back()) { st.current_2d_group.push_back(obj); @@ -229,6 +233,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.current_matrices.push_back(st.current_matrix); st.current_matrix.clear(); } @@ -237,6 +242,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.curr_attrs.push_back(st.curr_attr); st.curr_attr.clear(); } @@ -245,6 +251,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.current_matrix.push_back(st.current_vec); st.current_vec.clear(); } @@ -269,6 +276,7 @@ void add_group_3d(parser_state &st) { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_3d(st); } }; @@ -276,6 +284,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_2d(st); } }; @@ -283,6 +292,7 @@ template <> struct action> { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_3d(st); } }; @@ -290,6 +300,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_3d(st); } }; @@ -297,6 +308,7 @@ template <> struct action { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_3d(st); } }; @@ -304,6 +316,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); add_group_2d(st); } }; @@ -311,6 +324,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto csg_in = csg::Intersection3D(); for (const auto &curr_obj : st.current_3d_group) { csg_in.objs.push_back(curr_obj); @@ -322,6 +336,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto csg_in = csg::Intersection2D(); for (const auto &curr_obj : st.current_2d_group) { csg_in.objs.push_back(curr_obj); @@ -333,6 +348,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto csg_diff = csg::Difference3D(); for (auto it = st.current_3d_group.begin(); it != st.current_3d_group.end(); ++it) { @@ -349,6 +365,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto csg_diff = csg::Difference2D(); for (auto it = st.current_2d_group.begin(); it != st.current_2d_group.end(); ++it) { @@ -365,6 +382,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto mulmat = csg::Mulmatrix2D(); auto mat = st.current_matrices.back(); // clang-format off @@ -388,6 +406,7 @@ template <> struct action> { template <> struct action> { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto mulmat = csg::Mulmatrix3D(); auto mat = st.current_matrices.back(); // clang-format off @@ -413,6 +432,7 @@ template <> struct action> { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto lin_ext = csg::LinearExtrude(); auto &curr_attr = st.curr_attrs.back(); lin_ext.height = std::get(curr_attr["height"]); @@ -431,6 +451,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto rot_ext = csg::RotateExtrude(); auto &curr_attr = st.curr_attrs.back(); rot_ext.angle = std::get(curr_attr["angle"]); @@ -456,6 +477,7 @@ std::optional get_name(AttrMap curr_attr) { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); csg::Cube cub; auto &curr_attr = st.curr_attrs.back(); auto size = std::get>(curr_attr["size"]); @@ -471,6 +493,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); auto &curr_attr = st.curr_attrs.back(); if (curr_attr.count("r")) { // proper cylinder @@ -503,6 +526,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); csg::Sphere sph; auto &curr_attr = st.curr_attrs.back(); sph.name = get_name(curr_attr); @@ -516,6 +540,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); csg::Circle cir; auto &curr_attr = st.curr_attrs.back(); cir.name = get_name(curr_attr); @@ -529,6 +554,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); csg::Square sq; auto &curr_attr = st.curr_attrs.back(); auto size = std::get>(curr_attr["size"]); @@ -572,6 +598,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.curr_attr[st.current_name] = true; } }; @@ -579,6 +606,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.curr_attr[st.current_name] = false; } }; @@ -586,6 +614,7 @@ template <> struct action { template <> struct action { template static void apply(const Input &in, parser_state &st) { + std::stringstream ss(in.string()); st.curr_attr[st.current_name] = st.current_vec; st.current_vec.clear(); } diff --git a/src/csg/meson.build b/src/csg/meson.build index c70ecd7ee173bde8e33e39115d25a468edb571ab..be75acbe75bbd52a033d58c3f5b70070856244e3 100644 --- a/src/csg/meson.build +++ b/src/csg/meson.build @@ -1,4 +1,4 @@ -lib_csg_parser = static_library( +lib_csg_parser = library( 'csg-parser', 'impl/csg.cpp', 'impl/levelset_3d.cpp', @@ -7,4 +7,6 @@ lib_csg_parser = static_library( include_directories: tao_inc, install : true) -subdir('tests') +if get_option('cpp_std')=='c++2a' + subdir('tests') +endif diff --git a/src/csg/tests/levelset/boolean.t.cpp b/src/csg/tests/levelset/boolean.t.cpp index f2eb216ee9a7b5947fe70592dd6addda6c549f66..826ecf1037cc27a22548eae4217bfc67b3148002 100644 --- a/src/csg/tests/levelset/boolean.t.cpp +++ b/src/csg/tests/levelset/boolean.t.cpp @@ -9,8 +9,8 @@ namespace { TEST_CASE("Union3D", "[Levelset Boolean]") { // Create a union of a cube of size 12 and a sphere of radius 8 - csg::Cube my_cub{.size = {12, 12, 12}, .center = true}; - csg::Sphere my_sph{.radius = 8}; + csg::Cube my_cub{.name = std::nullopt, .size = {12, 12, 12}, .center = true}; + csg::Sphere my_sph{.name = std::nullopt, .radius = 8}; auto my_union = csg::Union3D(); my_union.objs.push_back(my_cub); @@ -35,8 +35,8 @@ TEST_CASE("Union3D", "[Levelset Boolean]") { TEST_CASE("Intersection3D", "[Levelset Boolean]") { // Create an of a cube of size 12 and a sphere of radius 8 - csg::Cube my_cub{.size = {12, 12, 12}, .center = true}; - csg::Sphere my_sph{.radius = 8}; + csg::Cube my_cub{.name = std::nullopt, .size = {12, 12, 12}, .center = true}; + csg::Sphere my_sph{.name = std::nullopt, .radius = 8}; auto my_in = csg::Intersection3D(); my_in.objs.push_back(my_cub); @@ -61,8 +61,8 @@ TEST_CASE("Intersection3D", "[Levelset Boolean]") { TEST_CASE("Difference3D", "[Levelset Boolean]") { // Create an of a cube of size 12 and remove a sphere of radius 8 - csg::Cube my_cub{.size = {12, 12, 12}, .center = true}; - csg::Sphere my_sph{.radius = 8}; + csg::Cube my_cub{.name = std::nullopt, .size = {12, 12, 12}, .center = true}; + csg::Sphere my_sph{.name = std::nullopt, .radius = 8}; csg::Union3D my_union; my_union.objs.push_back(my_sph); diff --git a/src/csg/tests/levelset/extrude.t.cpp b/src/csg/tests/levelset/extrude.t.cpp index 205c3973fe78d3f5325f68c443643fee5f437c4f..11769ce0715ebc98f4d2f0130fe3693efc199e19 100644 --- a/src/csg/tests/levelset/extrude.t.cpp +++ b/src/csg/tests/levelset/extrude.t.cpp @@ -8,7 +8,7 @@ namespace { TEST_CASE("two shape linear", "[Levelset Extrude]") { auto my_lin_ext = csg::LinearExtrude(); - csg::Circle my_cir{.radius = 1}; + csg::Circle my_cir{.name = std::nullopt, .radius = 1}; my_lin_ext.group.objs.push_back(my_cir); auto my_mat = csg::Mulmatrix2D(); @@ -40,7 +40,7 @@ TEST_CASE("two shape linear", "[Levelset Extrude]") { TEST_CASE("simple torus", "[Levelset Extrude]") { auto my_rot_ext = csg::RotateExtrude(); - csg::Circle my_cir{.radius = 1}; + csg::Circle my_cir{.name = std::nullopt, .radius = 1}; auto my_mat = csg::Mulmatrix2D(); my_mat.rotation[0] = std::array{{1, 0}}; my_mat.rotation[1] = std::array{{0, 1}}; diff --git a/src/csg/tests/levelset/primitives.t.cpp b/src/csg/tests/levelset/primitives.t.cpp index 5a02af4771405728f5f05ef8c1168a8b2291a547..b2b3b0152f9aa08138c9f5219ceab694f60426a1 100644 --- a/src/csg/tests/levelset/primitives.t.cpp +++ b/src/csg/tests/levelset/primitives.t.cpp @@ -7,7 +7,8 @@ namespace { TEST_CASE("Cylinder", "[Levelset Primitives]") { - csg::Cylinder my_cyl{.radius = 1, .height = 2, .center = false}; + csg::Cylinder my_cyl{ + .name = std::nullopt, .radius = 1, .height = 2, .center = false}; SECTION("Not Centered") { my_cyl.center = false; @@ -77,7 +78,7 @@ TEST_CASE("Cylinder", "[Levelset Primitives]") { TEST_CASE("Cube", "[Levelset Primitives]") { - csg::Cube my_cub{.size = {2, 3, 5}, .center = false}; + csg::Cube my_cub{.name = std::nullopt, .size = {2, 3, 5}, .center = false}; SECTION("Not Centered") { my_cub.center = false; @@ -155,7 +156,7 @@ TEST_CASE("Cube", "[Levelset Primitives]") { TEST_CASE("Sphere", "[Levelset Primitives]") { - csg::Sphere my_sph{.radius = 10}; + csg::Sphere my_sph{.name = std::nullopt, .radius = 10}; auto my_tree = std::make_shared(); my_tree->top.objs.push_back(my_sph); @@ -189,7 +190,11 @@ TEST_CASE("Cone", "[Levelset Primitives]") { SECTION("radius1 < radius 2; regular)") { - csg::Cone my_cone{.radius1 = 0, .radius2 = 1, .height = 2, .center = false}; + csg::Cone my_cone{.name = std::nullopt, + .radius1 = 0, + .radius2 = 1, + .height = 2, + .center = false}; SECTION("Untruncated") { my_cone.radius1 = 0; @@ -469,7 +474,11 @@ TEST_CASE("Cone", "[Levelset Primitives]") { } SECTION("radius1 > radius2; inverted") { - csg::Cone my_cone{.radius1 = 1, .radius2 = 0, .height = 2, .center = false}; + csg::Cone my_cone{.name = std::nullopt, + .radius1 = 1, + .radius2 = 0, + .height = 2, + .center = false}; SECTION("Untruncated") { my_cone.radius2 = 0; diff --git a/src/csg/tests/levelset/transform.t.cpp b/src/csg/tests/levelset/transform.t.cpp index ffa4ec127b79959b7e228e631b5267e5792c287c..af6c818b6b713655d3348094ca0588ad57cf1e2f 100644 --- a/src/csg/tests/levelset/transform.t.cpp +++ b/src/csg/tests/levelset/transform.t.cpp @@ -9,7 +9,8 @@ namespace { TEST_CASE("Translation", "[Levelset Transform]") { - csg::Cylinder my_cyl{.radius = 2, .height = 20, .center = true}; + csg::Cylinder my_cyl{ + .name = std::nullopt, .radius = 2, .height = 20, .center = true}; auto my_mat = csg::Mulmatrix3D(); my_mat.rotation[0] = std::array{{1, 0, 0}}; @@ -44,7 +45,8 @@ TEST_CASE("Translation", "[Levelset Transform]") { TEST_CASE("90° Rotation around y-axis, rotating z-axis into x-axis", "[Levelset Transform]") { - csg::Cylinder my_cyl{.radius = 2, .height = 20, .center = false}; + csg::Cylinder my_cyl{ + .name = std::nullopt, .radius = 2, .height = 20, .center = false}; auto my_mat = csg::Mulmatrix3D(); my_mat.rotation[0] = std::array{{0, 0, 1}}; @@ -92,7 +94,8 @@ TEST_CASE("Orthogonal rotation + translation of cylinder", double radius = 4.5, height = 10; double Cx = 10, Cy = 5, Cz = 5; - csg::Cylinder my_cyl{.radius = radius, .height = height, .center = true}; + csg::Cylinder my_cyl{ + .name = std::nullopt, .radius = radius, .height = height, .center = true}; auto my_mat = csg::Mulmatrix3D(); my_mat.rotation[0] = std::array{{0, 0, 1}}; my_mat.rotation[1] = std::array{{0, 1, 0}}; diff --git a/src/csg/tests/meson.build b/src/csg/tests/meson.build index e114a28b89100fb291e479095b05f1d6589ec246..555396dc50c50f763c81cc5e9ef1706b78ef552e 100644 --- a/src/csg/tests/meson.build +++ b/src/csg/tests/meson.build @@ -12,6 +12,7 @@ unit_exe = executable( 'parser/transform.t.cpp', 'parser/extrude.t.cpp', include_directories: [parser_inc, catch2_inc], - link_with: lib_csg_parser + link_with: lib_csg_parser, + override_options: 'cpp_std=c++2a', ) test('unit_test', unit_exe) diff --git a/src/inputs/meson.build b/src/inputs/meson.build index a435c0ac4fd146e7ecf97a3632d292691b8c2bf4..4d39f989a37385f012899fb157c1f662310efe8c 100644 --- a/src/inputs/meson.build +++ b/src/inputs/meson.build @@ -1,4 +1,4 @@ -lib_inputs_parser = static_library( +lib_inputs_parser = library( 'inputs-parser', 'geometry.cpp', 'mesh.cpp',