mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 07:41:09 -06:00
ExPolygon::XS->rotate()
This commit is contained in:
parent
1506907212
commit
87a5de193d
7 changed files with 86 additions and 19 deletions
|
@ -21,6 +21,7 @@ class ExPolygon
|
|||
SV* arrayref();
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void _rotate(double angle, Point* center);
|
||||
};
|
||||
|
||||
#define scale_polygon(poly, factor) \
|
||||
|
@ -35,6 +36,14 @@ class ExPolygon
|
|||
(*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);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::scale(double factor)
|
||||
{
|
||||
|
@ -53,6 +62,15 @@ ExPolygon::translate(double x, double y)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ExPolygon::_rotate(double angle, Point* center)
|
||||
{
|
||||
rotate_polygon(&contour, angle, center);
|
||||
for (Polygons::iterator it = holes.begin(); it != holes.end(); ++it) {
|
||||
rotate_polygon(&*it, angle, center);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
perl2polygon(SV* poly_sv, Polygon& poly)
|
||||
{
|
||||
|
|
|
@ -8,14 +8,26 @@ extern "C" {
|
|||
#include "ppport.h"
|
||||
}
|
||||
|
||||
#include <math.h>
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
unsigned long x;
|
||||
unsigned long y;
|
||||
Point(unsigned long _x = 0, unsigned long _y = 0): x(_x), y(_y) {};
|
||||
void rotate(double angle, Point* center);
|
||||
};
|
||||
|
||||
void
|
||||
Point::rotate(double angle, Point* center)
|
||||
{
|
||||
double cur_x = (double)x;
|
||||
double cur_y = (double)y;
|
||||
x = (unsigned long)( (double)center->x + cos(angle) * (cur_x - (double)center->x) - sin(angle) * (cur_y - (double)center->y) );
|
||||
y = (unsigned long)( (double)center->y + cos(angle) * (cur_y - (double)center->y) + sin(angle) * (cur_x - (double)center->x) );
|
||||
}
|
||||
|
||||
SV*
|
||||
point2perl(Point& point) {
|
||||
AV* av = newAV();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue