2013-06-22 15:16:45 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2013-11-24 13:28:17 +00:00
|
|
|
use Test::More tests => 52;
|
2013-06-22 15:16:45 +00:00
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
is Slic3r::TriangleMesh::hello_world(), 'Hello world!',
|
2013-06-22 15:16:45 +00:00
|
|
|
'hello world';
|
|
|
|
|
2013-07-03 09:38:01 +00:00
|
|
|
my $cube = {
|
|
|
|
vertices => [ [20,20,0], [20,0,0], [0,0,0], [0,20,0], [20,20,20], [0,20,20], [0,0,20], [20,0,20] ],
|
|
|
|
facets => [ [0,1,2], [0,2,3], [4,5,6], [4,6,7], [0,4,7], [0,7,1], [1,7,6], [1,6,2], [2,6,5], [2,5,3], [4,0,3], [4,3,5] ],
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
2013-09-09 22:40:46 +00:00
|
|
|
my $m = Slic3r::TriangleMesh->new;
|
2013-07-03 09:38:01 +00:00
|
|
|
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
2013-09-09 21:18:33 +00:00
|
|
|
$m->repair;
|
2013-08-04 19:23:27 +00:00
|
|
|
my ($vertices, $facets) = ($m->vertices, $m->facets);
|
|
|
|
|
2013-07-03 09:38:01 +00:00
|
|
|
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
|
|
|
|
is_deeply $facets, $cube->{facets}, 'facets arrayref roundtrip';
|
2013-09-11 18:15:42 +00:00
|
|
|
is scalar(@{$m->normals}), scalar(@$facets), 'normals returns the right number of items';
|
2013-07-13 16:51:49 +00:00
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
{
|
|
|
|
my $m2 = $m->clone;
|
|
|
|
is_deeply $m2->vertices, $cube->{vertices}, 'cloned vertices arrayref roundtrip';
|
|
|
|
is_deeply $m2->facets, $cube->{facets}, 'cloned facets arrayref roundtrip';
|
|
|
|
$m2->scale(3); # check that it does not affect $m
|
|
|
|
}
|
|
|
|
|
2013-08-04 19:34:26 +00:00
|
|
|
{
|
|
|
|
my $stats = $m->stats;
|
|
|
|
is $stats->{number_of_facets}, scalar(@{ $cube->{facets} }), 'stats.number_of_facets';
|
|
|
|
ok abs($stats->{volume} - 20*20*20) < 1E-2, 'stats.volume';
|
|
|
|
}
|
|
|
|
|
|
|
|
$m->scale(2);
|
|
|
|
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
|
2013-08-05 08:48:38 +00:00
|
|
|
|
2013-09-09 21:38:49 +00:00
|
|
|
$m->scale_xyz([2,1,1]);
|
|
|
|
ok abs($m->stats->{volume} - 2*40*40*40) < 1E-2, 'scale_xyz';
|
|
|
|
|
2013-08-05 08:48:38 +00:00
|
|
|
$m->translate(5,10,0);
|
2013-09-09 21:38:49 +00:00
|
|
|
is_deeply $m->vertices->[0], [85,50,0], 'translate';
|
2013-08-05 17:22:33 +00:00
|
|
|
|
|
|
|
$m->align_to_origin;
|
|
|
|
is_deeply $m->vertices->[2], [0,0,0], 'align_to_origin';
|
2013-08-05 17:39:10 +00:00
|
|
|
|
2013-09-09 21:38:49 +00:00
|
|
|
is_deeply $m->size, [80,40,40], 'size';
|
2013-08-05 17:52:37 +00:00
|
|
|
|
2013-09-09 21:38:49 +00:00
|
|
|
$m->scale_xyz([0.5,1,1]);
|
2013-08-05 17:52:37 +00:00
|
|
|
$m->rotate(45, Slic3r::Point->new(20,20));
|
|
|
|
ok abs($m->size->[0] - sqrt(2)*40) < 1E-4, 'rotate';
|
2013-09-09 20:27:58 +00:00
|
|
|
|
2013-09-09 21:09:56 +00:00
|
|
|
{
|
|
|
|
my $meshes = $m->split;
|
|
|
|
is scalar(@$meshes), 1, 'split';
|
2013-09-09 22:40:46 +00:00
|
|
|
isa_ok $meshes->[0], 'Slic3r::TriangleMesh', 'split';
|
2013-11-24 13:28:17 +00:00
|
|
|
is_deeply $m->bb3, $meshes->[0]->bb3, 'split populates stats';
|
2013-09-09 21:09:56 +00:00
|
|
|
}
|
2013-09-09 20:45:22 +00:00
|
|
|
|
2013-09-09 22:40:46 +00:00
|
|
|
my $m2 = Slic3r::TriangleMesh->new;
|
2013-09-09 20:45:22 +00:00
|
|
|
$m2->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
2013-09-09 21:18:33 +00:00
|
|
|
$m2->repair;
|
2013-09-09 20:45:22 +00:00
|
|
|
$m->merge($m2);
|
2013-09-09 21:18:33 +00:00
|
|
|
$m->repair;
|
2013-09-09 20:45:22 +00:00
|
|
|
is $m->stats->{number_of_facets}, 2 * $m2->stats->{number_of_facets}, 'merge';
|
2013-09-09 21:09:56 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
my $meshes = $m->split;
|
|
|
|
is scalar(@$meshes), 2, 'split';
|
|
|
|
}
|
2013-07-03 09:38:01 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 10:18:52 +00:00
|
|
|
{
|
2013-09-09 22:40:46 +00:00
|
|
|
my $m = Slic3r::TriangleMesh->new;
|
2013-09-07 12:06:09 +00:00
|
|
|
$m->ReadFromPerl($cube->{vertices}, $cube->{facets});
|
2013-09-09 21:18:33 +00:00
|
|
|
$m->repair;
|
2013-09-07 22:44:01 +00:00
|
|
|
my @z = (2,4,8,6,8,10,12,14,16,18,20);
|
|
|
|
my $result = $m->slice(\@z);
|
|
|
|
for my $i (0..$#z) {
|
|
|
|
is scalar(@{$result->[$i]}), 1, 'number of returned polygons per layer';
|
|
|
|
is $result->[$i][0]->area, 20*20, 'size of returned polygon';
|
|
|
|
ok $result->[$i][0]->is_counter_clockwise, 'orientation of returned polygon';
|
|
|
|
}
|
2013-09-07 12:06:09 +00:00
|
|
|
}
|
|
|
|
|
2013-06-22 15:16:45 +00:00
|
|
|
__END__
|