Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/xs
diff options
context:
space:
mode:
authorAlessandro Ranellucci <aar@cpan.org>2013-07-06 17:26:32 +0400
committerAlessandro Ranellucci <aar@cpan.org>2013-07-06 17:26:32 +0400
commitc50ecfb7f8a42ab06a22e97cbb3cc8fe62ec5000 (patch)
treed8cbf10fd5397319066ec90cc052c7711b05a35b /xs
parentcca25c99501091c63578652c26cd77f89045fbf9 (diff)
New Slic3r::Point::XS class
Diffstat (limited to 'xs')
-rw-r--r--xs/lib/Slic3r/XS.pm3
-rw-r--r--xs/src/Point.cpp14
-rw-r--r--xs/src/Point.hpp21
-rw-r--r--xs/src/TriangleMesh.hpp5
-rw-r--r--xs/src/ZTable.hpp24
-rw-r--r--xs/src/myinit.h19
-rw-r--r--xs/t/03_point.t12
-rw-r--r--xs/xsp/Object.xsp1
-rw-r--r--xs/xsp/Point.xsp25
-rw-r--r--xs/xsp/TriangleMesh.xsp1
-rw-r--r--xs/xsp/my.map1
11 files changed, 109 insertions, 17 deletions
diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm
index 0bdf5f31d..1b245329a 100644
--- a/xs/lib/Slic3r/XS.pm
+++ b/xs/lib/Slic3r/XS.pm
@@ -7,5 +7,8 @@ our $VERSION = '0.01';
use XSLoader;
XSLoader::load(__PACKAGE__, $VERSION);
+package Slic3r::Point::XS;
+use overload
+ '@{}' => sub { $_[0]->_toPerl };
1;
diff --git a/xs/src/Point.cpp b/xs/src/Point.cpp
new file mode 100644
index 000000000..a4c905eae
--- /dev/null
+++ b/xs/src/Point.cpp
@@ -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);
+}
diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp
new file mode 100644
index 000000000..3b7a5e5dd
--- /dev/null
+++ b/xs/src/Point.hpp
@@ -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
diff --git a/xs/src/TriangleMesh.hpp b/xs/src/TriangleMesh.hpp
index 78e62cf9a..56380ebf8 100644
--- a/xs/src/TriangleMesh.hpp
+++ b/xs/src/TriangleMesh.hpp
@@ -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
diff --git a/xs/src/ZTable.hpp b/xs/src/ZTable.hpp
new file mode 100644
index 000000000..045722eec
--- /dev/null
+++ b/xs/src/ZTable.hpp
@@ -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
diff --git a/xs/src/myinit.h b/xs/src/myinit.h
index 46e564d2e..4f534519c 100644
--- a/xs/src/myinit.h
+++ b/xs/src/myinit.h
@@ -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
diff --git a/xs/t/03_point.t b/xs/t/03_point.t
new file mode 100644
index 000000000..0a876af71
--- /dev/null
+++ b/xs/t/03_point.t
@@ -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__
diff --git a/xs/xsp/Object.xsp b/xs/xsp/Object.xsp
index d6071977b..2f8a0601e 100644
--- a/xs/xsp/Object.xsp
+++ b/xs/xsp/Object.xsp
@@ -2,6 +2,7 @@
%{
#include <myinit.h>
+#include "ZTable.hpp"
#include <vector>
%}
diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp
new file mode 100644
index 000000000..db810068b
--- /dev/null
+++ b/xs/xsp/Point.xsp
@@ -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
+%}
diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp
index be0d5b25e..6952dfdbd 100644
--- a/xs/xsp/TriangleMesh.xsp
+++ b/xs/xsp/TriangleMesh.xsp
@@ -2,6 +2,7 @@
%{
#include <myinit.h>
+#include "TriangleMesh.hpp"
%}
%name{Slic3r::TriangleMesh::XS} class TriangleMesh {
diff --git a/xs/xsp/my.map b/xs/xsp/my.map
index 656389f00..46a311676 100644
--- a/xs/xsp/my.map
+++ b/xs/xsp/my.map
@@ -1,3 +1,4 @@
ZTable* O_OBJECT
TriangleMesh* O_OBJECT
+Point* O_OBJECT
std::vector< unsigned int >* T_STD_VECTOR_UINT_PTR