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

Switch from assert to throw, add check for polyhedron

parent 67b91123
Loading
Loading
Loading
Loading
Loading
+6 −12
Changes for include/csg_types.hpp: 6 added lines, 12 removed lines.
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));
    }
+1 −0
Changes for src/csg/CMakeLists.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ add_library(csg
  levelset_3d.cpp
  matrix_functions.cpp
  parser.cpp
  exception.cpp
  )

target_link_libraries(csg PRIVATE
+6 −0
Changes for src/csg/cgal_helper_polyhedron.cpp: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include "csg_cgal_helper.hpp"
#include "csg_exception.hpp"

#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_traits.h>
@@ -46,6 +47,11 @@ public:
    // Add facets next
    for (const auto &face : m_faces) {
      B.begin_facet();
      if (!B.test_facet(face.begin(), face.end()))
        throw csg::Exception(
            "Polyhedron builder",
            "Unable to create the polyhedron. test_facet failed. Check input!");

      for (const auto &p_index : face) {
        B.add_vertex_to_facet(p_index);
      }

src/csg/exception.cpp

0 → 100644
+27 −0
Changes for src/csg/exception.cpp: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
#include "csg_exception.hpp"

#include <sstream>
#include <string>

namespace csg {

Exception::Exception() : m_msg(make_message("No Source", "No message")) {}

Exception::Exception(const std::string &message)
    : m_msg(make_message("No Source", message)) {}

Exception::Exception(const std::string &source, const std::string &message)
    : m_msg(make_message(source, message)) {}

const char *Exception::what() const noexcept { return m_msg.c_str(); }

std::string Exception::make_message(const std::string &source,
                                    const std::string &message) {
  std::stringstream s;
  s << "Exception Data:" << std::endl;
  s << "Source  : " << source << std::endl;
  s << "Message : " << message << std::endl;
  return s.str();
}

} // namespace csg
+1 −0
Changes for src/csg/meson.build: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ lib_csg_parser = static_library('csg-parser',
  'levelset_3d.cpp',
  'matrix_functions.cpp',
  'parser.cpp',
  'exception.cpp',
  include_directories: parser_inc,
  dependencies: [pegtl, cgal],
  install : true)
Loading