Optimizations for better usage of XS code

This commit is contained in:
Alessandro Ranellucci 2013-08-29 01:36:42 +02:00
parent 9254ff9704
commit 5d6fd7f4d9
22 changed files with 68 additions and 42 deletions

View file

@ -14,6 +14,12 @@ ExtrusionPath::first_point() const
return &(this->polyline.points.front());
}
const Point*
ExtrusionPath::last_point() const
{
return &(this->polyline.points.back());
}
ExtrusionPath*
ExtrusionLoop::split_at_index(int index)
{

View file

@ -39,6 +39,7 @@ class ExtrusionPath : public ExtrusionEntity
Polyline polyline;
void reverse();
const Point* first_point() const;
const Point* last_point() const;
};
class ExtrusionLoop : public ExtrusionEntity

View file

@ -36,6 +36,12 @@ Line::length() const
return this->a.distance_to(&(this->b));
}
Point*
Line::midpoint() const
{
return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
}
void
Line::from_SV(SV* line_sv)
{

View file

@ -23,6 +23,7 @@ class Line
void rotate(double angle, Point* center);
void reverse();
double length() const;
Point* midpoint() const;
};
typedef std::vector<Line> Lines;

View file

@ -38,6 +38,12 @@ MultiPoint::first_point() const
return &(this->points.front());
}
const Point*
MultiPoint::last_point() const
{
return &(this->points.back());
}
void
MultiPoint::from_SV(SV* poly_sv)
{

View file

@ -20,6 +20,7 @@ class MultiPoint
void rotate(double angle, Point* center);
void reverse();
const Point* first_point() const;
const Point* last_point() const;
};
}

View file

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 4;
use Test::More tests => 5;
my $points = [
[100, 100],
@ -24,4 +24,7 @@ is_deeply [ map $_->pp, @$lines ], [
[ [200, 100], [200, 200] ],
], 'polyline lines';
$polyline->append_polyline($polyline->clone);
is_deeply $polyline->pp, [ @$points, @$points ], 'append_polyline';
__END__

View file

@ -18,6 +18,8 @@
%code{% RETVAL = THIS->polyline.lines(); %};
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
%{
ExtrusionPath*

View file

@ -21,6 +21,8 @@
void scale(double factor);
void translate(double x, double y);
double length();
Point* midpoint()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->midpoint(); %};
%{
Line*

View file

@ -21,6 +21,8 @@
Lines lines();
Point* first_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->first_point())); %};
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*(THIS->last_point())); %};
%{
Polyline*
@ -44,6 +46,14 @@ Polyline::append(...)
THIS->points.push_back(p);
}
void
Polyline::append_polyline(polyline)
Polyline* polyline;
CODE:
for (Points::const_iterator it = polyline->points.begin(); it != polyline->points.end(); ++it) {
THIS->points.push_back((*it));
}
void
Polyline::rotate(angle, center_sv)
double angle;