Polygon->lines
This commit is contained in:
parent
77c479c127
commit
62e5bd0ee7
@ -13,10 +13,24 @@ extern "C" {
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Polygon : public MultiPoint {};
|
||||
class Polygon : public MultiPoint {
|
||||
public:
|
||||
Lines lines();
|
||||
};
|
||||
|
||||
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
|
||||
|
@ -4,7 +4,7 @@ use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 3;
|
||||
use Test::More tests => 4;
|
||||
|
||||
my $square = [ # ccw
|
||||
[100, 100],
|
||||
@ -19,4 +19,12 @@ is_deeply $polygon->pp, $square, 'polygon roundtrip';
|
||||
is ref($polygon->arrayref), 'ARRAY', 'polygon arrayref is unblessed';
|
||||
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__
|
||||
|
@ -15,6 +15,7 @@
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
Lines lines();
|
||||
%{
|
||||
|
||||
Polygon*
|
||||
|
Loading…
Reference in New Issue
Block a user