XS interface completed, including new Line class

This commit is contained in:
Alessandro Ranellucci 2013-07-15 22:57:22 +02:00
parent 9af2a1c007
commit ab6b3d41a7
33 changed files with 435 additions and 257 deletions

View file

@ -5,13 +5,13 @@
#include "ExPolygon.hpp"
%}
%name{Slic3r::ExPolygon::XS} class ExPolygon {
%name{Slic3r::ExPolygon} class ExPolygon {
ExPolygon* clone()
%code{% const char* CLASS = "Slic3r::ExPolygon::XS"; RETVAL = new ExPolygon(*THIS); RETVAL->in_collection = false; %};
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(*THIS); RETVAL->in_collection = false; %};
SV* arrayref()
%code{% RETVAL = THIS->to_SV(true, false); %};
SV* arrayref_pp()
%code{% RETVAL = THIS->to_SV(true, true); %};
%code{% RETVAL = THIS->to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
void scale(double factor);
void translate(double x, double y);
%{
@ -42,29 +42,9 @@ ExPolygon::rotate(angle, center_sv)
double angle;
SV* center_sv;
CODE:
Point* center;
if (sv_isobject(center_sv) && (SvTYPE(SvRV(center_sv)) == SVt_PVMG)) {
center = (Point*)SvIV((SV*)SvRV( center_sv ));
THIS->rotate(angle, center);
} else {
center = new Point;
perl2point(center_sv, *center);
THIS->rotate(angle, center);
delete center;
}
Point center;
center.from_SV_check(center_sv);
THIS->rotate(angle, &center);
%}
};
%package{Slic3r::ExPolygon::XS};
%{
PROTOTYPES: DISABLE
std::string
hello_world()
CODE:
RETVAL = "Hello world!";
OUTPUT:
RETVAL
%}

View file

@ -23,7 +23,8 @@ ExPolygonCollection::new(...)
// ST(0) is class name, others are expolygons
RETVAL->expolygons.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
perl2expolygon_check(ST(i), RETVAL->expolygons[i-1]);
// Note: a COPY of the input is stored
RETVAL->expolygons[i-1].from_SV_check(ST(i));
RETVAL->expolygons[i-1].in_collection = true;
}
OUTPUT:
@ -36,20 +37,22 @@ ExPolygonCollection::arrayref()
av_fill(av, THIS->expolygons.size()-1);
int i = 0;
for (ExPolygons::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
av_store(av, i++, (*it).to_SV(false, false));
SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::ExPolygon", &*it );
av_store(av, i++, sv);
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
RETVAL
SV*
ExPolygonCollection::arrayref_pp()
ExPolygonCollection::pp()
CODE:
AV* av = newAV();
av_fill(av, THIS->expolygons.size()-1);
int i = 0;
for (ExPolygons::iterator it = THIS->expolygons.begin(); it != THIS->expolygons.end(); ++it) {
av_store(av, i++, (*it).to_SV(true, true));
av_store(av, i++, (*it).to_SV_pureperl());
}
RETVAL = newRV_noinc((SV*)av);
OUTPUT:
@ -59,8 +62,10 @@ void
ExPolygonCollection::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
THIS->expolygons.push_back(*(ExPolygon *)SvIV((SV*)SvRV( ST(i) )));
THIS->expolygons.back().in_collection = true;
ExPolygon expolygon;
expolygon.from_SV_check( ST(i) );
expolygon.in_collection = true;
THIS->expolygons.push_back(expolygon);
}
%}

View file

@ -8,11 +8,11 @@
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
~ExtrusionLoop();
SV* arrayref()
%code{% RETVAL = THIS->polygon.to_SV(true, false); %};
SV* arrayref_pp()
%code{% RETVAL = THIS->polygon.to_SV(true, true); %};
%code{% RETVAL = THIS->polygon.to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->polygon.to_SV_pureperl(); %};
Polygon* as_polygon()
%code{% const char* CLASS = "Slic3r::Polygon::XS"; RETVAL = new Polygon(THIS->polygon); %};
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(THIS->polygon); %};
void set_polygon(SV* polygon_sv)
%code{% THIS->polygon.from_SV_check(polygon_sv); %};
%{

View file

@ -8,11 +8,11 @@
%name{Slic3r::ExtrusionPath} class ExtrusionPath {
~ExtrusionPath();
SV* arrayref()
%code{% RETVAL = THIS->polyline.to_SV(true, false); %};
SV* arrayref_pp()
%code{% RETVAL = THIS->polyline.to_SV(true, true); %};
%code{% RETVAL = THIS->polyline.to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->polyline.to_SV_pureperl(); %};
Polyline* as_polyline()
%code{% const char* CLASS = "Slic3r::Polyline::XS"; RETVAL = new Polyline(THIS->polyline); %};
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = new Polyline(THIS->polyline); %};
void set_polyline(SV* polyline_sv)
%code{% THIS->polyline.from_SV_check(polyline_sv); %};
void pop_back()
@ -71,7 +71,7 @@ ExtrusionPath::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
Point p;
perl2point_check(ST(i), p);
p.from_SV_check(ST(i));
THIS->polyline.points.push_back(p);
}

30
xs/xsp/Line.xsp Normal file
View file

@ -0,0 +1,30 @@
%module{Slic3r::XS};
%{
#include <myinit.h>
#include "Line.hpp"
%}
%name{Slic3r::Line} class Line {
~Line();
Line* clone()
%code{% const char* CLASS = "Slic3r::Line"; RETVAL = new Line(*THIS); %};
SV* arrayref()
%code{% RETVAL = THIS->to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
void reverse();
%{
Line*
Line::new(...)
CODE:
RETVAL = new Line ();
// ST(0) is class name, ST(1) and ST(2) are endpoints
RETVAL->a.from_SV_check( ST(1) );
RETVAL->b.from_SV_check( ST(2) );
OUTPUT:
RETVAL
%}
};

View file

@ -13,7 +13,7 @@
void scale(double factor);
void translate(double x, double y);
SV* arrayref()
%code{% RETVAL = THIS->to_SV(true); %};
%code{% RETVAL = THIS->to_SV_pureperl(); %};
unsigned long x()
%code{% RETVAL = THIS->x; %};
unsigned long y()
@ -27,7 +27,7 @@ Point::rotate(angle, center_sv)
SV* center_sv;
CODE:
Point center;
perl2point_check(center_sv, center);
center.from_SV_check(center_sv);
THIS->rotate(angle, &center);
bool
@ -35,7 +35,7 @@ Point::coincides_with(point_sv)
SV* point_sv;
CODE:
Point point;
perl2point_check(point_sv, point);
point.from_SV_check(point_sv);
RETVAL = THIS->coincides_with(&point);
OUTPUT:
RETVAL

View file

@ -5,14 +5,16 @@
#include "Polygon.hpp"
%}
%name{Slic3r::Polygon::XS} class Polygon {
%name{Slic3r::Polygon} class Polygon {
~Polygon();
Polygon* clone()
%code{% const char* CLASS = "Slic3r::Polygon::XS"; RETVAL = new Polygon(*THIS); %};
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(*THIS); %};
SV* arrayref()
%code{% RETVAL = THIS->to_SV(true, false); %};
SV* arrayref_pp()
%code{% RETVAL = THIS->to_SV(true, true); %};
%code{% RETVAL = THIS->to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
void scale(double factor);
void translate(double x, double y);
%{
Polygon*
@ -22,7 +24,7 @@ Polygon::new(...)
// ST(0) is class name, ST(1) is first point
RETVAL->points.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
perl2point(ST(i), RETVAL->points[i-1]);
RETVAL->points[i-1].from_SV_check( ST(i) );
}
OUTPUT:
RETVAL

View file

@ -5,14 +5,14 @@
#include "Polyline.hpp"
%}
%name{Slic3r::Polyline::XS} class Polyline {
%name{Slic3r::Polyline} class Polyline {
~Polyline();
Polyline* clone()
%code{% const char* CLASS = "Slic3r::Polyline::XS"; RETVAL = new Polyline(*THIS); %};
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = new Polyline(*THIS); %};
SV* arrayref()
%code{% RETVAL = THIS->to_SV(true, false); %};
SV* arrayref_pp()
%code{% RETVAL = THIS->to_SV(true, true); %};
%code{% RETVAL = THIS->to_SV(); %};
SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %};
void pop_back()
%code{% THIS->points.pop_back(); %};
void reverse();
@ -25,7 +25,7 @@ Polyline::new(...)
// ST(0) is class name, ST(1) is first point
RETVAL->points.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
perl2point(ST(i), RETVAL->points[i-1]);
RETVAL->points[i-1].from_SV_check( ST(i) );
}
OUTPUT:
RETVAL
@ -35,11 +35,7 @@ Polyline::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
Point p;
if (sv_isobject(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PVMG)) {
p = *(Point*)SvIV((SV*)SvRV( ST(i) ));
} else {
perl2point(ST(i), p);
}
p.from_SV_check( ST(1) );
THIS->points.push_back(p);
}

View file

@ -7,7 +7,7 @@
%name{Slic3r::Surface} class Surface {
ExPolygon* expolygon()
%code{% const char* CLASS = "Slic3r::ExPolygon::XS"; RETVAL = new ExPolygon(THIS->expolygon); %};
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(THIS->expolygon); %};
double thickness()
%code{% RETVAL = THIS->thickness; %};
unsigned short thickness_layers()

View file

@ -18,6 +18,7 @@ SurfaceCollection::new(...)
// ST(0) is class name, others are surfaces
RETVAL->surfaces.resize(items-1);
for (unsigned int i = 1; i < items; i++) {
// Note: a COPY of the input is stored
RETVAL->surfaces[i-1] = *(Surface *)SvIV((SV*)SvRV( ST(i) ));
RETVAL->surfaces[i-1].in_collection = true;
}

View file

@ -1,6 +1,7 @@
ZTable* O_OBJECT
TriangleMesh* O_OBJECT
Point* O_OBJECT
Line* O_OBJECT
Polyline* O_OBJECT
Polygon* O_OBJECT
ExPolygon* O_OBJECT