Skip to content

Commit

Permalink
reinstate old testing plus transformation test
Browse files Browse the repository at this point in the history
  • Loading branch information
Oekn5w authored and lordofhyphens committed Dec 2, 2019
1 parent ad7a169 commit 00b836b
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions xs/t/01_trianglemesh.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ my $cube = {

{
my $m = Slic3r::TriangleMesh->new;
my $trafo = Slic3r::TransformationMatrix->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->repair;
my ($vertices, $facets) = ($m->vertices, $m->facets);
Expand All @@ -31,10 +30,9 @@ my $cube = {
my $m2 = $m->clone;
is_deeply $m2->vertices, $cube->{vertices}, 'cloned vertices arrayref roundtrip';
is_deeply $m2->facets, $cube->{facets}, 'cloned facets arrayref roundtrip';
# check that it does not affect $m
$trafo->set_scale_uni(3);
$m2->transform($trafo);
$m2->scale(3); # check that it does not affect $m
ok $m2->stats->{volume} != $m->stats->{volume}, 'cloned transform not affecting original'

}

{
Expand All @@ -43,9 +41,23 @@ my $cube = {
ok abs($stats->{volume} - 20*20*20) < 1E-2, 'stats.volume';
}

$trafo->set_scale_uni(2);
$m->transform($trafo);
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'transform';
$m->scale(2);
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';

$m->scale_xyz(Slic3r::Pointf3->new(2,1,1));
ok abs($m->stats->{volume} - 2*40*40*40) < 1E-2, 'scale_xyz';

$m->translate(5,10,0);
is_deeply $m->vertices->[0], [85,50,0], 'translate';

$m->align_to_origin;
is_deeply $m->vertices->[2], [0,0,0], 'align_to_origin';

is_deeply $m->size, [80,40,40], 'size';

$m->scale_xyz(Slic3r::Pointf3->new(0.5,1,1));
$m->rotate(45, Slic3r::Point->new(20,20));
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';

{
my $meshes = $m->split;
Expand All @@ -67,6 +79,19 @@ my $cube = {
}
}

{
my $m = Slic3r::TriangleMesh->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
$m->repair;

my $trafo = Slic3r::TransformationMatrix->new;
$trafo->set_scale_uni(2);

$m->transform($trafo);

ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'general purpose transformation';
}

{
my $m = Slic3r::TriangleMesh->new;
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
Expand All @@ -92,9 +117,7 @@ my $cube = {
my $slices = $m->slice([ 5, 10 ]);
is $slices->[0][0]->area, $slices->[1][0]->area, 'slicing a top tangent plane includes its area';
}
my $trafo = Slic3r::TransformationMatrix->new;
$trafo->set_mirror_xyz(Z);
$m->transform($trafo);
$m->mirror_z;
{
# this second test also checks that performing a second slice on a mesh after
# a transformation works properly (shared_vertices is correctly invalidated);
Expand Down

0 comments on commit 00b836b

Please sign in to comment.