From 5b6508454f67e3347d8766156c580aa737765e15 Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Tue, 16 Jun 2020 09:12:11 -0400 Subject: [PATCH 1/3] add checks to test --- src/csg/tests/parser/boolean.t.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index 6cb885b..ea5e383 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -93,11 +93,25 @@ 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 union", "[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(st.top.objs.at(0)); + auto mm = std::get(st.top.objs.at(1)); + + CHECK(sph.radius == 0.1); + CHECK(mm.group.objs.size() == 1); + + auto cyl = std::get(mm.group.objs.at(0)); + CHECK(cyl.height == 0.2); + CHECK(cyl.radius1 == 0.3); + CHECK(cyl.radius2 == 0.4); + CHECK(cyl.center == false); } -- GitLab From 573176c6958cf601c9f023ed9d4f935b91fcc229 Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Tue, 16 Jun 2020 09:14:16 -0400 Subject: [PATCH 2/3] rename test --- src/csg/tests/parser/boolean.t.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index ea5e383..9381e58 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -93,7 +93,7 @@ circle(size = [1,2], center=true); CHECK(st == nullptr); } -TEST_CASE("sphere and mulmat cylinder union", "[csg]") { +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]]) { -- GitLab From c7e4512358a11d7b70052cd09c5cdad3887d1c66 Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Tue, 16 Jun 2020 09:38:35 -0400 Subject: [PATCH 3/3] more checks --- src/csg/tests/parser/boolean.t.cpp | 16 ++++++++++------ src/csg/tests/parser/transform.t.cpp | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index 9381e58..8a56351 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -108,10 +108,14 @@ multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0.1], [0, 0, 1, 0], [0, 0, 0, 1]]) { CHECK(sph.radius == 0.1); CHECK(mm.group.objs.size() == 1); - - auto cyl = std::get(mm.group.objs.at(0)); - CHECK(cyl.height == 0.2); - CHECK(cyl.radius1 == 0.3); - CHECK(cyl.radius2 == 0.4); - CHECK(cyl.center == false); + CHECK(mm.translation == std::array({0.5, 0.1, 0})); + CHECK(mm.rotation()[0] == std::array({1, 0, 0})); + CHECK(mm.rotation()[1] == std::array({0, 1, 0})); + CHECK(mm.rotation()[2] == std::array({0, 0, 1})); + + auto cone = std::get(mm.group.objs.at(0)); + CHECK(cone.height == 0.2); + CHECK(cone.radius1 == 0.3); + CHECK(cone.radius2 == 0.4); + CHECK(cone.center == false); } diff --git a/src/csg/tests/parser/transform.t.cpp b/src/csg/tests/parser/transform.t.cpp index 3f042ff..e7fa6bc 100644 --- a/src/csg/tests/parser/transform.t.cpp +++ b/src/csg/tests/parser/transform.t.cpp @@ -27,6 +27,10 @@ multmatrix( )"); auto mat = std::get(st.top.objs.back()); CHECK(mat.group.objs.size() == 1); + 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})); auto cyl = std::get(mat.group.objs.at(0)); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); @@ -47,6 +51,10 @@ multmatrix( } )"); auto mat = std::get(st.top.objs.back()); + 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})); auto cyl = std::get(mat.group.objs.at(0)); auto sph = std::get(mat.group.objs.at(1)); CHECK(cyl.height == 2); @@ -80,6 +88,10 @@ multmatrix( } )"); auto mat = std::get(st.top.objs.at(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})); auto cyl = std::get(mat.group.objs.at(0)); auto sph = std::get(mat.group.objs.at(1)); CHECK(cyl.height == 2); @@ -87,6 +99,10 @@ multmatrix( CHECK(sph.radius == 11); auto mat2 = std::get(st.top.objs.at(1)); + CHECK(mat2.translation == std::array({0.0020, 0.0005, 0.0005})); + CHECK(mat2.rotation()[0] == std::array({1, 0, 0})); + CHECK(mat2.rotation()[1] == std::array({0, 1, 0})); + CHECK(mat2.rotation()[2] == std::array({0, 0, 1})); auto cube = std::get(mat2.group.objs.at(0)); auto cone = std::get(mat2.group.objs.at(1)); auto [XX, YY, ZZ] = cube.size; @@ -117,6 +133,10 @@ multmatrix( auto cyl = std::get(st.top.objs.at(0)); auto sph = std::get(st.top.objs.at(1)); auto mat = std::get(st.top.objs.at(2)); + 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})); CHECK(cyl.height == 2); CHECK(cyl.radius == 10); CHECK(sph.radius == 11); -- GitLab