PlanePath.pm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package Slic3r::Fill::PlanePath;
  2. use Moo;
  3. extends 'Slic3r::Fill::Base';
  4. use Slic3r::Geometry qw(scale bounding_box X1 Y1 X2 Y2);
  5. sub multiplier () { 1 }
  6. sub get_n {
  7. my $self = shift;
  8. my ($path, $bounding_box) = @_;
  9. my ($n_lo, $n_hi) = $path->rect_to_n_range(@$bounding_box);
  10. return ($n_lo .. $n_hi);
  11. }
  12. sub process_polyline {}
  13. sub fill_surface {
  14. my $self = shift;
  15. my ($surface, %params) = @_;
  16. # rotate polygons
  17. my $expolygon = $surface->expolygon->clone;
  18. my $rotate_vector = $self->infill_direction($surface);
  19. $self->rotate_points($expolygon, $rotate_vector);
  20. my $distance_between_lines = scale $params{flow_spacing} / $params{density} * $self->multiplier;
  21. my $bounding_box = [ bounding_box(map @$_, $expolygon) ];
  22. my $bounding_box_polygon = Slic3r::Polygon->new([
  23. [ $bounding_box->[X1], $bounding_box->[Y1] ],
  24. [ $bounding_box->[X2], $bounding_box->[Y1] ],
  25. [ $bounding_box->[X2], $bounding_box->[Y2] ],
  26. [ $bounding_box->[X1], $bounding_box->[Y2] ],
  27. ]);
  28. (ref $self) =~ /::([^:]+)$/;
  29. my $path = "Math::PlanePath::$1"->new;
  30. my @n = $self->get_n($path, [map +($_ / $distance_between_lines), @$bounding_box]);
  31. my $polyline = Slic3r::Polyline->new([
  32. map [ map {$_*$distance_between_lines} $path->n_to_xy($_) ], @n,
  33. ]);
  34. return {} if !@$polyline;
  35. $self->process_polyline($polyline, $bounding_box);
  36. my @paths = map $_->clip_with_expolygon($expolygon),
  37. $polyline->clip_with_polygon($bounding_box_polygon);
  38. if (0) {
  39. require "Slic3r/SVG.pm";
  40. Slic3r::SVG::output(undef, "fill.svg",
  41. polygons => $expolygon,
  42. polylines => [map $_->p, @paths],
  43. );
  44. }
  45. # paths must be rotated back
  46. $self->rotate_points_back(\@paths, $rotate_vector);
  47. return {}, @paths;
  48. }
  49. 1;