Commit b21d7225 authored by Deepak Rangarajan's avatar Deepak Rangarajan Committed by Mark Meredith
Browse files

Fix parsing empty objects

parent d5348a1f
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ double signed_distance_2d(const Intersection2D &group, double xx, double yy) {
}

double signed_distance_2d(const Difference2D &group, double xx, double yy) {
  if (group.first_obj == nullptr)
    return -std::numeric_limits<double>::max();

  auto sdist = signed_distance_2d(*group.first_obj, xx, yy);

  for (const auto &member : group.next_objs.objs) {
+3 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ double signed_distance_3d(const Intersection3D &group, double xx, double yy,

double signed_distance_3d(const Difference3D &group, double xx, double yy,
                          double zz) {
  if (group.first_obj == nullptr)
    return -std::numeric_limits<double>::max();

  auto sdist = signed_distance_3d(*group.first_obj, xx, yy, zz);

  for (const auto &member : group.next_objs.objs) {
+9 −0
Original line number Diff line number Diff line
@@ -292,6 +292,7 @@ void add_group_2d(parser_state &st) {
  for (const auto &curr_obj : st.current_2d_group) {
    group.objs.push_back(curr_obj);
  }
  st.current_2d_group.clear();
  st.current_2d_objs.back().push_back(group);
}

@@ -300,6 +301,7 @@ void add_group_3d(parser_state &st) {
  for (const auto &curr_obj : st.current_3d_group) {
    group.objs.push_back(curr_obj);
  }
  st.current_3d_group.clear();
  st.current_3d_objs.back().push_back(group);
}

@@ -359,6 +361,7 @@ template <> struct action<bool_intersection<Dimension::D3>> {
    for (const auto &curr_obj : st.current_3d_group) {
      csg_in.objs.push_back(curr_obj);
    }
    st.current_3d_group.clear();
    st.current_3d_objs.back().push_back(csg_in);
  }
};
@@ -371,6 +374,7 @@ template <> struct action<bool_intersection<Dimension::D2>> {
    for (const auto &curr_obj : st.current_2d_group) {
      csg_in.objs.push_back(curr_obj);
    }
    st.current_2d_group.clear();
    st.current_2d_objs.back().push_back(csg_in);
  }
};
@@ -388,6 +392,7 @@ template <> struct action<bool_diff<Dimension::D3>> {
        csg_diff.next_objs.objs.push_back(*it);
      }
    }
    st.current_3d_group.clear();
    st.current_3d_objs.back().push_back(csg_diff);
  }
};
@@ -405,6 +410,7 @@ template <> struct action<bool_diff<Dimension::D2>> {
        csg_diff.next_objs.objs.push_back(*it);
      }
    }
    st.current_2d_group.clear();
    st.current_2d_objs.back().push_back(csg_diff);
  }
};
@@ -470,6 +476,7 @@ template <> struct action<extrude_lin> {
      lin_ext.group.objs.push_back(curr_obj);
    }

    st.current_2d_group.clear();
    st.current_3d_objs.back().push_back(lin_ext);
    st.curr_attrs.pop_back();
  }
@@ -493,6 +500,7 @@ template <> struct action<extrude_rot> {
      rot_ext.group.objs.push_back(curr_obj);
    }

    st.current_3d_group.clear();
    st.current_3d_objs.back().push_back(rot_ext);
    st.curr_attrs.pop_back();
  }
@@ -525,6 +533,7 @@ template <> struct action<hull> {
        }
      }
    }
    st.current_3d_group.clear();

    // If the conditions were not met and throw exception
    std::string except_src = "action<hull>";
+2 −0
Original line number Diff line number Diff line
@@ -4,12 +4,14 @@

add_executable(unit_tests_csg EXCLUDE_FROM_ALL
  levelset/boolean.t.cpp
  levelset/empty.t.cpp
  levelset/extrude.t.cpp
  levelset/hull.t.cpp
  levelset/internal_flow.t.cpp
  levelset/primitives.t.cpp
  levelset/transform.t.cpp
  parser/boolean.t.cpp
  parser/empty.t.cpp
  parser/extrude.t.cpp
  parser/hull.t.cpp
  parser/nest.cpp
+45 −0
Original line number Diff line number Diff line
#include "catch2/catch.hpp"

#include <csg.hpp>
#include <csg_types.hpp>

#include <memory>

namespace {

TEST_CASE("Empty Difference3D", "[Levelset Boolean]") {
  auto my_diff = csg::Difference3D();

  auto my_tree = std::make_shared<csg::Tree>();
  my_tree->top.objs.push_back(my_diff);
  csg::CsgIF my_levelset(my_tree);

  // Any point should lie outside!
  CHECK_FALSE(0 < my_levelset(0, 0, 0));
  CHECK_FALSE(0 < my_levelset(0, 7, 0));
  CHECK_FALSE(0 < my_levelset(0, 0, -7.5));
  CHECK_FALSE(0 < my_levelset(0, -9, 0));
  CHECK_FALSE(0 < my_levelset(9, 0, 0));
}

TEST_CASE("Empty Difference2D", "[Levelset Boolean]") {
  double height = 100, radius = 10;
  auto my_lin_ext = csg::LinearExtrude{
      .height = 100, .center = false, .scale = {1, 1}, .group = csg::Union2D()};
  auto my_diff = csg::Difference2D();

  my_lin_ext.center = false;
  my_lin_ext.group.objs.push_back(my_diff);
  auto my_tree = std::make_shared<csg::Tree>();
  my_tree->top.objs.push_back(my_lin_ext);
  csg::CsgIF my_levelset(my_tree);

  // Any point should lie outside!
  CHECK_FALSE(0 < my_levelset(0, 0, 0));
  CHECK_FALSE(0 < my_levelset(0, 7, 0));
  CHECK_FALSE(0 < my_levelset(0, 0, -7.5));
  CHECK_FALSE(0 < my_levelset(0, -9, 0));
  CHECK_FALSE(0 < my_levelset(9, 0, 0));
}

}
Loading