From c017c6ed4364e348ddca92266850d7f2a8ac75ba Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Mon, 15 Jun 2020 16:53:00 -0400 Subject: [PATCH 1/3] Fix parsing bug --- src/csg/parser.cpp | 1 + src/csg/tests/parser/boolean.t.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/csg/parser.cpp b/src/csg/parser.cpp index b3a4313..9ad0f5d 100644 --- a/src/csg/parser.cpp +++ b/src/csg/parser.cpp @@ -510,6 +510,7 @@ template <> struct action { if (curr_attr.count("r1") || curr_attr.count("r2")) { std::cout << " ERROR: cannot specify both r and (r1 or r2); ambiguous " << std::endl; + assert(false); } csg::Cylinder cyl; cyl.name = get_name(curr_attr); diff --git a/src/csg/tests/parser/boolean.t.cpp b/src/csg/tests/parser/boolean.t.cpp index b96d85c..6cb885b 100644 --- a/src/csg/tests/parser/boolean.t.cpp +++ b/src/csg/tests/parser/boolean.t.cpp @@ -92,3 +92,12 @@ circle(size = [1,2], center=true); )"); CHECK(st == nullptr); } + +TEST_CASE("sphere and 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); +} +)"); +} -- GitLab From e21347545d34ef4335f64ad71eb7982ccb07cdaa Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Mon, 15 Jun 2020 18:09:10 -0400 Subject: [PATCH 2/3] fix --- src/csg/parser.cpp | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/csg/parser.cpp b/src/csg/parser.cpp index 9ad0f5d..fae30fc 100644 --- a/src/csg/parser.cpp +++ b/src/csg/parser.cpp @@ -455,6 +455,7 @@ template <> struct action { st.current_3d_objs.back().push_back(lin_ext); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -472,6 +473,7 @@ template <> struct action { st.current_3d_objs.back().push_back(rot_ext); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -497,6 +499,7 @@ template <> struct action { st.current_3d_objs.back().push_back(cub); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -519,6 +522,7 @@ template <> struct action { cyl.radius = std::get(curr_attr["r"]); st.current_3d_objs.back().push_back(cyl); st.curr_attrs.pop_back(); + st.current_name.clear(); } else { // conic "cylinder" @@ -530,6 +534,7 @@ template <> struct action { cone.radius2 = std::get(curr_attr["r2"]); st.current_3d_objs.back().push_back(cone); st.curr_attrs.pop_back(); + st.current_name.clear(); } } }; @@ -545,6 +550,7 @@ template <> struct action { st.current_3d_objs.back().push_back(sph); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -559,6 +565,7 @@ template <> struct action { st.current_2d_objs.back().push_back(cir); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -575,6 +582,7 @@ template <> struct action { st.current_2d_objs.back().push_back(sq); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -606,6 +614,7 @@ template <> struct action { st.current_2d_objs.back().push_back(diff); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -624,6 +633,7 @@ template <> struct action { st.current_3d_objs.back().push_back(polyh); st.curr_attrs.pop_back(); + st.current_name.clear(); } }; @@ -641,7 +651,8 @@ template <> struct action { std::stringstream ss(in.string()); std::string v; ss >> v; - st.curr_attr[st.current_name] = v; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = v; } }; @@ -651,7 +662,8 @@ template <> struct action { std::stringstream ss(in.string()); double v; ss >> v; - st.curr_attr[st.current_name] = v; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = v; } }; @@ -659,7 +671,8 @@ 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; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = true; } }; @@ -667,7 +680,8 @@ 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; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = false; } }; @@ -675,7 +689,8 @@ template <> struct action { template static void apply(const Input &in, parser_state &st) { std::stringstream ss(in.string()); - st.curr_attr[st.current_name] = UNDEFINED_STR; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = UNDEFINED_STR; } }; @@ -683,7 +698,8 @@ 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; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = st.current_vec; st.current_vec.clear(); } }; @@ -692,7 +708,8 @@ 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_matrix; + if (!st.current_name.empty()) + st.curr_attr[st.current_name] = st.current_matrix; st.current_matrix.clear(); } }; -- GitLab From 99aa9d424b150db9ef9bb1e15fbe294a955a295e Mon Sep 17 00:00:00 2001 From: Deepak Rangarajan Date: Mon, 15 Jun 2020 18:12:27 -0400 Subject: [PATCH 3/3] better fix --- src/csg/parser.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/csg/parser.cpp b/src/csg/parser.cpp index fae30fc..7e8491e 100644 --- a/src/csg/parser.cpp +++ b/src/csg/parser.cpp @@ -260,6 +260,7 @@ template <> struct action { std::stringstream ss(in.string()); st.curr_attrs.push_back(st.curr_attr); st.curr_attr.clear(); + st.current_name.clear(); } }; @@ -455,7 +456,6 @@ template <> struct action { st.current_3d_objs.back().push_back(lin_ext); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -473,7 +473,6 @@ template <> struct action { st.current_3d_objs.back().push_back(rot_ext); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -499,7 +498,6 @@ template <> struct action { st.current_3d_objs.back().push_back(cub); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -522,7 +520,6 @@ template <> struct action { cyl.radius = std::get(curr_attr["r"]); st.current_3d_objs.back().push_back(cyl); st.curr_attrs.pop_back(); - st.current_name.clear(); } else { // conic "cylinder" @@ -534,7 +531,6 @@ template <> struct action { cone.radius2 = std::get(curr_attr["r2"]); st.current_3d_objs.back().push_back(cone); st.curr_attrs.pop_back(); - st.current_name.clear(); } } }; @@ -550,7 +546,6 @@ template <> struct action { st.current_3d_objs.back().push_back(sph); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -565,7 +560,6 @@ template <> struct action { st.current_2d_objs.back().push_back(cir); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -582,7 +576,6 @@ template <> struct action { st.current_2d_objs.back().push_back(sq); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -614,7 +607,6 @@ template <> struct action { st.current_2d_objs.back().push_back(diff); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; @@ -633,7 +625,6 @@ template <> struct action { st.current_3d_objs.back().push_back(polyh); st.curr_attrs.pop_back(); - st.current_name.clear(); } }; -- GitLab