Skip to content

Commit

Permalink
Ported Slic3r::BridgeDetector to XS
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Nov 15, 2014
1 parent 36825e0 commit 379cde3
Show file tree
Hide file tree
Showing 22 changed files with 539 additions and 307 deletions.
2 changes: 1 addition & 1 deletion lib/Slic3r.pm
Expand Up @@ -58,7 +58,6 @@ use Slic3r::GCode::VibrationLimit;
use Slic3r::Geometry qw(PI);
use Slic3r::Geometry::Clipper;
use Slic3r::Layer;
use Slic3r::Layer::BridgeDetector;
use Slic3r::Layer::Region;
use Slic3r::Line;
use Slic3r::Model;
Expand Down Expand Up @@ -162,6 +161,7 @@ sub thread_cleanup {

# prevent destruction of shared objects
no warnings 'redefine';
*Slic3r::BridgeDetector::DESTROY = sub {};
*Slic3r::Config::DESTROY = sub {};
*Slic3r::Config::Full::DESTROY = sub {};
*Slic3r::Config::GCode::DESTROY = sub {};
Expand Down
17 changes: 0 additions & 17 deletions lib/Slic3r/Geometry.pm
Expand Up @@ -207,23 +207,6 @@ sub polygon_is_convex {
return 1;
}

sub deg2rad {
my ($degrees) = @_;
return PI() * $degrees / 180;
}

sub rad2deg {
my ($rad) = @_;
return $rad / PI() * 180;
}

sub rad2deg_dir {
my ($rad) = @_;
$rad = ($rad < PI) ? (-$rad + PI/2) : ($rad + PI/2);
$rad += PI if $rad < 0;
return rad2deg($rad);
}

sub rotate_points {
my ($radians, $center, @points) = @_;
$center //= [0,0];
Expand Down
277 changes: 0 additions & 277 deletions lib/Slic3r/Layer/BridgeDetector.pm

This file was deleted.

13 changes: 7 additions & 6 deletions lib/Slic3r/Layer/Region.pm
Expand Up @@ -486,16 +486,17 @@ sub process_external_surfaces {
# of very thin (but still working) anchors, the grown expolygon would go beyond them
my $angle;
if ($lower_layer) {
my $bridge_detector = Slic3r::Layer::BridgeDetector->new(
expolygon => $surface->expolygon,
lower_slices => $lower_layer->slices,
extrusion_width => $self->flow(FLOW_ROLE_INFILL, $self->height, 1)->scaled_width,
my $bridge_detector = Slic3r::BridgeDetector->new(
$surface->expolygon,
$lower_layer->slices,
$self->flow(FLOW_ROLE_INFILL, $self->height, 1)->scaled_width,
);
Slic3r::debugf "Processing bridge at layer %d:\n", $self->id;
$angle = $bridge_detector->detect_angle;
$bridge_detector->detect_angle;
$angle = $bridge_detector->angle;

if (defined $angle && $self->object->config->support_material) {
$self->bridged->append($_) for @{ $bridge_detector->coverage($angle) };
$self->bridged->append($_) for @{ $bridge_detector->coverage_with_angle($angle) };
$self->unsupported_bridge_edges->append($_) for @{ $bridge_detector->unsupported_edges };
}
}
Expand Down
13 changes: 7 additions & 6 deletions t/bridges.t
Expand Up @@ -84,17 +84,18 @@ use Slic3r::Test;
sub check_angle {
my ($lower, $bridge, $expected, $tolerance, $expected_coverage) = @_;

if (ref($lower) eq 'ARRAY') {
$lower = Slic3r::ExPolygon::Collection->new(@$lower);
}

$expected_coverage //= -1;
$expected_coverage = $bridge->area if $expected_coverage == -1;

my $bd = Slic3r::Layer::BridgeDetector->new(
expolygon => $bridge,
lower_slices => $lower,
extrusion_width => scale 0.5,
);
my $bd = Slic3r::BridgeDetector->new($bridge, $lower, scale 0.5);

$tolerance //= rad2deg($bd->resolution) + epsilon;
my $result = $bd->detect_angle;
$bd->detect_angle;
my $result = $bd->angle;
my $coverage = $bd->coverage;
is sum(map $_->area, @$coverage), $expected_coverage, 'correct coverage area';

Expand Down

0 comments on commit 379cde3

Please sign in to comment.