Loading src/csg/tests/parser/boolean.t.cpp +21 −3 Original line number Diff line number Diff line Loading @@ -93,11 +93,29 @@ circle(size = [1,2], center=true); CHECK(st == nullptr); } TEST_CASE("sphere and cylinder union", "[csg]") { auto st = csg::parse_csg(R"( TEST_CASE("sphere and mulmat cylinder", "[csg]") { auto st = *csg::parse_csg(R"( sphere(r = 0.1); multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { cylinder(h = 0.1, r1 = 0.1, r2 = 0.1, center = false); cylinder(h = 0.2, r1 = 0.3, r2 = 0.4, center = false); } )"); CHECK(st.top.objs.size() == 2); auto sph = std::get<csg::Sphere>(st.top.objs.at(0)); auto mm = std::get<csg::Mulmatrix3D>(st.top.objs.at(1)); CHECK(sph.radius == 0.1); CHECK(mm.group.objs.size() == 1); CHECK(mm.translation == std::array<double, 3>({0.5, 0.1, 0})); CHECK(mm.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mm.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mm.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cone = std::get<csg::Cone>(mm.group.objs.at(0)); CHECK(cone.height == 0.2); CHECK(cone.radius1 == 0.3); CHECK(cone.radius2 == 0.4); CHECK(cone.center == false); } src/csg/tests/parser/transform.t.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ multmatrix( )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.back()); CHECK(mat.group.objs.size() == 1); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); Loading @@ -47,6 +51,10 @@ multmatrix( } )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.back()); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); auto sph = std::get<csg::Sphere>(mat.group.objs.at(1)); CHECK(cyl.height == 2); Loading Loading @@ -80,6 +88,10 @@ multmatrix( } )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.at(0)); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); auto sph = std::get<csg::Sphere>(mat.group.objs.at(1)); CHECK(cyl.height == 2); Loading @@ -87,6 +99,10 @@ multmatrix( CHECK(sph.radius == 11); auto mat2 = std::get<csg::Mulmatrix3D>(st.top.objs.at(1)); CHECK(mat2.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat2.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat2.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat2.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cube = std::get<csg::Cube>(mat2.group.objs.at(0)); auto cone = std::get<csg::Cone>(mat2.group.objs.at(1)); auto [XX, YY, ZZ] = cube.size; Loading Loading @@ -117,6 +133,10 @@ multmatrix( auto cyl = std::get<csg::Cylinder>(st.top.objs.at(0)); auto sph = std::get<csg::Sphere>(st.top.objs.at(1)); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.at(2)); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); CHECK(sph.radius == 11); Loading Loading
src/csg/tests/parser/boolean.t.cpp +21 −3 Original line number Diff line number Diff line Loading @@ -93,11 +93,29 @@ circle(size = [1,2], center=true); CHECK(st == nullptr); } TEST_CASE("sphere and cylinder union", "[csg]") { auto st = csg::parse_csg(R"( TEST_CASE("sphere and mulmat cylinder", "[csg]") { auto st = *csg::parse_csg(R"( sphere(r = 0.1); multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { cylinder(h = 0.1, r1 = 0.1, r2 = 0.1, center = false); cylinder(h = 0.2, r1 = 0.3, r2 = 0.4, center = false); } )"); CHECK(st.top.objs.size() == 2); auto sph = std::get<csg::Sphere>(st.top.objs.at(0)); auto mm = std::get<csg::Mulmatrix3D>(st.top.objs.at(1)); CHECK(sph.radius == 0.1); CHECK(mm.group.objs.size() == 1); CHECK(mm.translation == std::array<double, 3>({0.5, 0.1, 0})); CHECK(mm.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mm.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mm.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cone = std::get<csg::Cone>(mm.group.objs.at(0)); CHECK(cone.height == 0.2); CHECK(cone.radius1 == 0.3); CHECK(cone.radius2 == 0.4); CHECK(cone.center == false); }
src/csg/tests/parser/transform.t.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ multmatrix( )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.back()); CHECK(mat.group.objs.size() == 1); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); Loading @@ -47,6 +51,10 @@ multmatrix( } )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.back()); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); auto sph = std::get<csg::Sphere>(mat.group.objs.at(1)); CHECK(cyl.height == 2); Loading Loading @@ -80,6 +88,10 @@ multmatrix( } )"); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.at(0)); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cyl = std::get<csg::Cylinder>(mat.group.objs.at(0)); auto sph = std::get<csg::Sphere>(mat.group.objs.at(1)); CHECK(cyl.height == 2); Loading @@ -87,6 +99,10 @@ multmatrix( CHECK(sph.radius == 11); auto mat2 = std::get<csg::Mulmatrix3D>(st.top.objs.at(1)); CHECK(mat2.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat2.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat2.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat2.rotation()[2] == std::array<double, 3>({0, 0, 1})); auto cube = std::get<csg::Cube>(mat2.group.objs.at(0)); auto cone = std::get<csg::Cone>(mat2.group.objs.at(1)); auto [XX, YY, ZZ] = cube.size; Loading Loading @@ -117,6 +133,10 @@ multmatrix( auto cyl = std::get<csg::Cylinder>(st.top.objs.at(0)); auto sph = std::get<csg::Sphere>(st.top.objs.at(1)); auto mat = std::get<csg::Mulmatrix3D>(st.top.objs.at(2)); CHECK(mat.translation == std::array<double, 3>({0.0020, 0.0005, 0.0005})); CHECK(mat.rotation()[0] == std::array<double, 3>({1, 0, 0})); CHECK(mat.rotation()[1] == std::array<double, 3>({0, 1, 0})); CHECK(mat.rotation()[2] == std::array<double, 3>({0, 0, 1})); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); CHECK(sph.radius == 11); Loading