diff --git a/xs/src/ExtrusionEntity.hpp b/xs/src/ExtrusionEntity.hpp index 257bd3ff2..34fbda7db 100644 --- a/xs/src/ExtrusionEntity.hpp +++ b/xs/src/ExtrusionEntity.hpp @@ -47,6 +47,8 @@ class ExtrusionLoop : public ExtrusionEntity { public: Polygon polygon; + ExtrusionPath* split_at_index(int index); + ExtrusionPath* split_at_first_point(); }; void @@ -55,6 +57,27 @@ ExtrusionPath::reverse() this->polyline.reverse(); } +ExtrusionPath* +ExtrusionLoop::split_at_index(int index) +{ + Polyline* poly = this->polygon.split_at_index(index); + + ExtrusionPath* path = new ExtrusionPath(); + path->polyline = *poly; + path->role = this->role; + path->height = this->height; + path->flow_spacing = this->flow_spacing; + + delete poly; + return path; +} + +ExtrusionPath* +ExtrusionLoop::split_at_first_point() +{ + return this->split_at_index(0); +} + } #endif diff --git a/xs/t/08_extrusionloop.t b/xs/t/08_extrusionloop.t index 548431411..8ae7237d3 100644 --- a/xs/t/08_extrusionloop.t +++ b/xs/t/08_extrusionloop.t @@ -4,7 +4,7 @@ use strict; use warnings; use Slic3r::XS; -use Test::More tests => 4; +use Test::More tests => 7; my $square = [ [100, 100], @@ -26,4 +26,12 @@ is $loop->role, Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER, 'role'; $loop->role(Slic3r::ExtrusionPath::EXTR_ROLE_FILL); is $loop->role, Slic3r::ExtrusionPath::EXTR_ROLE_FILL, 'modify role'; +{ + my $path = $loop->split_at_first_point; + is_deeply $path->as_polyline->pp, $square, 'split_at_first_point'; + is $path->role, $loop->role, 'role preserved after split'; + + is_deeply $loop->split_at_index(2)->as_polyline->pp, [ @$square[2,3,0,1] ], 'split_at_index'; +} + __END__ diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index ee5f32a22..e401efc76 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -15,6 +15,10 @@ %code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(THIS->polygon); %}; void set_polygon(SV* polygon_sv) %code{% THIS->polygon.from_SV_check(polygon_sv); %}; + ExtrusionPath* split_at_index(int index) + %code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_index(index); %}; + ExtrusionPath* split_at_first_point() + %code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_first_point(); %}; %{ ExtrusionLoop* diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 2357bdf8e..78564998b 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -6,6 +6,8 @@ %typemap{ExPolygon*}; %typemap{Polyline*}; %typemap{Polygon*}; +%typemap{ExtrusionPath*}; +%typemap{ExtrusionLoop*}; %typemap{Lines}; %typemap{SurfaceType}{parsed}{