mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-21 07:41:09 -06:00
More integration of Slic3r::Point::XS
This commit is contained in:
parent
159a009f96
commit
c9749ca3b3
9 changed files with 80 additions and 17 deletions
|
@ -18,18 +18,41 @@ class Point
|
|||
long x;
|
||||
long y;
|
||||
Point(long _x = 0, long _y = 0): x(_x), y(_y) {};
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void rotate(double angle, Point* center);
|
||||
bool coincides_with(Point* point);
|
||||
};
|
||||
|
||||
typedef std::vector<Point> Points;
|
||||
|
||||
void
|
||||
Point::scale(double factor)
|
||||
{
|
||||
this->x *= factor;
|
||||
this->y *= factor;
|
||||
}
|
||||
|
||||
void
|
||||
Point::translate(double x, double y)
|
||||
{
|
||||
this->x += x;
|
||||
this->y += y;
|
||||
}
|
||||
|
||||
void
|
||||
Point::rotate(double angle, Point* center)
|
||||
{
|
||||
double cur_x = (double)x;
|
||||
double cur_y = (double)y;
|
||||
x = (long)( (double)center->x + cos(angle) * (cur_x - (double)center->x) - sin(angle) * (cur_y - (double)center->y) );
|
||||
y = (long)( (double)center->y + cos(angle) * (cur_y - (double)center->y) + sin(angle) * (cur_x - (double)center->x) );
|
||||
double cur_x = (double)this->x;
|
||||
double cur_y = (double)this->y;
|
||||
this->x = (long)( (double)center->x + cos(angle) * (cur_x - (double)center->x) - sin(angle) * (cur_y - (double)center->y) );
|
||||
this->y = (long)( (double)center->y + cos(angle) * (cur_y - (double)center->y) + sin(angle) * (cur_x - (double)center->x) );
|
||||
}
|
||||
|
||||
bool
|
||||
Point::coincides_with(Point* point)
|
||||
{
|
||||
return this->x == point->x && this->y == point->y;
|
||||
}
|
||||
|
||||
SV*
|
||||
|
@ -48,6 +71,16 @@ perl2point(SV* point_sv, Point& point)
|
|||
point.y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0));
|
||||
}
|
||||
|
||||
void
|
||||
perl2point_check(SV* point_sv, Point& point)
|
||||
{
|
||||
if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) {
|
||||
point = *(Point*)SvIV((SV*)SvRV( point_sv ));
|
||||
} else {
|
||||
perl2point(point_sv, point);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,8 +29,7 @@ void
|
|||
Polyline::scale(double factor)
|
||||
{
|
||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
(*it).x *= factor;
|
||||
(*it).y *= factor;
|
||||
(*it).scale(factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,8 +37,7 @@ void
|
|||
Polyline::translate(double x, double y)
|
||||
{
|
||||
for (Points::iterator it = points.begin(); it != points.end(); ++it) {
|
||||
(*it).x += x;
|
||||
(*it).y += y;
|
||||
(*it).translate(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue