Commit 8e2c88a2 authored by Deepak Rangarajan's avatar Deepak Rangarajan
Browse files

Move assert checks into parser exceptions

parent 639b59ab
Loading
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -58,12 +58,9 @@ private:

public:
  std::optional<std::string> name;
  Polyhedron(const std::vector<std::vector<double>> &points,
             const std::vector<std::vector<double>> &faces) {
    for (const auto &pt : points) {
      assert(pt.size() == 3);
      m_points.push_back({pt[0], pt[1], pt[2]});
    }
  Polyhedron(const std::vector<std::tuple<double, double, double>> &points,
             const std::vector<std::vector<double>> &faces)
      : m_points(points) {
    for (const auto &f : faces) {
      m_faces.push_back(std::vector<unsigned int>(f.begin(), f.end()));
    }
@@ -83,12 +80,9 @@ private:

public:
  std::optional<std::string> name;
  Polygon(const std::vector<std::vector<double>> &points,
          const std::vector<double> &path) {
    for (const auto &pt : points) {
      assert(pt.size() == 2);
      m_points.push_back({pt[0], pt[1]});
    }
  Polygon(const std::vector<std::tuple<double, double>> &points,
          const std::vector<double> &path)
      : m_points(points) {
    for (const auto &p : path) {
      m_path.push_back((unsigned int)(p));
    }
+16 −2
Original line number Diff line number Diff line
@@ -586,9 +586,16 @@ template <> struct action<polygon> {
    std::stringstream ss(in.string());
    auto &curr_attr = st.curr_attrs.back();

    auto points =
    auto points_raw =
        std::get<std::vector<std::vector<double>>>(curr_attr["points"]);

    std::vector<std::tuple<double, double>> points;
    for (const auto &pt : points_raw) {
      if (pt.size() != 2)
        throw csg::Exception("action<polygon>", "pt.size() != 2");
      points.push_back({pt[0], pt[1]});
    }

    std::vector<std::vector<double>> paths = {{}};
    if (std::holds_alternative<std::string>(curr_attr["paths"])) {
      auto paths_str = std::get<std::string>(curr_attr["paths"]);
@@ -620,10 +627,17 @@ template <> struct action<polyhedron> {
    std::stringstream ss(in.string());
    auto &curr_attr = st.curr_attrs.back();

    auto points =
    auto points_raw =
        std::get<std::vector<std::vector<double>>>(curr_attr["points"]);
    auto faces = std::get<std::vector<std::vector<double>>>(curr_attr["faces"]);

    std::vector<std::tuple<double, double, double>> points;
    for (const auto &pt : points_raw) {
      if (pt.size() != 3)
        throw csg::Exception("action<polyhedron>", "pt.size() != 3");
      points.push_back({pt[0], pt[1], pt[2]});
    }

    csg::Polyhedron polyh(points, faces);
    polyh.name = get_name(curr_attr);