New Slic3r::Point::XS class
This commit is contained in:
parent
cca25c9950
commit
c50ecfb7f8
@ -7,5 +7,8 @@ our $VERSION = '0.01';
|
||||
use XSLoader;
|
||||
XSLoader::load(__PACKAGE__, $VERSION);
|
||||
|
||||
package Slic3r::Point::XS;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->_toPerl };
|
||||
|
||||
1;
|
||||
|
14
xs/src/Point.cpp
Normal file
14
xs/src/Point.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
#include "myinit.h"
|
||||
#include "Point.hpp"
|
||||
|
||||
Point::Point(unsigned long x, unsigned long y) {}
|
||||
Point::~Point() {}
|
||||
|
||||
|
||||
SV*
|
||||
Point::_toPerl() {
|
||||
AV* av = newAV();
|
||||
av_fill(av, 1);
|
||||
av_store_point_xy(av, x, y);
|
||||
return (SV*)newRV_noinc((SV*)av);
|
||||
}
|
21
xs/src/Point.hpp
Normal file
21
xs/src/Point.hpp
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef slic3r_Point_hpp_
|
||||
#define slic3r_Point_hpp_
|
||||
|
||||
extern "C" {
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "ppport.h"
|
||||
}
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
unsigned long x;
|
||||
unsigned long y;
|
||||
Point(unsigned long _x, unsigned long _y): x(_x), y(_y) {};
|
||||
~Point();
|
||||
SV* _toPerl();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,3 +1,6 @@
|
||||
#ifndef slic3r_TriangleMesh_hpp_
|
||||
#define slic3r_TriangleMesh_hpp_
|
||||
|
||||
#include <admesh/stl.h>
|
||||
|
||||
extern "C" {
|
||||
@ -21,4 +24,4 @@ class TriangleMesh
|
||||
stl_file stl;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
24
xs/src/ZTable.hpp
Normal file
24
xs/src/ZTable.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef slic3r_ZTable_hpp_
|
||||
#define slic3r_ZTable_hpp_
|
||||
|
||||
extern "C" {
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "ppport.h"
|
||||
}
|
||||
|
||||
class ZTable
|
||||
{
|
||||
public:
|
||||
ZTable(std::vector<unsigned int>* z_array);
|
||||
std::vector<unsigned int> get_range(unsigned int min_z, unsigned int max_z);
|
||||
std::vector<unsigned int> z;
|
||||
};
|
||||
|
||||
ZTable::ZTable(std::vector<unsigned int>* ztable) :
|
||||
z(*ztable)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
@ -3,21 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
////////////////
|
||||
class ZTable
|
||||
{
|
||||
public:
|
||||
ZTable(std::vector<unsigned int>* z_array);
|
||||
std::vector<unsigned int> get_range(unsigned int min_z, unsigned int max_z);
|
||||
std::vector<unsigned int> z;
|
||||
};
|
||||
|
||||
ZTable::ZTable(std::vector<unsigned int>* ztable) :
|
||||
z(*ztable)
|
||||
{
|
||||
}
|
||||
////////////////
|
||||
|
||||
#include "TriangleMesh.hpp"
|
||||
#define av_store_point_xy(AV, X, Y) \
|
||||
av_store(AV, 0, newSViv(X)); \
|
||||
av_store(AV, 1, newSViv(Y))
|
||||
|
||||
#endif
|
||||
|
12
xs/t/03_point.t
Normal file
12
xs/t/03_point.t
Normal file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 1;
|
||||
|
||||
my $point = Slic3r::Point::XS->new(10, 15);
|
||||
is_deeply [ @$point ], [10, 15], 'point roundtrip';
|
||||
|
||||
__END__
|
@ -2,6 +2,7 @@
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "ZTable.hpp"
|
||||
#include <vector>
|
||||
%}
|
||||
|
||||
|
25
xs/xsp/Point.xsp
Normal file
25
xs/xsp/Point.xsp
Normal file
@ -0,0 +1,25 @@
|
||||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "Point.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Point::XS} class Point {
|
||||
Point(unsigned long _x, unsigned long _y);
|
||||
~Point();
|
||||
SV* _toPerl();
|
||||
};
|
||||
|
||||
%package{Slic3r::Point::XS};
|
||||
|
||||
%{
|
||||
PROTOTYPES: DISABLE
|
||||
|
||||
std::string
|
||||
hello_world()
|
||||
CODE:
|
||||
RETVAL = "Hello world!";
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
%}
|
@ -2,6 +2,7 @@
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "TriangleMesh.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::TriangleMesh::XS} class TriangleMesh {
|
||||
|
@ -1,3 +1,4 @@
|
||||
ZTable* O_OBJECT
|
||||
TriangleMesh* O_OBJECT
|
||||
Point* O_OBJECT
|
||||
std::vector< unsigned int >* T_STD_VECTOR_UINT_PTR
|
||||
|
Loading…
Reference in New Issue
Block a user