test_utils.hpp 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef SLIC3R_TEST_UTILS
  2. #define SLIC3R_TEST_UTILS
  3. #include <libslic3r/TriangleMesh.hpp>
  4. #include <libslic3r/Format/OBJ.hpp>
  5. #include <random>
  6. #if defined(WIN32) || defined(_WIN32)
  7. #define PATH_SEPARATOR R"(\)"
  8. #else
  9. #define PATH_SEPARATOR R"(/)"
  10. #endif
  11. inline Slic3r::TriangleMesh load_model(const std::string &obj_filename)
  12. {
  13. Slic3r::TriangleMesh mesh;
  14. auto fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename;
  15. Slic3r::load_obj(fpath.c_str(), &mesh);
  16. return mesh;
  17. }
  18. template<class T>
  19. Slic3r::FloatingOnly<T> random_value(T minv, T maxv)
  20. {
  21. static std::mt19937 rng(std::random_device{}());
  22. std::uniform_real_distribution<T> dist(minv, maxv);
  23. return dist(rng);
  24. }
  25. template<class T>
  26. Slic3r::IntegerOnly<T> random_value(T minv, T maxv)
  27. {
  28. static std::mt19937 rng(std::random_device{}());
  29. std::uniform_int_distribution<T> dist(minv, maxv);
  30. return dist(rng);
  31. }
  32. #endif // SLIC3R_TEST_UTILS