Implemented TriangleMesh->clone

This commit is contained in:
Alessandro Ranellucci 2013-09-10 00:09:56 +02:00
parent 9b12d6037a
commit 311eda7d42
4 changed files with 25 additions and 2 deletions

View File

@ -11,8 +11,23 @@
namespace Slic3r {
TriangleMesh::TriangleMesh(const TriangleMesh &other)
: stl(other.stl), repaired(other.repaired)
{
this->stl.heads = NULL;
this->stl.tail = NULL;
if (other.stl.facet_start != NULL)
std::copy(other.stl.facet_start, other.stl.facet_start + other.stl.stats.number_of_facets, this->stl.facet_start);
if (other.stl.neighbors_start != NULL)
std::copy(other.stl.neighbors_start, other.stl.neighbors_start + other.stl.stats.number_of_facets, this->stl.neighbors_start);
if (other.stl.v_indices != NULL)
std::copy(other.stl.v_indices, other.stl.v_indices + other.stl.stats.number_of_facets, this->stl.v_indices);
if (other.stl.v_shared != NULL)
std::copy(other.stl.v_shared, other.stl.v_shared + other.stl.stats.shared_vertices, this->stl.v_shared);
}
TriangleMesh::~TriangleMesh() {
stl_close(&stl);
stl_close(&this->stl);
}
SV*

View File

@ -16,6 +16,7 @@ class TriangleMesh
{
public:
TriangleMesh() : repaired(false) {};
TriangleMesh(const TriangleMesh &other);
~TriangleMesh();
SV* to_SV();
void ReadSTLFile(char* input_file);

View File

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 48;
use Test::More tests => 49;
is Slic3r::TriangleMesh::XS::hello_world(), 'Hello world!',
'hello world';
@ -32,6 +32,11 @@ my $cube = {
$m->scale(2);
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
{
my $m2 = $m->clone;
ok abs($m->stats->{volume} - 40*40*40) < 1E-2, 'scale';
}
$m->scale_xyz([2,1,1]);
ok abs($m->stats->{volume} - 2*40*40*40) < 1E-2, 'scale_xyz';

View File

@ -8,6 +8,8 @@
%name{Slic3r::TriangleMesh::XS} class TriangleMesh {
TriangleMesh();
~TriangleMesh();
TriangleMesh* clone()
%code{% const char* CLASS = "Slic3r::TriangleMesh"; RETVAL = new TriangleMesh(*THIS); %};
void ReadSTLFile(char* input_file);
void ReadFromPerl(SV* vertices, SV* facets);
void repair();