mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-14 23:05:53 +08:00
Update and restore t/loops.t
This commit is contained in:
parent
5c21237e51
commit
ef8695da1d
60
t/loops.t
60
t/loops.t
@ -2,7 +2,6 @@ use Test::More;
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
plan skip_all => 'temporarily disabled';
|
|
||||||
plan tests => 4;
|
plan tests => 4;
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
@ -12,46 +11,41 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
use Slic3r;
|
use Slic3r;
|
||||||
|
use Slic3r::Geometry qw(Z epsilon scale);
|
||||||
use Slic3r::Test;
|
use Slic3r::Test;
|
||||||
|
|
||||||
{
|
{
|
||||||
# We only need to slice at one height, so we'll build a non-manifold mesh
|
# We want to check what happens when three concentric loops happen
|
||||||
# that still produces complete loops at that height. Triangular walls are
|
|
||||||
# enough for this purpose.
|
|
||||||
# Basically we want to check what happens when three concentric loops happen
|
|
||||||
# to be at the same height, the two external ones being ccw and the other being
|
# to be at the same height, the two external ones being ccw and the other being
|
||||||
# a hole, thus cw.
|
# a hole, thus cw. So we create three cubes, centered around origin, the internal
|
||||||
my (@vertices, @facets) = ();
|
# one having reversed normals.
|
||||||
Slic3r::Test::add_facet($_, \@vertices, \@facets) for
|
my $mesh1 = Slic3r::Test::mesh('20mm_cube');
|
||||||
# external surface below the slicing Z
|
|
||||||
[ [0,0,0], [20,0,10], [0,0,10] ],
|
|
||||||
[ [20,0,0], [20,20,10], [20,0,10] ],
|
|
||||||
[ [20,20,0], [0,20,10], [20,20,10] ],
|
|
||||||
[ [0,20,0], [0,0,10], [0,20,10] ],
|
|
||||||
|
|
||||||
# external insetted surface above the slicing Z
|
# center around origin
|
||||||
[ [2,2,10], [18,2,10], [2,2,20] ],
|
my $bb = $mesh1->bounding_box;
|
||||||
[ [18,2,10], [18,18,10], [18,2,20] ],
|
$mesh1->translate(
|
||||||
[ [18,18,10], [2,18,10], [18,18,20] ],
|
-($bb->x_min + $bb->size->x/2),
|
||||||
[ [2,18,10], [2,2,10], [2,18,20] ],
|
-($bb->y_min + $bb->size->y/2), #//
|
||||||
|
-($bb->z_min + $bb->size->z/2),
|
||||||
|
);
|
||||||
|
|
||||||
# insetted hole below the slicing Z
|
my $mesh2 = $mesh1->clone;
|
||||||
[ [15,5,0], [5,5,10], [15,5,10] ],
|
$mesh2->scale(1.2);
|
||||||
[ [15,15,0], [15,5,10], [15,15,10] ],
|
|
||||||
[ [5,15,0], [15,15,10], [5,15,10] ],
|
|
||||||
[ [5,5,0], [5,15,10], [5,5,10] ];
|
|
||||||
|
|
||||||
my $mesh = Slic3r::TriangleMesh->new;
|
my $mesh3 = $mesh2->clone;
|
||||||
$mesh->ReadFromPerl(\@vertices, \@facets);
|
$mesh3->scale(1.2);
|
||||||
$mesh->analyze;
|
|
||||||
my @lines = map $mesh->intersect_facet($_, 10), 0..$#facets;
|
|
||||||
my $loops = Slic3r::TriangleMesh::make_loops(\@lines);
|
|
||||||
is scalar(@$loops), 3, 'correct number of loops detected';
|
|
||||||
is scalar(grep $_->is_counter_clockwise, @$loops), 2, 'correct number of ccw loops detected';
|
|
||||||
|
|
||||||
my @surfaces = Slic3r::Layer::Region::_merge_loops($loops, 0);
|
$mesh1->reverse_normals;
|
||||||
is scalar(@surfaces), 1, 'one surface detected';
|
ok $mesh1->volume < 0, 'reverse_normals';
|
||||||
is scalar(@{$surfaces[0]->expolygon})-1, 1, 'surface has one hole';
|
|
||||||
|
my $all_meshes = Slic3r::TriangleMesh->new;
|
||||||
|
$all_meshes->merge($_) for $mesh1, $mesh2, $mesh3;
|
||||||
|
|
||||||
|
my $loops = $all_meshes->slice_at(Z, 0);
|
||||||
|
is scalar(@$loops), 1, 'one expolygon returned';
|
||||||
|
is scalar(@{$loops->[0]->holes}), 1, 'expolygon has one hole';
|
||||||
|
ok abs(-$loops->[0]->holes->[0]->area - scale($bb->size->x)*scale($bb->size->y)) < epsilon, #))
|
||||||
|
'hole has expected size';
|
||||||
}
|
}
|
||||||
|
|
||||||
__END__
|
__END__
|
||||||
|
@ -511,6 +511,13 @@ TriangleMesh::require_shared_vertices()
|
|||||||
if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl));
|
if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TriangleMesh::reverse_normals()
|
||||||
|
{
|
||||||
|
stl_reverse_all_facets(&this->stl);
|
||||||
|
if (this->stl.stats.volume != -1) this->stl.stats.volume *= -1.0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TriangleMesh::extrude_tin(float offset)
|
TriangleMesh::extrude_tin(float offset)
|
||||||
{
|
{
|
||||||
|
@ -59,6 +59,7 @@ class TriangleMesh
|
|||||||
size_t facets_count() const;
|
size_t facets_count() const;
|
||||||
void extrude_tin(float offset);
|
void extrude_tin(float offset);
|
||||||
void require_shared_vertices();
|
void require_shared_vertices();
|
||||||
|
void reverse_normals();
|
||||||
|
|
||||||
static TriangleMesh make_cube(double x, double y, double z);
|
static TriangleMesh make_cube(double x, double y, double z);
|
||||||
static TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360));
|
static TriangleMesh make_cylinder(double r, double h, double fa=(2*PI/360));
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
%code{% RETVAL = THIS->bounding_box().center(); %};
|
%code{% RETVAL = THIS->bounding_box().center(); %};
|
||||||
int facets_count();
|
int facets_count();
|
||||||
void reset_repair_stats();
|
void reset_repair_stats();
|
||||||
|
void reverse_normals();
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user