Loading include/csg_types.hpp +7 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include <array> #include <memory> #include <optional> #include <stdexcept> #include <tuple> #include <variant> #include <vector> Loading Loading @@ -61,7 +62,9 @@ public: Polyhedron(const std::vector<std::vector<double>> &points, const std::vector<std::vector<double>> &faces) { for (const auto &pt : points) { assert(pt.size() == 3); if (pt.size() != 3) throw std::runtime_error("Error parsing polyhedron. Check input!"); m_points.push_back({pt[0], pt[1], pt[2]}); } for (const auto &f : faces) { Loading @@ -86,7 +89,9 @@ public: Polygon(const std::vector<std::vector<double>> &points, const std::vector<double> &path) { for (const auto &pt : points) { assert(pt.size() == 2); if (pt.size() != 2) throw std::runtime_error("Error parsing polygon. Check input!"); m_points.push_back({pt[0], pt[1]}); } for (const auto &p : path) { Loading src/csg/cgal_helper_polyhedron.cpp +6 −0 Original line number Diff line number Diff line #include "csg_cgal_helper.hpp" #include <stdexcept> #include <CGAL/AABB_face_graph_triangle_primitive.h> #include <CGAL/AABB_traits.h> #include <CGAL/AABB_tree.h> Loading Loading @@ -46,6 +48,10 @@ public: // Add facets next for (const auto &face : m_faces) { B.begin_facet(); if (!B.test_facet(face.begin(), face.end())) throw std::runtime_error( "Unable to create the polyhedron. Check input!"); for (const auto &p_index : face) { B.add_vertex_to_facet(p_index); } Loading src/csg/parser.cpp +12 −5 Original line number Diff line number Diff line // standard includes #include <assert.h> #include <iostream> #include <memory> #include <stdexcept> // subproject includes #include <tao/pegtl.hpp> Loading Loading @@ -511,7 +511,7 @@ template <> struct action<cylinder> { 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); throw std::runtime_error("Error parsing cylinder. Check input!"); } csg::Cylinder cyl; cyl.name = get_name(curr_attr); Loading Loading @@ -590,7 +590,8 @@ template <> struct action<polygon> { std::vector<std::vector<double>> paths = {{}}; if (std::holds_alternative<std::string>(curr_attr["paths"])) { assert(std::get<std::string>(curr_attr["paths"]) == UNDEFINED_STR); if (std::get<std::string>(curr_attr["paths"]) != UNDEFINED_STR) throw std::runtime_error("Error parsing polygon. Check inputs!"); } else { paths = std::get<std::vector<std::vector<double>>>(curr_attr["paths"]); } Loading Loading @@ -727,12 +728,18 @@ std::shared_ptr<Tree> parse_csg(std::string str) { } auto st = maybe_state.value(); assert(st.current_3d_objs.size() == 1); if (st.current_3d_objs.size() != 1) throw std::runtime_error("Error parsing. Check input!"); Tree tree; for (auto obj : st.current_3d_objs.back()) { tree.top.objs.push_back(obj); } assert(tree.top.objs.size() > 0); // Disallow empty .csg file if (tree.top.objs.empty()) throw std::runtime_error( "Error parsing. Check input!"); // Disallow empty .csg file return std::make_shared<Tree>(tree); } } // namespace csg Loading
include/csg_types.hpp +7 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ #include <array> #include <memory> #include <optional> #include <stdexcept> #include <tuple> #include <variant> #include <vector> Loading Loading @@ -61,7 +62,9 @@ public: Polyhedron(const std::vector<std::vector<double>> &points, const std::vector<std::vector<double>> &faces) { for (const auto &pt : points) { assert(pt.size() == 3); if (pt.size() != 3) throw std::runtime_error("Error parsing polyhedron. Check input!"); m_points.push_back({pt[0], pt[1], pt[2]}); } for (const auto &f : faces) { Loading @@ -86,7 +89,9 @@ public: Polygon(const std::vector<std::vector<double>> &points, const std::vector<double> &path) { for (const auto &pt : points) { assert(pt.size() == 2); if (pt.size() != 2) throw std::runtime_error("Error parsing polygon. Check input!"); m_points.push_back({pt[0], pt[1]}); } for (const auto &p : path) { Loading
src/csg/cgal_helper_polyhedron.cpp +6 −0 Original line number Diff line number Diff line #include "csg_cgal_helper.hpp" #include <stdexcept> #include <CGAL/AABB_face_graph_triangle_primitive.h> #include <CGAL/AABB_traits.h> #include <CGAL/AABB_tree.h> Loading Loading @@ -46,6 +48,10 @@ public: // Add facets next for (const auto &face : m_faces) { B.begin_facet(); if (!B.test_facet(face.begin(), face.end())) throw std::runtime_error( "Unable to create the polyhedron. Check input!"); for (const auto &p_index : face) { B.add_vertex_to_facet(p_index); } Loading
src/csg/parser.cpp +12 −5 Original line number Diff line number Diff line // standard includes #include <assert.h> #include <iostream> #include <memory> #include <stdexcept> // subproject includes #include <tao/pegtl.hpp> Loading Loading @@ -511,7 +511,7 @@ template <> struct action<cylinder> { 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); throw std::runtime_error("Error parsing cylinder. Check input!"); } csg::Cylinder cyl; cyl.name = get_name(curr_attr); Loading Loading @@ -590,7 +590,8 @@ template <> struct action<polygon> { std::vector<std::vector<double>> paths = {{}}; if (std::holds_alternative<std::string>(curr_attr["paths"])) { assert(std::get<std::string>(curr_attr["paths"]) == UNDEFINED_STR); if (std::get<std::string>(curr_attr["paths"]) != UNDEFINED_STR) throw std::runtime_error("Error parsing polygon. Check inputs!"); } else { paths = std::get<std::vector<std::vector<double>>>(curr_attr["paths"]); } Loading Loading @@ -727,12 +728,18 @@ std::shared_ptr<Tree> parse_csg(std::string str) { } auto st = maybe_state.value(); assert(st.current_3d_objs.size() == 1); if (st.current_3d_objs.size() != 1) throw std::runtime_error("Error parsing. Check input!"); Tree tree; for (auto obj : st.current_3d_objs.back()) { tree.top.objs.push_back(obj); } assert(tree.top.objs.size() > 0); // Disallow empty .csg file if (tree.top.objs.empty()) throw std::runtime_error( "Error parsing. Check input!"); // Disallow empty .csg file return std::make_shared<Tree>(tree); } } // namespace csg