Polygon->lines

This commit is contained in:
Alessandro Ranellucci 2013-07-15 23:28:23 +02:00
parent 77c479c127
commit 62e5bd0ee7
3 changed files with 25 additions and 2 deletions

View File

@ -13,10 +13,24 @@ extern "C" {
namespace Slic3r { namespace Slic3r {
class Polygon : public MultiPoint {}; class Polygon : public MultiPoint {
public:
Lines lines();
};
typedef std::vector<Polygon> Polygons; typedef std::vector<Polygon> Polygons;
Lines
Polygon::lines()
{
Lines lines;
for (int i = 0; i < this->points.size()-1; i++) {
lines.push_back(Line(this->points[i], this->points[i+1]));
}
lines.push_back(Line(this->points.back(), this->points.front()));
return lines;
}
} }
#endif #endif

View File

@ -4,7 +4,7 @@ use strict;
use warnings; use warnings;
use Slic3r::XS; use Slic3r::XS;
use Test::More tests => 3; use Test::More tests => 4;
my $square = [ # ccw my $square = [ # ccw
[100, 100], [100, 100],
@ -19,4 +19,12 @@ is_deeply $polygon->pp, $square, 'polygon roundtrip';
is ref($polygon->arrayref), 'ARRAY', 'polygon arrayref is unblessed'; is ref($polygon->arrayref), 'ARRAY', 'polygon arrayref is unblessed';
isa_ok $polygon->[0], 'Slic3r::Point', 'polygon point is blessed'; isa_ok $polygon->[0], 'Slic3r::Point', 'polygon point is blessed';
my $lines = $polygon->lines;
is_deeply [ map $_->pp, @$lines ], [
[ [100, 100], [200, 100] ],
[ [200, 100], [200, 200] ],
[ [200, 200], [100, 200] ],
[ [100, 200], [100, 100] ],
], 'polygon lines';
__END__ __END__

View File

@ -15,6 +15,7 @@
%code{% RETVAL = THIS->to_SV_pureperl(); %}; %code{% RETVAL = THIS->to_SV_pureperl(); %};
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
Lines lines();
%{ %{
Polygon* Polygon*