diff --git a/src/csg/parser.cpp b/src/csg/parser.cpp index e05e05f74a2eb464fe1d2765a91e9ae11a66fd9b..10d229b0bfa09f57abf0563a0731b60391bae8ab 100644 --- a/src/csg/parser.cpp +++ b/src/csg/parser.cpp @@ -135,17 +135,21 @@ struct shape : seq, opt> {}; template struct obj_list; template -struct bool_union : seq, L_FUN, R_FUN, - L_BLK, obj_list, R_BLK> {}; +struct bool_union + : seq, L_FUN, R_FUN, + opt, obj_list, R_BLK>>, opt> {}; template struct bool_intersection : seq, - L_FUN, R_FUN, L_BLK, obj_list, R_BLK> {}; + L_FUN, R_FUN, opt, obj_list, R_BLK>>, + opt> {}; template -struct bool_diff : seq, - L_FUN, R_FUN, L_BLK, obj_list, R_BLK> {}; +struct bool_diff + : seq, L_FUN, + R_FUN, opt, obj_list, R_BLK>>, opt> { +}; template struct bool_exp : sor, bool_intersection, bool_diff> { @@ -154,7 +158,8 @@ struct bool_exp : sor, bool_intersection, bool_diff> { template struct mulmat : seq, L_FUN, - matrix, R_FUN, L_BLK, obj_list, R_BLK> {}; + matrix, R_FUN, opt, obj_list, R_BLK>>, + opt> {}; template struct group @@ -163,13 +168,17 @@ struct group struct extrude_rot : seq, - L_FUN, attr_list, R_FUN, L_BLK, - obj_list, R_BLK> {}; + L_FUN, attr_list, R_FUN, + opt, obj_list, + R_BLK>>, + opt> {}; struct extrude_lin : seq, - L_FUN, attr_list, R_FUN, L_BLK, - obj_list, R_BLK> {}; + L_FUN, attr_list, R_FUN, + opt, obj_list, + R_BLK>>, + opt> {}; struct hull : seq, L_FUN, R_FUN, L_BLK, diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index 6b7ff2c029fd18dce1d214a75940fccd66273463..378de7671128be2d9573a359954e2b2321112e39 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -131,3 +131,38 @@ group(); CHECK(un.objs.size() == 0); } + +TEST_CASE("empty boolean", "[csg]") { + auto st = *csg::parse_csg(R"( +union(); +sphere(r=0.1); +)"); + auto un = std::get(st.top.objs.at(0)); + CHECK(un.objs.size() == 0); + + auto sph = std::get(st.top.objs.at(1)); + CHECK(sph.radius == 0.1); +} + +TEST_CASE("empty intersection", "[csg]") { + auto st = *csg::parse_csg(R"( +intersection(); +)"); + auto in = std::get(st.top.objs.at(0)); + CHECK(in.objs.size() == 0); +} + +TEST_CASE("empty difference", "[csg]") { + auto st = *csg::parse_csg(R"( +cylinder(h = 200, r1 = 1.7, r2 = 2.7, center = false); +difference(); +)"); + auto cone = std::get(st.top.objs.at(0)); + CHECK(cone.radius1 == 1.7); + CHECK(cone.radius2 == 2.7); + CHECK(cone.height == 200); + + auto diff = std::get(st.top.objs.at(1)); + CHECK(diff.first_obj == nullptr); + CHECK(diff.next_objs.objs.size() == 0); +} diff --git a/src/csg/tests/parser/extrude.t.cpp b/src/csg/tests/parser/extrude.t.cpp index 749e3c10aa93f54281a94dd62cca4517b7ee4ee0..6a89ff1fb94baec42c25804725f47a3f8b2a0969 100644 --- a/src/csg/tests/parser/extrude.t.cpp +++ b/src/csg/tests/parser/extrude.t.cpp @@ -189,4 +189,38 @@ paths = [[0, 1, 2], [3, 4, 5]]); CHECK(inner.cgal_polygon().size() == 3); } +TEST_CASE("empty linear_extrude", "[csg]") { + auto st = *csg::parse_csg(R"( +linear_extrude(height = 10, center = true, scale = [10,1]); +)"); + auto lin_ext = std::get(st.top.objs.at(0)); + CHECK(lin_ext.height == 10); + CHECK(lin_ext.center == true); + + auto [sx, sy] = lin_ext.scale; + CHECK(sx == 10); + CHECK(sy == 1); +} + +TEST_CASE("empty intersection inside linear extrude", "[csg]") { + auto st = *csg::parse_csg(R"( +linear_extrude( +height = 10, +center = true, +scale = [10,1] +) { + circle(r=0.2); + intersection(); +} +)"); + auto lin_ext = std::get(st.top.objs.at(0)); + CHECK(lin_ext.group.objs.size() == 2); + + auto cir = std::get(lin_ext.group.objs.at(0)); + CHECK(cir.radius == 0.2); + + auto in = std::get(lin_ext.group.objs.at(1)); + CHECK(in.objs.size() == 0); +} + } // namespace diff --git a/src/csg/tests/parser/transform.t.cpp b/src/csg/tests/parser/transform.t.cpp index e7fa6bca7d43b9070d4255f38b23323f57c1c378..4b3a0527997fa23731b986a042bdba8133380843 100644 --- a/src/csg/tests/parser/transform.t.cpp +++ b/src/csg/tests/parser/transform.t.cpp @@ -151,3 +151,22 @@ multmatrix( CHECK(cone.radius1 == 1); CHECK(cone.radius2 == 2); } + +TEST_CASE("empty matmul", "[csg]") { + auto st = *csg::parse_csg(R"( +multmatrix( +[ +[1, 0, 0, 0.0020], +[0, 1, 0, 0.0005], +[0, 0, 1, 0.0005], +[0, 0, 0, 1] +] +); +)"); + auto mat = std::get(st.top.objs.back()); + CHECK(mat.group.objs.size() == 0); + CHECK(mat.translation == std::array({0.0020, 0.0005, 0.0005})); + CHECK(mat.rotation()[0] == std::array({1, 0, 0})); + CHECK(mat.rotation()[1] == std::array({0, 1, 0})); + CHECK(mat.rotation()[2] == std::array({0, 0, 1})); +}