test_utils.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. inline std::string get_model_path(const std::string &obj_filename)
  19. {
  20. std::string fpath = TEST_DATA_DIR PATH_SEPARATOR + obj_filename;
  21. return fpath;
  22. }
  23. template<class T>
  24. Slic3r::FloatingOnly<T> random_value(T minv, T maxv)
  25. {
  26. static std::mt19937 rng(std::random_device{}());
  27. std::uniform_real_distribution<T> dist(minv, maxv);
  28. return dist(rng);
  29. }
  30. template<class T>
  31. Slic3r::IntegerOnly<T> random_value(T minv, T maxv)
  32. {
  33. static std::mt19937 rng(std::random_device{}());
  34. std::uniform_int_distribution<T> dist(minv, maxv);
  35. return dist(rng);
  36. }
  37. #endif // SLIC3R_TEST_UTILS