test_dense_infill.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //#define CATCH_CONFIG_DISABLE
  2. //#include <catch2/catch.hpp>
  3. #include <catch_main.hpp>
  4. //#include <catch2/catch.hpp>
  5. #include <string>
  6. #include "test_data.hpp"
  7. #include <libslic3r/libslic3r.h>
  8. //#include <libslic3r/ModelArrange.hpp>
  9. //#include <libslic3r/SVG.hpp>
  10. //#include <libslic3r/SVG.hpp>
  11. //#include <libslic3r/Print.hpp>
  12. using namespace Slic3r::Test;
  13. using namespace Slic3r;
  14. using namespace std::literals;
  15. Slic3r::Polygon get_polygon_scale(std::vector<std::vector<float>> points) {
  16. Slic3r::Polygon poly;
  17. for (std::vector<float>& point : points) {
  18. poly.points.push_back(Point::new_scale(point[0], point[1]));
  19. }
  20. return poly;
  21. }
  22. SCENARIO("test auto generation") {
  23. GIVEN("triangle with top to fill") {
  24. //DynamicPrintConfig& config = Slic3r::DynamicPrintConfig::full_print_config();
  25. //config.set_key_value("fill_density", new ConfigOptionPercent(0));
  26. //config.set_deserialize("nozzle_diameter", "0.4");
  27. //config.set_deserialize("layer_height", "0.3");
  28. //config.set_deserialize("infill_dense_algo", "50");
  29. //config.set_deserialize("extruder_clearance_radius", "10");
  30. WHEN("little surface") {
  31. ExPolygon polygon_to_cover;
  32. polygon_to_cover.contour = get_polygon_scale({ {0,0}, {10,0}, {10,10}, {0,10} });
  33. ExPolygon growing_area;
  34. growing_area.contour = get_polygon_scale({ {0,0}, {40,0}, {0,40} });
  35. ExPolygons allowedPoints;
  36. allowedPoints.emplace_back();
  37. //diff_ex(offset_ex(growing_area, scale_(1)), offset_ex(layerm->fill_no_overlap_expolygons, double(-layerm->flow(frInfill).scaled_width())));
  38. allowedPoints.back().contour = get_polygon_scale({ {0,0}, {40,0}, {0,40} });
  39. coord_t offset = scale_(2);
  40. float coverage = 1.f;
  41. ExPolygons solution = dense_fill_fit_to_size(polygon_to_cover, allowedPoints, growing_area, offset, coverage);
  42. THEN("little support") {
  43. double area_result = 0;
  44. for (ExPolygon& p : solution)
  45. area_result += unscaled(unscaled(p.area()));
  46. double area_full = unscaled(unscaled(growing_area.area()));
  47. //for (ExPolygon& p : allowedPoints)
  48. // area_full += unscaled(unscaled(p.area());
  49. for (ExPolygon& po : solution)
  50. for (Point& p : po.contour.points)
  51. std::cout << ", " << unscaled(p.x()) << ":" << unscaled(p.y());
  52. std::cout << "\n";
  53. std::cout << "area_result= " << area_result << "\n";
  54. std::cout << "area_full = " << area_full << "\n";
  55. REQUIRE(area_full > 1.5 * area_result);
  56. }
  57. }
  58. //THEN("(too near)") {
  59. // result = init_print_with_dist(config, 40)->validate();
  60. // REQUIRE(result.first == PrintBase::PrintValidationError::pveWrongPosition);
  61. //}
  62. //THEN("(ok far)") {
  63. // result = init_print_with_dist(config, 40.8)->validate();
  64. // REQUIRE(result.second == "");
  65. // REQUIRE(result.first == PrintBase::PrintValidationError::pveNone);
  66. //}
  67. }
  68. }