Some cleanup and further optimization to 5f521b24c42ed657967b919871900fa6a65ba790. #3293

This commit is contained in:
Alessandro Ranellucci 2016-07-10 13:38:33 +02:00
parent 3daf64ae56
commit 6f1d1f6af7
4 changed files with 21 additions and 12 deletions

View File

@ -490,21 +490,18 @@ sub process_layer {
# group extrusions by extruder and then by island # group extrusions by extruder and then by island
my %by_extruder = (); # extruder_id => [ { perimeters => \@perimeters, infill => \@infill } ] my %by_extruder = (); # extruder_id => [ { perimeters => \@perimeters, infill => \@infill } ]
my $n_slices = $#{$layer->slices}; # cache bounding boxes of layer slices
my @layer_surface_bboxes = (); my @layer_slices_bb = map $_->contour->bounding_box, @{$layer->slices};
for my $i (0 .. $n_slices) {
push @layer_surface_bboxes, $layer->slices->[$i]->contour->bounding_box;
}
my $point_inside_surface = sub { my $point_inside_surface = sub {
my ($i, $point) = @_; my ($i, $point) = @_;
my $bbox = $layer_surface_bboxes[$i];
return my $bbox = $layer_slices_bb[$i];
$point->x >= $bbox->x_min && $point->x < $bbox->x_max && return $layer_slices_bb[$i]->contains_point($point)
$point->y >= $bbox->y_min && $point->y < $bbox->y_max && && $layer->slices->[$i]->contour->contains_point($point);
$layer->slices->[$i]->contour->contains_point($point);
}; };
my $n_slices = $layer->slices->count - 1;
foreach my $region_id (0..($self->print->region_count-1)) { foreach my $region_id (0..($self->print->region_count-1)) {
my $layerm = $layer->regions->[$region_id] or next; my $layerm = $layer->regions->[$region_id] or next;
my $region = $self->print->get_region($region_id); my $region = $self->print->get_region($region_id);

View File

@ -219,4 +219,13 @@ BoundingBox3Base<PointClass>::center() const
} }
template Pointf3 BoundingBox3Base<Pointf3>::center() const; template Pointf3 BoundingBox3Base<Pointf3>::center() const;
template <class PointClass> bool
BoundingBoxBase<PointClass>::contains(const PointClass &point) const
{
return point.x >= this->min.x && point.x <= this->max.x
&& point.y >= this->min.y && point.y <= this->max.y;
}
template bool BoundingBoxBase<Point>::contains(const Point &point) const;
template bool BoundingBoxBase<Pointf>::contains(const Pointf &point) const;
} }

View File

@ -30,6 +30,7 @@ class BoundingBoxBase
void translate(coordf_t x, coordf_t y); void translate(coordf_t x, coordf_t y);
void offset(coordf_t delta); void offset(coordf_t delta);
PointClass center() const; PointClass center() const;
bool contains(const PointClass &point) const;
}; };
template <class PointClass> template <class PointClass>

View File

@ -16,6 +16,7 @@
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
void offset(double delta); void offset(double delta);
bool contains_point(Point* point) %code{% RETVAL = THIS->contains(*point); %};
Clone<Polygon> polygon(); Clone<Polygon> polygon();
Clone<Point> size(); Clone<Point> size();
Clone<Point> center(); Clone<Point> center();
@ -49,6 +50,7 @@ new_from_points(CLASS, points)
void merge_point(Pointf* point) %code{% THIS->merge(*point); %}; void merge_point(Pointf* point) %code{% THIS->merge(*point); %};
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
bool contains_point(Pointf* point) %code{% RETVAL = THIS->contains(*point); %};
Clone<Pointf> size(); Clone<Pointf> size();
Clone<Pointf> center(); Clone<Pointf> center();
Clone<Pointf> min_point() %code{% RETVAL = THIS->min; %}; Clone<Pointf> min_point() %code{% RETVAL = THIS->min; %};