Got rid of Math::Geometry::Planar

This commit is contained in:
Alessandro Ranellucci 2011-10-06 12:39:58 +02:00
parent e2d2574b8b
commit bfd1d0e1dd
6 changed files with 11 additions and 62 deletions

View File

@ -11,8 +11,7 @@ my $build = Module::Build->new(
'File::Basename' => '0',
'Getopt::Long' => '0',
'Math::Clipper' => '1.01',
'Math::Geometry::Planar' => '0',
'Math::Geometry::Planar::Offset' => '0',
'Math::ConvexHull' => '1.0.4',
'Moo' => '0',
'Time::HiRes' => '0',
'XXX' => '0',

View File

@ -11,7 +11,6 @@ use constant B => 1;
use constant X => 0;
use constant Y => 1;
use Math::Geometry::Planar;
use POSIX qw(ceil);
use XXX;
@ -28,7 +27,7 @@ sub make_fill {
SURFACE: foreach my $surface (@{ $surface_collection->surfaces }) {
Slic3r::debugf " Processing surface %s:\n", $surface->id;
my $polygon = $surface->mgp_polygon;
my $polygons = [ $surface->p ];
# set infill angle
my (@rotate, @shift);
@ -45,7 +44,8 @@ sub make_fill {
# rotate surface as needed
@shift = @{ +(Slic3r::Geometry::rotate_points(@rotate, \@shift))[0] };
$polygon = $polygon->rotate(@rotate)->move(@shift) if $rotate[0];
@$polygons = map [ Slic3r::Geometry::move_points(\@shift, @$_) ],
map [ Slic3r::Geometry::rotate_points(@rotate, @$_) ], @$polygons if $rotate[0];
# force 100% density for external surfaces
my $density = $surface->surface_type eq 'internal' ? $Slic3r::fill_density : 1;
@ -59,7 +59,7 @@ sub make_fill {
# this arrayref will hold intersection points of the fill grid with surface segments
my $points = [ map [], 0..$number_of_lines-1 ];
foreach my $line (map $self->_lines_from_mgp_points($_), @{ $polygon->polygons }) {
foreach my $line (map Slic3r::Geometry::polygon_lines($_), @$polygons) {
# find out the coordinates
my @coordinates = map @$_, @$line;
@ -134,7 +134,7 @@ sub make_fill {
my @search_points = @$row;
@search_points = reverse @search_points if $direction == 1;
my @connectable_points = $self->find_connectable_points($polygon, $path_points[-1], $c, [@search_points]);
my @connectable_points = $self->find_connectable_points($polygons, $path_points[-1], $c, [@search_points]);
Slic3r::debugf " ==> found %d connectable points = %s\n", scalar(@connectable_points),
join ', ', @connectable_points if $Slic3r::debug;
@ -181,11 +181,11 @@ sub make_fill {
# points connectable to a given one
sub find_connectable_points {
my $self = shift;
my ($polygon, $point, $c, $points) = @_;
my ($polygons, $point, $c, $points) = @_;
my @connectable_points = ();
foreach my $p (@$points) {
if (!Slic3r::Geometry::can_connect_points($point, [ $c, $p ], [ $polygon->get_polygons ])) {
if (!Slic3r::Geometry::can_connect_points($point, [ $c, $p ], $polygons)) {
@connectable_points ? last : next;
}
push @connectable_points, $p;
@ -194,25 +194,4 @@ sub find_connectable_points {
return @connectable_points;
}
sub _lines_from_mgp_points {
my $self = shift;
my ($points) = @_;
my @lines = ();
my $last_point = $points->[-1];
foreach my $point (@$points) {
push @lines, [ $last_point, $point ];
$last_point = $point;
}
return @lines;
}
sub _mgp_from_points_ref {
my $self = shift;
my ($points) = @_;
my $p = Math::Geometry::Planar->new;
$p->points($points);
return $p;
}
1;

View File

@ -2,7 +2,6 @@ package Slic3r::Layer;
use Moo;
use Math::Clipper ':all';
use Math::Geometry::Planar;
use XXX;
# a sequential number of layer, starting at 0

View File

@ -2,7 +2,7 @@ package Slic3r::Perimeter;
use Moo;
use Math::Clipper ':all';
use Math::Geometry::Planar;
use Math::ConvexHull qw(convex_hull);
use XXX;
use constant X => 0;
@ -77,14 +77,12 @@ sub make_perimeter {
# generate skirt on bottom layer
if ($layer->id == 0 && $Slic3r::skirts > 0 && @{ $layer->surfaces }) {
# find out convex hull
my $points = [ map { @{ $_->mgp_polygon->polygons->[0] } } @{ $layer->surfaces } ];
my $convex_hull = $self->_mgp_from_points_ref($points)->convexhull2; # maybe Math::ConvexHull is faster?
my $convex_hull_points = ref $convex_hull eq 'ARRAY' ? $convex_hull : $convex_hull->points;
my $convex_hull = convex_hull([ map @$_, map $_->p, @{ $layer->surfaces } ]);
# draw outlines from outside to inside
for (my $i = $Slic3r::skirts - 1; $i >= 0; $i--) {
my $distance = ($Slic3r::skirt_distance + ($Slic3r::flow_width * $i)) / $Slic3r::resolution;
my $outline = offset([$convex_hull_points], $distance, $Slic3r::resolution * 100, JT_ROUND);
my $outline = offset([$convex_hull], $distance, $Slic3r::resolution * 100, JT_ROUND);
push @{ $layer->skirts }, Slic3r::ExtrusionLoop->cast([ @{$outline->[0]} ]);
}
}
@ -120,12 +118,4 @@ sub offset_polygon {
return @$results;
}
sub _mgp_from_points_ref {
my $self = shift;
my ($points) = @_;
my $p = Math::Geometry::Planar->new;
$p->points($points);
return $p;
}
1;

View File

@ -32,12 +32,4 @@ sub encloses_point {
return Slic3r::Geometry::point_in_polygon($point->p, $self->p);
}
sub mgp_polygon {
my $self = shift;
my $p = Math::Geometry::Planar->new;
$p->points($self->points);
return $p;
}
1;

View File

@ -1,8 +1,6 @@
package Slic3r::Surface;
use Moo;
use Math::Geometry::Planar;
has 'contour' => (
is => 'ro',
#isa => 'Slic3r::Polyline::Closed',
@ -42,14 +40,6 @@ sub encloses_point {
return 1;
}
sub mgp_polygon {
my $self = shift;
my $p = Math::Geometry::Planar->new;
$p->polygons([ $self->contour->p, map($_->p, @{ $self->holes }) ]);
return $p;
}
sub clipper_polygon {
my $self = shift;