From 00b836b3dae9daee95a629fb7ceb203f2672fdb8 Mon Sep 17 00:00:00 2001 From: Michael Kirsch Date: Tue, 16 Jul 2019 20:01:50 +0200 Subject: [PATCH] reinstate old testing plus transformation test --- xs/t/01_trianglemesh.t | 43 ++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/xs/t/01_trianglemesh.t b/xs/t/01_trianglemesh.t index f87c12ac9c..4b16dbba09 100644 --- a/xs/t/01_trianglemesh.t +++ b/xs/t/01_trianglemesh.t @@ -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); @@ -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' + } { @@ -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; @@ -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}); @@ -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);