New Slic3r::Surface::Collection class
This commit is contained in:
parent
0099218f61
commit
5885be881c
8 changed files with 115 additions and 16 deletions
|
@ -60,4 +60,8 @@ sub clone {
|
|||
);
|
||||
}
|
||||
|
||||
package Slic3r::Surface::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
|
||||
1;
|
||||
|
|
26
xs/src/SurfaceCollection.hpp
Normal file
26
xs/src/SurfaceCollection.hpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef slic3r_SurfaceCollection_hpp_
|
||||
#define slic3r_SurfaceCollection_hpp_
|
||||
|
||||
extern "C" {
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "ppport.h"
|
||||
}
|
||||
|
||||
#include "Surface.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef std::vector<Surface> Surfaces;
|
||||
|
||||
class SurfaceCollection
|
||||
{
|
||||
public:
|
||||
Surfaces surfaces;
|
||||
SV* arrayref();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 6;
|
||||
use Test::More tests => 10;
|
||||
|
||||
my $square = [ # ccw
|
||||
[100, 100],
|
||||
|
@ -40,4 +40,15 @@ is $surface->bridge_angle, 30, 'bridge_angle';
|
|||
$surface->extra_perimeters(2);
|
||||
is $surface->extra_perimeters, 2, 'extra_perimeters';
|
||||
|
||||
{
|
||||
my $collection = Slic3r::Surface::Collection->new($surface, $surface->clone);
|
||||
is scalar(@$collection), 2, 'collection has the right number of items';
|
||||
is_deeply $collection->[0]->expolygon->arrayref, [$square, $hole_in_square],
|
||||
'collection returns a correct surface expolygon';
|
||||
$collection->clear;
|
||||
is scalar(@$collection), 0, 'clear collection';
|
||||
$collection->append($surface);
|
||||
is scalar(@$collection), 1, 'append to collection';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
49
xs/xsp/SurfaceCollection.xsp
Normal file
49
xs/xsp/SurfaceCollection.xsp
Normal file
|
@ -0,0 +1,49 @@
|
|||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "SurfaceCollection.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Surface::Collection} class SurfaceCollection {
|
||||
~SurfaceCollection();
|
||||
void clear()
|
||||
%code{% THIS->surfaces.clear(); %};
|
||||
%{
|
||||
|
||||
SurfaceCollection*
|
||||
SurfaceCollection::new(...)
|
||||
CODE:
|
||||
RETVAL = new SurfaceCollection ();
|
||||
// ST(0) is class name, others are surfaces
|
||||
RETVAL->surfaces.resize(items-1);
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) ));
|
||||
}
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
SV*
|
||||
SurfaceCollection::arrayref()
|
||||
CODE:
|
||||
AV* av = newAV();
|
||||
av_fill(av, THIS->surfaces.size()-1);
|
||||
int i = 0;
|
||||
for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) {
|
||||
SV* sv = newSV(0);
|
||||
sv_setref_pv( sv, "Slic3r::Surface", new Surface(*it) );
|
||||
av_store(av, i++, sv);
|
||||
}
|
||||
RETVAL = newRV_noinc((SV*)av);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
SurfaceCollection::append(...)
|
||||
CODE:
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
THIS->surfaces.push_back(*(Surface *)SvIV((SV*)SvRV( ST(i) )));
|
||||
}
|
||||
|
||||
%}
|
||||
};
|
|
@ -5,3 +5,4 @@ ExPolygon* O_OBJECT
|
|||
ExPolygonCollection* O_OBJECT
|
||||
SurfaceType T_UV
|
||||
Surface* O_OBJECT
|
||||
SurfaceCollection* O_OBJECT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue