mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 07:41:09 -06:00
New Slic3r::ExPolygon::XS class
This commit is contained in:
parent
c2d63bcd09
commit
5a11d4df89
9 changed files with 138 additions and 3 deletions
52
xs/src/ExPolygon.hpp
Normal file
52
xs/src/ExPolygon.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
#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;
|
||||
SV* _toPerl();
|
||||
};
|
||||
|
||||
Polygon*
|
||||
perl2polygon(SV* poly_sv)
|
||||
{
|
||||
AV* poly_av = (AV*)SvRV(poly_sv);
|
||||
const unsigned int num_points = av_len(poly_av)+1;
|
||||
Polygon* retval = new Polygon(num_points);
|
||||
|
||||
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);
|
||||
Point& p = (*retval)[i];
|
||||
p.x = (unsigned long)SvIV(*av_fetch(point_av, 0, 0));
|
||||
p.y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0));
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
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++) {
|
||||
av_store(av, i, poly[i]._toPerl());
|
||||
}
|
||||
return (SV*)newRV_noinc((SV*)av);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,7 +1,6 @@
|
|||
#include "myinit.h"
|
||||
#include "Point.hpp"
|
||||
|
||||
Point::Point(unsigned long x, unsigned long y) {}
|
||||
Point::~Point() {}
|
||||
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class Point
|
|||
public:
|
||||
unsigned long x;
|
||||
unsigned long y;
|
||||
Point(unsigned long _x, unsigned long _y): x(_x), y(_y) {};
|
||||
Point(unsigned long _x = 0, unsigned long _y = 0): x(_x), y(_y) {};
|
||||
~Point();
|
||||
SV* _toPerl();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue