2013-07-06 14:33:49 +00:00
|
|
|
#ifndef slic3r_ExPolygon_hpp_
|
|
|
|
#define slic3r_ExPolygon_hpp_
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "EXTERN.h"
|
|
|
|
#include "perl.h"
|
|
|
|
#include "XSUB.h"
|
|
|
|
#include "ppport.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "Point.hpp"
|
|
|
|
|
|
|
|
typedef std::vector<Point> Polygon;
|
|
|
|
typedef std::vector<Polygon> Polygons;
|
|
|
|
|
|
|
|
class ExPolygon
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Polygon contour;
|
|
|
|
Polygons holes;
|
2013-07-07 10:41:54 +00:00
|
|
|
SV* arrayref();
|
2013-07-06 14:33:49 +00:00
|
|
|
};
|
|
|
|
|
2013-07-07 14:51:02 +00:00
|
|
|
void
|
|
|
|
perl2polygon(SV* poly_sv, Polygon& poly)
|
2013-07-06 14:33:49 +00:00
|
|
|
{
|
|
|
|
AV* poly_av = (AV*)SvRV(poly_sv);
|
|
|
|
const unsigned int num_points = av_len(poly_av)+1;
|
2013-07-07 14:51:02 +00:00
|
|
|
poly.resize(num_points);
|
2013-07-06 14:33:49 +00:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < num_points; i++) {
|
|
|
|
SV** point_sv = av_fetch(poly_av, i, 0);
|
|
|
|
AV* point_av = (AV*)SvRV(*point_sv);
|
2013-07-07 14:51:02 +00:00
|
|
|
Point& p = poly[i];
|
2013-07-06 14:33:49 +00:00
|
|
|
p.x = (unsigned long)SvIV(*av_fetch(point_av, 0, 0));
|
|
|
|
p.y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SV*
|
|
|
|
polygon2perl(Polygon& poly) {
|
|
|
|
const unsigned int num_points = poly.size();
|
|
|
|
AV* av = newAV();
|
|
|
|
av_extend(av, num_points-1);
|
|
|
|
for (unsigned int i = 0; i < num_points; i++) {
|
2013-07-06 14:39:22 +00:00
|
|
|
av_store(av, i, point2perl(poly[i]));
|
2013-07-06 14:33:49 +00:00
|
|
|
}
|
|
|
|
return (SV*)newRV_noinc((SV*)av);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|