From e0da81e8bf6394fa55dde4109675859e4f00e0c2 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 17 Sep 2013 23:38:23 +0200 Subject: [PATCH] Introduce a ->count method for all collections to save time --- lib/Slic3r/Fill.pm | 2 +- lib/Slic3r/GCode/Layer.pm | 4 ++-- lib/Slic3r/Print.pm | 2 +- xs/xsp/ExPolygonCollection.xsp | 2 ++ xs/xsp/ExtrusionEntityCollection.xsp | 2 ++ xs/xsp/PolylineCollection.xsp | 2 ++ xs/xsp/SurfaceCollection.xsp | 2 ++ 7 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/Fill.pm b/lib/Slic3r/Fill.pm index 4b6ecf03..8e2f51e0 100644 --- a/lib/Slic3r/Fill.pm +++ b/lib/Slic3r/Fill.pm @@ -191,7 +191,7 @@ sub make_fill { } # add thin fill regions - if (@{ $layerm->thin_fills }) { + if ($layerm->thin_fills->count > 0) { push @fills, Slic3r::ExtrusionPath::Collection->new(@{$layerm->thin_fills}); push @fills_ordering_points, $fills[-1]->first_point; } diff --git a/lib/Slic3r/GCode/Layer.pm b/lib/Slic3r/GCode/Layer.pm index 5e76fccd..5cb858e6 100644 --- a/lib/Slic3r/GCode/Layer.pm +++ b/lib/Slic3r/GCode/Layer.pm @@ -109,12 +109,12 @@ sub process_layer { # extrude support material before other things because it might use a lower Z # and also because we avoid travelling on other things when printing it if ($self->print->has_support_material && $layer->isa('Slic3r::Layer::Support')) { - if ($layer->support_interface_fills) { + if ($layer->support_interface_fills->count > 0) { $gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_interface_extruder-1]); $gcode .= $self->gcodegen->extrude_path($_, 'support material interface') for @{$layer->support_interface_fills->chained_path_from($self->gcodegen->last_pos, 0)}; } - if ($layer->support_fills) { + if ($layer->support_fills->count > 0) { $gcode .= $self->gcodegen->set_extruder($self->extruders->[$Slic3r::Config->support_material_extruder-1]); $gcode .= $self->gcodegen->extrude_path($_, 'support material') for @{$layer->support_fills->chained_path_from($self->gcodegen->last_pos, 0)}; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d64abde6..bd6ef934 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -177,7 +177,7 @@ sub validate { for my $copy (@{$self->objects->[$obj_idx]->copies}) { my $copy_clearance = $clearance->clone; $copy_clearance->translate(@$copy); - if (@{ intersection_ex(\@a, [$copy_clearance]) }) { + if (@{ intersection(\@a, [$copy_clearance]) }) { die "Some objects are too close; your extruder will collide with them.\n"; } @a = map @$_, @{union_ex([ @a, $copy_clearance ])}; diff --git a/xs/xsp/ExPolygonCollection.xsp b/xs/xsp/ExPolygonCollection.xsp index 50d6dda8..0e6e50c0 100644 --- a/xs/xsp/ExPolygonCollection.xsp +++ b/xs/xsp/ExPolygonCollection.xsp @@ -14,6 +14,8 @@ void scale(double factor); void translate(double x, double y); void rotate(double angle, Point* center); + int count() + %code{% RETVAL = THIS->expolygons.size(); %}; %{ ExPolygonCollection* diff --git a/xs/xsp/ExtrusionEntityCollection.xsp b/xs/xsp/ExtrusionEntityCollection.xsp index 5870b3c8..1bd7a2c4 100644 --- a/xs/xsp/ExtrusionEntityCollection.xsp +++ b/xs/xsp/ExtrusionEntityCollection.xsp @@ -18,6 +18,8 @@ %code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->first_point(); %}; Point* last_point() %code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->last_point(); %}; + int count() + %code{% RETVAL = THIS->entities.size(); %}; %{ void diff --git a/xs/xsp/PolylineCollection.xsp b/xs/xsp/PolylineCollection.xsp index e26cd504..7256e83f 100644 --- a/xs/xsp/PolylineCollection.xsp +++ b/xs/xsp/PolylineCollection.xsp @@ -15,6 +15,8 @@ %code{% const char* CLASS = "Slic3r::Polyline::Collection"; RETVAL = THIS->chained_path(no_reverse); %}; PolylineCollection* chained_path_from(Point* start_near, bool no_reverse) %code{% const char* CLASS = "Slic3r::Polyline::Collection"; RETVAL = THIS->chained_path_from(start_near, no_reverse); %}; + int count() + %code{% RETVAL = THIS->polylines.size(); %}; %{ PolylineCollection* diff --git a/xs/xsp/SurfaceCollection.xsp b/xs/xsp/SurfaceCollection.xsp index 512b06f0..08d2aa16 100644 --- a/xs/xsp/SurfaceCollection.xsp +++ b/xs/xsp/SurfaceCollection.xsp @@ -9,6 +9,8 @@ ~SurfaceCollection(); void clear() %code{% THIS->surfaces.clear(); %}; + int count() + %code{% RETVAL = THIS->surfaces.size(); %}; %{ SurfaceCollection*