Have Polygon inherit from Polyline
This commit is contained in:
parent
06de21b154
commit
8c1e1cc3ea
2 changed files with 80 additions and 35 deletions
|
@ -8,47 +8,14 @@ extern "C" {
|
||||||
#include "ppport.h"
|
#include "ppport.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "Point.hpp"
|
#include "Polyline.hpp"
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
class Polygon
|
class Polygon : public Polyline {};
|
||||||
{
|
|
||||||
public:
|
|
||||||
Points points;
|
|
||||||
void scale(double factor);
|
|
||||||
void translate(double x, double y);
|
|
||||||
void rotate(double angle, Point* center);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::vector<Polygon> Polygons;
|
typedef std::vector<Polygon> Polygons;
|
||||||
|
|
||||||
void
|
|
||||||
Polygon::scale(double factor)
|
|
||||||
{
|
|
||||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
|
||||||
(*it).x *= factor;
|
|
||||||
(*it).y *= factor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Polygon::translate(double x, double y)
|
|
||||||
{
|
|
||||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
|
||||||
(*it).x += x;
|
|
||||||
(*it).y += y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Polygon::rotate(double angle, Point* center)
|
|
||||||
{
|
|
||||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
|
||||||
(*it).rotate(angle, center);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
perl2polygon(SV* poly_sv, Polygon& poly)
|
perl2polygon(SV* poly_sv, Polygon& poly)
|
||||||
{
|
{
|
||||||
|
|
78
xs/src/Polyline.hpp
Normal file
78
xs/src/Polyline.hpp
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
#ifndef slic3r_Polyline_hpp_
|
||||||
|
#define slic3r_Polyline_hpp_
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "EXTERN.h"
|
||||||
|
#include "perl.h"
|
||||||
|
#include "XSUB.h"
|
||||||
|
#include "ppport.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "Point.hpp"
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
class Polyline
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Points points;
|
||||||
|
void scale(double factor);
|
||||||
|
void translate(double x, double y);
|
||||||
|
void rotate(double angle, Point* center);
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::vector<Polyline> Polylines;
|
||||||
|
|
||||||
|
void
|
||||||
|
Polyline::scale(double factor)
|
||||||
|
{
|
||||||
|
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||||
|
(*it).x *= factor;
|
||||||
|
(*it).y *= factor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Polyline::translate(double x, double y)
|
||||||
|
{
|
||||||
|
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||||
|
(*it).x += x;
|
||||||
|
(*it).y += y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Polyline::rotate(double angle, Point* center)
|
||||||
|
{
|
||||||
|
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||||
|
(*it).rotate(angle, center);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
perl2polyline(SV* poly_sv, Polyline& poly)
|
||||||
|
{
|
||||||
|
AV* poly_av = (AV*)SvRV(poly_sv);
|
||||||
|
const unsigned int num_points = av_len(poly_av)+1;
|
||||||
|
poly.points.resize(num_points);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < num_points; i++) {
|
||||||
|
SV** point_sv = av_fetch(poly_av, i, 0);
|
||||||
|
perl2point(*point_sv, poly.points[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SV*
|
||||||
|
polyline2perl(Polyline& poly) {
|
||||||
|
const unsigned int num_points = poly.points.size();
|
||||||
|
AV* av = newAV();
|
||||||
|
av_extend(av, num_points-1);
|
||||||
|
for (unsigned int i = 0; i < num_points; i++) {
|
||||||
|
av_store(av, i, point2perl(poly.points[i]));
|
||||||
|
}
|
||||||
|
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Polyline", GV_ADD));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue