Removed offset() method from Slic3r::Polygon because it only works with ccw polygons

This commit is contained in:
Alessandro Ranellucci 2013-03-26 14:03:24 +01:00
parent 4c41f6c462
commit 2f046799f2
5 changed files with 12 additions and 13 deletions

View File

@ -13,7 +13,7 @@ has '_crossing_edges' => (is => 'rw', default => sub { {} }); # edge_idx => boo
use List::Util qw(first); use List::Util qw(first);
use Slic3r::Geometry qw(A B scale epsilon nearest_point); use Slic3r::Geometry qw(A B scale epsilon nearest_point);
use Slic3r::Geometry::Clipper qw(diff_ex JT_MITER); use Slic3r::Geometry::Clipper qw(diff_ex offset JT_MITER);
# clearance (in mm) from the perimeters # clearance (in mm) from the perimeters
has '_inner_margin' => (is => 'ro', default => sub { scale 0.5 }); has '_inner_margin' => (is => 'ro', default => sub { scale 0.5 });
@ -68,7 +68,8 @@ sub BUILD {
: [ $self->islands->[$i]->offset_ex(-$self->_inner_margin) ]; : [ $self->islands->[$i]->offset_ex(-$self->_inner_margin) ];
# offset the island outwards to make the boundaries for external movements # offset the island outwards to make the boundaries for external movements
$self->_outer->[$i] = [ $self->islands->[$i]->contour->offset($self->_outer_margin) ]; $self->_outer->[$i] = [ offset([ $self->islands->[$i]->contour], $self->_outer_margin) ];
bless $_, 'Slic3r::Polygon' for @{ $self->_outer->[$i] };
# if internal motion is enabled, build a set of utility expolygons representing # if internal motion is enabled, build a set of utility expolygons representing
# the outer boundaries (as contours) and the inner boundaries (as holes). whenever # the outer boundaries (as contours) and the inner boundaries (as holes). whenever

View File

@ -7,7 +7,7 @@ use File::Basename qw(basename dirname);
use List::Util qw(max sum first); use List::Util qw(max sum first);
use Math::ConvexHull::MonotoneChain qw(convex_hull); use Math::ConvexHull::MonotoneChain qw(convex_hull);
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX); use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX);
use Slic3r::Geometry::Clipper qw(JT_ROUND); use Slic3r::Geometry::Clipper qw(offset JT_ROUND);
use threads::shared qw(shared_clone); use threads::shared qw(shared_clone);
use Wx qw(:bitmap :brush :button :cursor :dialog :filedialog :font :keycode :icon :id :listctrl :misc :panel :pen :sizer :toolbar :window); use Wx qw(:bitmap :brush :button :cursor :dialog :filedialog :font :keycode :icon :id :listctrl :misc :panel :pen :sizer :toolbar :window);
use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL EVT_CHOICE); use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_KEY_DOWN EVT_LIST_ITEM_ACTIVATED EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL EVT_CHOICE);
@ -881,7 +881,7 @@ sub repaint {
# if sequential printing is enabled and we have more than one object # if sequential printing is enabled and we have more than one object
if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) { if ($parent->{config}->complete_objects && (map @{$_->instances}, @{$parent->{objects}}) > 1) {
my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, @{$parent->{object_previews}->[-1][2]->expolygons} ])); my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, @{$parent->{object_previews}->[-1][2]->expolygons} ]));
my $clearance = +($convex_hull->offset($parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND))[0]; my ($clearance) = offset([$convex_hull], $parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND);
$dc->SetPen($parent->{clearance_pen}); $dc->SetPen($parent->{clearance_pen});
$dc->SetBrush($parent->{transparent_brush}); $dc->SetBrush($parent->{transparent_brush});
$dc->DrawPolygon($parent->_y($clearance), 0, 0); $dc->DrawPolygon($parent->_y($clearance), 0, 0);
@ -892,7 +892,7 @@ sub repaint {
# draw skirt # draw skirt
if (@{$parent->{object_previews}} && $parent->{config}->skirts) { if (@{$parent->{object_previews}} && $parent->{config}->skirts) {
my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, map @{$_->[2]->expolygons}, @{$parent->{object_previews}} ])); my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->contour}, map @{$_->[2]->expolygons}, @{$parent->{object_previews}} ]));
$convex_hull = +($convex_hull->offset($parent->{config}->skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND))[0]; ($convex_hull) = offset([$convex_hull], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND);
$dc->SetPen($parent->{skirt_pen}); $dc->SetPen($parent->{skirt_pen});
$dc->SetBrush($parent->{transparent_brush}); $dc->SetBrush($parent->{transparent_brush});
$dc->DrawPolygon($parent->_y($convex_hull), 0, 0) if $convex_hull; $dc->DrawPolygon($parent->_y($convex_hull), 0, 0) if $convex_hull;

View File

@ -95,11 +95,6 @@ sub area {
return Slic3r::Geometry::Clipper::area($self); return Slic3r::Geometry::Clipper::area($self);
} }
sub offset {
my $self = shift;
return map Slic3r::Polygon->new($_), Slic3r::Geometry::Clipper::offset([$self], @_);
}
sub grow { sub grow {
my $self = shift; my $self = shift;
return $self->split_at_first_point->grow(@_); return $self->split_at_first_point->grow(@_);
@ -147,7 +142,7 @@ sub is_printable {
# detect them and we would be discarding them. # detect them and we would be discarding them.
my $p = $self->clone; my $p = $self->clone;
$p->make_counter_clockwise; $p->make_counter_clockwise;
return $p->offset(-$width / 2) ? 1 : 0; return Slic3r::Geometry::Clipper::offset([$p], -$width / 2) ? 1 : 0;
} }
sub is_valid { sub is_valid {

View File

@ -86,7 +86,10 @@ sub length {
sub grow { sub grow {
my $self = shift; my $self = shift;
return Slic3r::Polygon->new(@$self, CORE::reverse @$self[1..($#$self-1)])->offset(@_); return Slic3r::Geometry::Clipper::offset(
[ Slic3r::Polygon->new(@$self, CORE::reverse @$self[1..($#$self-1)]) ],
@_,
);
} }
sub nearest_point_to { sub nearest_point_to {

View File

@ -151,7 +151,7 @@ sub validate {
{ {
my @points = map [ @$_[X,Y] ], map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes}; my @points = map [ @$_[X,Y] ], map @{$_->vertices}, @{$self->objects->[$obj_idx]->meshes};
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points)); my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
$clearance = +($convex_hull->offset(scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND))[0]; ($clearance) = offset([$convex_hull], scale $Slic3r::Config->extruder_clearance_radius / 2, 1, JT_ROUND);
} }
for my $copy (@{$self->objects->[$obj_idx]->copies}) { for my $copy (@{$self->objects->[$obj_idx]->copies}) {
my $copy_clearance = $clearance->clone; my $copy_clearance = $clearance->clone;