Refactoring: moved slicing code to new TriangleMesh class, leaving in STL just what's needed to read that particular input format. Slic3r will now warn if model is not manifold. #16

This commit is contained in:
Alessandro Ranellucci 2011-11-27 11:40:03 +01:00
parent 15d060019f
commit d51a37a0ae
16 changed files with 642 additions and 451 deletions

View file

@ -28,21 +28,24 @@ isnt Slic3r::Geometry::line_intersection($line1, $line2, 1), undef, 'line_inters
#==========================================================
my $polyline = [
[459190000, 5152739000], [147261000, 4612464000], [147261000, 3487535000], [339887000, 3153898000],
[437497000, 3438430000], [454223000, 3522515000], [523621000, 3626378000], [627484000, 3695776000],
[750000000, 3720147000], [872515000, 3695776000], [976378000, 3626378000], [1045776000, 3522515000],
[1070147000, 3400000000], [1045776000, 3277484000], [976378000, 3173621000], [872515000, 3104223000],
[827892000, 3095347000], [698461000, 2947261000], [2540810000, 2947261000], [2852739000, 3487535000],
[2852739000, 4612464000], [2540810000, 5152739000],
];
# this points belongs to $polyline
my $point = [2797980957.103410,3392691792.513960];
is_deeply Slic3r::Geometry::polygon_segment_having_point($polyline, $point),
[ [2540810000, 2947261000], [2852739000, 3487535000] ],
'polygon_segment_having_point';
{
my $polyline = [
[459190000, 5152739000], [147261000, 4612464000], [147261000, 3487535000], [339887000, 3153898000],
[437497000, 3438430000], [454223000, 3522515000], [523621000, 3626378000], [627484000, 3695776000],
[750000000, 3720147000], [872515000, 3695776000], [976378000, 3626378000], [1045776000, 3522515000],
[1070147000, 3400000000], [1045776000, 3277484000], [976378000, 3173621000], [872515000, 3104223000],
[827892000, 3095347000], [698461000, 2947261000], [2540810000, 2947261000], [2852739000, 3487535000],
[2852739000, 4612464000], [2540810000, 5152739000],
];
# this points belongs to $polyline
my $point = [2797980957.103410,3392691792.513960];
local $Slic3r::Geometry::epsilon = 1E-5;
is_deeply Slic3r::Geometry::polygon_segment_having_point($polyline, $point),
[ [2540810000, 2947261000], [2852739000, 3487535000] ],
'polygon_segment_having_point';
}
#==========================================================

21
t/stl.t
View file

@ -10,8 +10,10 @@ BEGIN {
}
use Slic3r;
use Slic3r::Geometry qw(X Y Z);
use XXX;
my $stl = Slic3r::STL->new;
my $mesh = Slic3r::TriangleMesh->new;
my @lines;
my $z = 20;
@ -30,15 +32,20 @@ is_deeply lines(28, 20, 30), [ ], 'lower vertex on la
is_deeply lines(24, 10, 16), [ [ [4, 4], [2, 6] ] ], 'two edges intersect';
is_deeply lines(24, 10, 20), [ [ [4, 4], [1, 9] ] ], 'one vertex on plane and one edge intersects';
my @lower = $stl->intersect_facet(vertices(22, 20, 20), $z);
my @upper = $stl->intersect_facet(vertices(20, 20, 10), $z);
isa_ok $lower[0], 'Slic3r::Line::FacetEdge::Bottom', 'bottom edge on layer';
isa_ok $upper[0], 'Slic3r::Line::FacetEdge::Top', 'upper edge on layer';
my @lower = $mesh->intersect_facet(0, vertices(22, 20, 20), $z);
my @upper = $mesh->intersect_facet(0, vertices(20, 20, 10), $z);
is $lower[0]->facet_edge, 'bottom', 'bottom edge on layer';
is $upper[0]->facet_edge, 'top', 'upper edge on layer';
sub vertices {
[ map [ @{$points[$_]}, $_[$_] ], 0..2 ]
[ map [ @{$points[$_]}, $_[$_] ], X,Y,Z ]
}
sub lines {
[ map [ map [ map sprintf('%.0f', $_), @$_ ], @$_ ], $stl->intersect_facet(vertices(@_), $z) ];
my @lines = $mesh->intersect_facet(0, vertices(@_), $z);
$_->a->[X] = sprintf('%.0f', $_->a->[X]) for @lines;
$_->a->[Y] = sprintf('%.0f', $_->a->[Y]) for @lines;
$_->b->[X] = sprintf('%.0f', $_->b->[X]) for @lines;
$_->b->[Y] = sprintf('%.0f', $_->b->[Y]) for @lines;
return [ map $_->points, @lines ];
}