Implemented Slic3r::ExtrusionLoop
This commit is contained in:
parent
c9749ca3b3
commit
d0701cdcd4
10 changed files with 145 additions and 88 deletions
|
@ -29,16 +29,15 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref };
|
||||
|
||||
package Slic3r::ExtrusionLoop;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
sub new {
|
||||
my ($class, %args) = @_;
|
||||
|
||||
my $polygon = ref($args{polygon}) eq 'Slic3r::Polygon::XS'
|
||||
? $args{polygon}
|
||||
: Slic3r::Polygon::XS->new(@{$args{polygon}});
|
||||
|
||||
return $class->_new(
|
||||
$polygon, # required
|
||||
$args{polygon}, # required
|
||||
$args{role}, # required
|
||||
$args{height} // -1,
|
||||
$args{flow_spacing} // -1,
|
||||
|
@ -49,7 +48,7 @@ sub clone {
|
|||
my ($self, %args) = @_;
|
||||
|
||||
return (ref $self)->_new(
|
||||
$args{polygon} // $self->polygon->clone,
|
||||
$args{polygon} // $self->as_polygon,
|
||||
$args{role} // $self->role,
|
||||
$args{height} // $self->height,
|
||||
$args{flow_spacing} // $self->flow_spacing,
|
||||
|
@ -64,12 +63,8 @@ use overload
|
|||
sub new {
|
||||
my ($class, %args) = @_;
|
||||
|
||||
my $polyline = ref($args{polyline}) eq 'Slic3r::Polyline::XS'
|
||||
? $args{polyline}
|
||||
: Slic3r::Polyline::XS->new(@{$args{polyline}});
|
||||
|
||||
return $class->_new(
|
||||
$polyline, # required
|
||||
$args{polyline}, # required
|
||||
$args{role}, # required
|
||||
$args{height} // -1,
|
||||
$args{flow_spacing} // -1,
|
||||
|
|
|
@ -29,6 +29,16 @@ perl2polygon(SV* poly_sv, Polygon& poly)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
perl2polygon_check(SV* poly_sv, Polygon& poly)
|
||||
{
|
||||
if (sv_isobject(poly_sv) && (SvTYPE(SvRV(poly_sv)) == SVt_PVMG)) {
|
||||
poly = *(Polygon*)SvIV((SV*)SvRV( poly_sv ));
|
||||
} else {
|
||||
perl2polygon(poly_sv, poly);
|
||||
}
|
||||
}
|
||||
|
||||
SV*
|
||||
polygon2perl(Polygon& poly) {
|
||||
const unsigned int num_points = poly.points.size();
|
||||
|
|
|
@ -68,6 +68,16 @@ perl2polyline(SV* poly_sv, Polyline& poly)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
perl2polyline_check(SV* poly_sv, Polyline& poly)
|
||||
{
|
||||
if (sv_isobject(poly_sv) && (SvTYPE(SvRV(poly_sv)) == SVt_PVMG)) {
|
||||
poly = *(Polyline*)SvIV((SV*)SvRV( poly_sv ));
|
||||
} else {
|
||||
perl2polyline(poly_sv, poly);
|
||||
}
|
||||
}
|
||||
|
||||
SV*
|
||||
polyline2perl(Polyline& poly) {
|
||||
const unsigned int num_points = poly.points.size();
|
||||
|
|
29
xs/t/08_extrusionloop.t
Normal file
29
xs/t/08_extrusionloop.t
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 4;
|
||||
|
||||
my $square = [
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
[200, 200],
|
||||
[100, 200],
|
||||
];
|
||||
|
||||
my $loop = Slic3r::ExtrusionLoop->new(
|
||||
polygon => Slic3r::Polygon::XS->new(@$square),
|
||||
role => Slic3r::ExtrusionPath::EXTR_ROLE_EXTERNAL_PERIMETER,
|
||||
);
|
||||
isa_ok $loop->as_polygon, 'Slic3r::Polygon::XS', 'loop polygon';
|
||||
is_deeply [ @{ $loop->as_polygon } ], [ @$square ], 'polygon points roundtrip';
|
||||
|
||||
$loop = $loop->clone;
|
||||
|
||||
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';
|
||||
|
||||
__END__
|
65
xs/xsp/ExtrusionLoop.xsp
Normal file
65
xs/xsp/ExtrusionLoop.xsp
Normal file
|
@ -0,0 +1,65 @@
|
|||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "ExtrusionEntity.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
|
||||
~ExtrusionLoop();
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = polygon2perl(THIS->polygon); %};
|
||||
Polygon* as_polygon()
|
||||
%code{% const char* CLASS = "Slic3r::Polygon::XS"; RETVAL = new Polygon(THIS->polygon); %};
|
||||
void set_polygon(SV* polygon_sv)
|
||||
%code{% perl2polygon_check(polygon_sv, THIS->polygon); %};
|
||||
%{
|
||||
|
||||
ExtrusionLoop*
|
||||
_new(CLASS, polygon_sv, role, height, flow_spacing)
|
||||
char* CLASS;
|
||||
SV* polygon_sv;
|
||||
ExtrusionRole role;
|
||||
double height;
|
||||
double flow_spacing;
|
||||
CODE:
|
||||
RETVAL = new ExtrusionLoop ();
|
||||
perl2polygon_check(polygon_sv, RETVAL->polygon);
|
||||
RETVAL->role = role;
|
||||
RETVAL->height = height;
|
||||
RETVAL->flow_spacing = flow_spacing;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
ExtrusionRole
|
||||
ExtrusionLoop::role(...)
|
||||
CODE:
|
||||
if (items > 1) {
|
||||
THIS->role = (ExtrusionRole)SvUV(ST(1));
|
||||
}
|
||||
RETVAL = THIS->role;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
double
|
||||
ExtrusionLoop::height(...)
|
||||
CODE:
|
||||
if (items > 1) {
|
||||
THIS->height = (double)SvNV(ST(1));
|
||||
}
|
||||
RETVAL = THIS->height;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
double
|
||||
ExtrusionLoop::flow_spacing(...)
|
||||
CODE:
|
||||
if (items > 1) {
|
||||
THIS->flow_spacing = (double)SvNV(ST(1));
|
||||
}
|
||||
RETVAL = THIS->flow_spacing;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
%}
|
||||
};
|
|
@ -9,6 +9,10 @@
|
|||
~ExtrusionPath();
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = polyline2perl(THIS->polyline); %};
|
||||
Polyline* as_polyline()
|
||||
%code{% const char* CLASS = "Slic3r::Polyline::XS"; RETVAL = new Polyline(THIS->polyline); %};
|
||||
void set_polyline(SV* polyline_sv)
|
||||
%code{% perl2polyline_check(polyline_sv, THIS->polyline); %};
|
||||
void pop_back()
|
||||
%code{% THIS->polyline.points.pop_back(); %};
|
||||
void reverse();
|
||||
|
@ -23,36 +27,13 @@ _new(CLASS, polyline_sv, role, height, flow_spacing)
|
|||
double flow_spacing;
|
||||
CODE:
|
||||
RETVAL = new ExtrusionPath ();
|
||||
if (sv_isobject(polyline_sv) && (SvTYPE(SvRV(polyline_sv)) == SVt_PVMG)) {
|
||||
RETVAL->polyline = *(Polyline*)SvIV((SV*)SvRV( polyline_sv ));
|
||||
} else {
|
||||
perl2polyline(polyline_sv, RETVAL->polyline);
|
||||
}
|
||||
perl2polyline_check(polyline_sv, RETVAL->polyline);
|
||||
RETVAL->role = role;
|
||||
RETVAL->height = height;
|
||||
RETVAL->flow_spacing = flow_spacing;
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
Polyline*
|
||||
ExtrusionPath::as_polyline()
|
||||
PREINIT:
|
||||
const char* CLASS = "Slic3r::Polyline::XS";
|
||||
CODE:
|
||||
RETVAL = new Polyline(THIS->polyline);
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
|
||||
void
|
||||
ExtrusionPath::set_polyline(polyline_sv)
|
||||
SV* polyline_sv;
|
||||
CODE:
|
||||
if (sv_isobject(polyline_sv) && (SvTYPE(SvRV(polyline_sv)) == SVt_PVMG)) {
|
||||
THIS->polyline = *(Polyline*)SvIV((SV*)SvRV( polyline_sv ));
|
||||
} else {
|
||||
perl2polyline(polyline_sv, THIS->polyline);
|
||||
}
|
||||
|
||||
ExtrusionRole
|
||||
ExtrusionPath::role(...)
|
||||
CODE:
|
||||
|
@ -88,11 +69,7 @@ ExtrusionPath::append(...)
|
|||
CODE:
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
Point p;
|
||||
if (sv_isobject(ST(i)) && (SvTYPE(SvRV(ST(i))) == SVt_PVMG)) {
|
||||
p = *(Point*)SvIV((SV*)SvRV( ST(i) ));
|
||||
} else {
|
||||
perl2point(ST(i), p);
|
||||
}
|
||||
perl2point_check(ST(i), p);
|
||||
THIS->polyline.points.push_back(p);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue