PlanePath.pm 1.6 KB

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