mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 05:37:52 -06:00
Move Polygon class to Polygon.hpp
This commit is contained in:
parent
13e3a9129c
commit
28a4f1a61e
4 changed files with 91 additions and 58 deletions
|
@ -8,13 +8,10 @@ extern "C" {
|
|||
#include "ppport.h"
|
||||
}
|
||||
|
||||
#include "Point.hpp"
|
||||
#include "Polygon.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef std::vector<Point> Polygon;
|
||||
typedef std::vector<Polygon> Polygons;
|
||||
|
||||
class ExPolygon
|
||||
{
|
||||
public:
|
||||
|
@ -26,80 +23,35 @@ class ExPolygon
|
|||
void _rotate(double angle, Point* center);
|
||||
};
|
||||
|
||||
#define scale_polygon(poly, factor) \
|
||||
for (Polygon::iterator pit = (poly).begin(); pit != (poly).end(); ++pit) { \
|
||||
(*pit).x *= factor; \
|
||||
(*pit).y *= factor; \
|
||||
}
|
||||
|
||||
#define translate_polygon(poly, x, y) \
|
||||
for (Polygon::iterator pit = (poly).begin(); pit != (poly).end(); ++pit) { \
|
||||
(*pit).x += x; \
|
||||
(*pit).y += y; \
|
||||
}
|
||||
|
||||
inline void
|
||||
rotate_polygon(Polygon* poly, double angle, Point* center)
|
||||
{
|
||||
for (Polygon::iterator pit = (*poly).begin(); pit != (*poly).end(); ++pit) { \
|
||||
(*pit).rotate(angle, center);
|
||||
}
|
||||
}
|
||||
typedef std::vector<ExPolygon> ExPolygons;
|
||||
|
||||
void
|
||||
ExPolygon::scale(double factor)
|
||||
{
|
||||
scale_polygon(contour, factor);
|
||||
contour.scale(factor);
|
||||
for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
|
||||
scale_polygon(*it, factor);
|
||||
(*it).scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::translate(double x, double y)
|
||||
{
|
||||
translate_polygon(contour, x, y);
|
||||
contour.translate(x, y);
|
||||
for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
|
||||
translate_polygon(*it, x, y);
|
||||
(*it).translate(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::_rotate(double angle, Point* center)
|
||||
{
|
||||
rotate_polygon(&contour, angle, center);
|
||||
contour._rotate(angle, center);
|
||||
for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
|
||||
rotate_polygon(&*it, angle, center);
|
||||
(*it)._rotate(angle, center);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
perl2polygon(SV* poly_sv, Polygon& poly)
|
||||
{
|
||||
AV* poly_av = (AV*)SvRV(poly_sv);
|
||||
const unsigned int num_points = av_len(poly_av)+1;
|
||||
poly.resize(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 = poly[i];
|
||||
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++) {
|
||||
av_store(av, i, point2perl(poly[i]));
|
||||
}
|
||||
return sv_bless(newRV_noinc((SV*)av), gv_stashpv("Slic3r::Polygon", GV_ADD));
|
||||
}
|
||||
|
||||
void
|
||||
perl2expolygon(SV* expoly_sv, ExPolygon& expoly)
|
||||
{
|
||||
|
|
|
@ -12,8 +12,6 @@ extern "C" {
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
typedef std::vector<ExPolygon> ExPolygons;
|
||||
|
||||
class ExPolygonCollection
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -21,6 +21,8 @@ class Point
|
|||
void rotate(double angle, Point* center);
|
||||
};
|
||||
|
||||
typedef std::vector<Point> Points;
|
||||
|
||||
void
|
||||
Point::rotate(double angle, Point* center)
|
||||
{
|
||||
|
|
81
xs/src/Polygon.hpp
Normal file
81
xs/src/Polygon.hpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#ifndef slic3r_Polygon_hpp_
|
||||
#define slic3r_Polygon_hpp_
|
||||
|
||||
extern "C" {
|
||||
#include "EXTERN.h"
|
||||
#include "perl.h"
|
||||
#include "XSUB.h"
|
||||
#include "ppport.h"
|
||||
}
|
||||
|
||||
#include "Point.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Polygon
|
||||
{
|
||||
public:
|
||||
Points points;
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void _rotate(double angle, Point* center);
|
||||
};
|
||||
|
||||
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
|
||||
perl2polygon(SV* poly_sv, Polygon& 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);
|
||||
AV* point_av = (AV*)SvRV(*point_sv);
|
||||
Point& p = poly.points[i];
|
||||
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.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::Polygon", GV_ADD));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue