Use XS Point everywhere

This commit is contained in:
Alessandro Ranellucci 2013-07-15 20:31:43 +02:00
parent d0701cdcd4
commit 9af2a1c007
37 changed files with 238 additions and 303 deletions

View file

@ -9,6 +9,7 @@ extern "C" {
}
#include "Polygon.hpp"
#include <vector>
namespace Slic3r {
@ -17,7 +18,8 @@ class ExPolygon
public:
Polygon contour;
Polygons holes;
SV* arrayref();
bool in_collection;
SV* to_SV(bool pureperl = false, bool pureperl_children = false);
void scale(double factor);
void translate(double x, double y);
void rotate(double angle, Point* center);
@ -52,6 +54,25 @@ ExPolygon::rotate(double angle, Point* center)
}
}
SV*
ExPolygon::to_SV(bool pureperl, bool pureperl_children)
{
if (pureperl) {
const unsigned int num_holes = this->holes.size();
AV* av = newAV();
av_extend(av, num_holes); // -1 +1
av_store(av, 0, this->contour.to_SV(pureperl_children, pureperl_children));
for (unsigned int i = 0; i < num_holes; i++) {
av_store(av, i+1, this->holes[i].to_SV(pureperl_children, pureperl_children));
}
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::ExPolygon", GV_ADD));
} else {
SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::ExPolygon::XS", this );
return sv;
}
}
void
perl2expolygon(SV* expoly_sv, ExPolygon& expoly)
{
@ -60,23 +81,23 @@ perl2expolygon(SV* expoly_sv, ExPolygon& expoly)
expoly.holes.resize(num_polygons-1);
SV** polygon_sv = av_fetch(expoly_av, 0, 0);
perl2polygon(*polygon_sv, expoly.contour);
expoly.contour.from_SV(*polygon_sv);
for (unsigned int i = 0; i < num_polygons-1; i++) {
polygon_sv = av_fetch(expoly_av, i+1, 0);
perl2polygon(*polygon_sv, expoly.holes[i]);
expoly.holes[i].from_SV(*polygon_sv);
}
}
SV*
expolygon2perl(ExPolygon& expoly) {
const unsigned int num_holes = expoly.holes.size();
AV* av = newAV();
av_extend(av, num_holes); // -1 +1
av_store(av, 0, polygon2perl(expoly.contour));
for (unsigned int i = 0; i < num_holes; i++) {
av_store(av, i+1, polygon2perl(expoly.holes[i]));
void
perl2expolygon_check(SV* expoly_sv, ExPolygon& expoly)
{
if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) {
// a XS ExPolygon was supplied
expoly = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv ));
} else {
// a Perl arrayref was supplied
perl2expolygon(expoly_sv, expoly);
}
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::ExPolygon", GV_ADD));
}
}