Implemented split_at_index() and split_at_first_point() for Polygon

This commit is contained in:
Alessandro Ranellucci 2013-07-15 23:38:06 +02:00
parent 62e5bd0ee7
commit 0d07a2e4e6
3 changed files with 29 additions and 1 deletions

View File

@ -16,6 +16,8 @@ namespace Slic3r {
class Polygon : public MultiPoint {
public:
Lines lines();
Polyline* split_at_index(int index);
Polyline* split_at_first_point();
};
typedef std::vector<Polygon> Polygons;
@ -31,6 +33,25 @@ Polygon::lines()
return lines;
}
Polyline*
Polygon::split_at_index(int index)
{
Polyline* poly = new Polyline;
for (int i = index; i < this->points.size(); i++) {
poly->points.push_back( this->points[i] );
}
for (int i = 0; i < index; i++) {
poly->points.push_back( this->points[i] );
}
return poly;
}
Polyline*
Polygon::split_at_first_point()
{
return this->split_at_index(0);
}
}
#endif

View File

@ -4,7 +4,7 @@ use strict;
use warnings;
use Slic3r::XS;
use Test::More tests => 4;
use Test::More tests => 6;
my $square = [ # ccw
[100, 100],
@ -27,4 +27,7 @@ is_deeply [ map $_->pp, @$lines ], [
[ [100, 200], [100, 100] ],
], 'polygon lines';
is_deeply $polygon->split_at_first_point->pp, $square, 'split_at_first_point';
is_deeply $polygon->split_at_index(2)->pp, [ @$square[2,3,0,1] ], 'split_at_index';
__END__

View File

@ -16,6 +16,10 @@
void scale(double factor);
void translate(double x, double y);
Lines lines();
Polyline* split_at_index(int index)
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %};
Polyline* split_at_first_point()
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %};
%{
Polygon*