Skip to content

Commit

Permalink
Ported TriangleMesh->scale
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Aug 4, 2013
1 parent a0bd152 commit 515d570
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions xs/src/TriangleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,9 @@ TriangleMesh::WriteOBJFile(char* output_file) {
stl_write_obj(&stl, output_file);
}

void TriangleMesh::scale(float factor)
{
stl_scale(&(this->stl), factor);
}

}
1 change: 1 addition & 0 deletions xs/src/TriangleMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TriangleMesh
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
stl_file stl;
};

Expand Down
6 changes: 6 additions & 0 deletions xs/src/admesh/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,19 @@ stl_scale(stl_file *stl, float factor)
int i;
int j;

// scale extents
stl->stats.min.x *= factor;
stl->stats.min.y *= factor;
stl->stats.min.z *= factor;
stl->stats.max.x *= factor;
stl->stats.max.y *= factor;
stl->stats.max.z *= factor;

// scale volume
if (stl->stats.volume > 0.0) {
stl->stats.volume *= (factor * factor * factor);
}

for(i = 0; i < stl->stats.number_of_facets; i++)
{
for(j = 0; j < 3; j++)
Expand Down
13 changes: 9 additions & 4 deletions xs/t/01_trianglemesh.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use strict;
use warnings;

use Slic3r::XS;
use Test::More tests => 5;
use Test::More tests => 6;

is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
Expand All @@ -23,9 +23,14 @@ my $cube = {
is_deeply $vertices, $cube->{vertices}, 'vertices arrayref roundtrip';
is_deeply $facets, $cube->{facets}, 'facets arrayref roundtrip';

my $stats = $m->stats;
is $stats->{number_of_facets}, scalar(@{ $cube->{facets} }), 'stats.number_of_facets';
ok abs($stats->{volume} - 20*20*20) < 1E-3, 'stats.volume';
{
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';
}

__END__
1 change: 1 addition & 0 deletions xs/xsp/TriangleMesh.xsp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
void ReadFromPerl(SV* vertices, SV* facets);
void Repair();
void WriteOBJFile(char* output_file);
void scale(float factor);
%{

SV*
Expand Down

0 comments on commit 515d570

Please sign in to comment.