mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-20 23:31:13 -06:00
Fix integration of XS containers
This commit is contained in:
parent
9b582a11ff
commit
9458c7db97
34 changed files with 279 additions and 152 deletions
|
@ -7,26 +7,36 @@ our $VERSION = '0.01';
|
|||
use XSLoader;
|
||||
XSLoader::load(__PACKAGE__, $VERSION);
|
||||
|
||||
package Slic3r::Point;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
|
||||
package Slic3r::ExPolygon;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
|
||||
package Slic3r::Polyline;
|
||||
package Slic3r::Line;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Point;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::ExPolygon;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polyline;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1,
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Polygon;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::ExPolygon::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::ExtrusionLoop;
|
||||
use overload
|
||||
|
@ -116,6 +126,7 @@ sub clone {
|
|||
|
||||
package Slic3r::Surface::Collection;
|
||||
use overload
|
||||
'@{}' => sub { $_[0]->arrayref };
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
1;
|
||||
|
|
|
@ -72,8 +72,8 @@ void
|
|||
Point::from_SV(SV* point_sv)
|
||||
{
|
||||
AV* point_av = (AV*)SvRV(point_sv);
|
||||
this->x = (unsigned long)SvIV(*av_fetch(point_av, 0, 0));
|
||||
this->y = (unsigned long)SvIV(*av_fetch(point_av, 1, 0));
|
||||
this->x = (long)SvIV(*av_fetch(point_av, 0, 0));
|
||||
this->y = (long)SvIV(*av_fetch(point_av, 1, 0));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -40,7 +40,7 @@ Polygon::split_at_index(int index)
|
|||
for (int i = index; i < this->points.size(); i++) {
|
||||
poly->points.push_back( this->points[i] );
|
||||
}
|
||||
for (int i = 0; i < index; i++) {
|
||||
for (int i = 0; i <= index; i++) {
|
||||
poly->points.push_back( this->points[i] );
|
||||
}
|
||||
return poly;
|
||||
|
|
|
@ -4,7 +4,7 @@ use strict;
|
|||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 5;
|
||||
use Test::More tests => 7;
|
||||
|
||||
my $point = Slic3r::Point->new(10, 15);
|
||||
is_deeply [ @$point ], [10, 15], 'point roundtrip';
|
||||
|
@ -19,4 +19,10 @@ is_deeply [ @$point2 ], [30, 15], 'translate';
|
|||
ok $point->coincides_with($point->clone), 'coincides_with';
|
||||
ok !$point->coincides_with($point2), 'coincides_with';
|
||||
|
||||
{
|
||||
my $point3 = Slic3r::Point->new(4300000, -9880845);
|
||||
is $point->[0], $point->x, 'x accessor';
|
||||
is $point->[1], $point->y, 'y accessor';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
|
@ -27,7 +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';
|
||||
is_deeply $polygon->split_at_first_point->pp, [ @$square[0,1,2,3,0] ], 'split_at_first_point';
|
||||
is_deeply $polygon->split_at_index(2)->pp, [ @$square[2,3,0,1,2] ], 'split_at_index';
|
||||
|
||||
__END__
|
||||
|
|
|
@ -28,10 +28,10 @@ is $loop->role, Slic3r::ExtrusionPath::EXTR_ROLE_FILL, 'modify role';
|
|||
|
||||
{
|
||||
my $path = $loop->split_at_first_point;
|
||||
is_deeply $path->polyline->pp, $square, 'split_at_first_point';
|
||||
is_deeply $path->polyline->pp, [ @$square[0,1,2,3,0] ], 'split_at_first_point';
|
||||
is $path->role, $loop->role, 'role preserved after split';
|
||||
|
||||
is_deeply $loop->split_at_index(2)->polyline->pp, [ @$square[2,3,0,1] ], 'split_at_index';
|
||||
is_deeply $loop->split_at_index(2)->polyline->pp, [ @$square[2,3,0,1,2] ], 'split_at_index';
|
||||
}
|
||||
|
||||
__END__
|
||||
|
|
40
xs/t/10_line.t
Normal file
40
xs/t/10_line.t
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Slic3r::XS;
|
||||
use Test::More tests => 6;
|
||||
|
||||
my $points = [
|
||||
[100, 100],
|
||||
[200, 100],
|
||||
];
|
||||
|
||||
my $line = Slic3r::Line->new(@$points);
|
||||
is_deeply $line->pp, $points, 'line roundtrip';
|
||||
|
||||
is ref($line->arrayref), 'ARRAY', 'line arrayref is unblessed';
|
||||
isa_ok $line->[0], 'Slic3r::Point', 'line point is blessed';
|
||||
|
||||
{
|
||||
my $clone = $line->clone;
|
||||
$clone->reverse;
|
||||
is_deeply $clone->pp, [ reverse @$points ], 'reverse';
|
||||
}
|
||||
|
||||
{
|
||||
my $line2 = Slic3r::Line->new($line->a->clone, $line->b->clone);
|
||||
is_deeply $line2->pp, $points, 'line roundtrip with cloned points';
|
||||
}
|
||||
|
||||
{
|
||||
my $clone = $line->clone;
|
||||
$clone->translate(10, -5);
|
||||
is_deeply $clone->pp, [
|
||||
[110, 95],
|
||||
[210, 95],
|
||||
], 'translate';
|
||||
}
|
||||
|
||||
__END__
|
|
@ -11,6 +11,8 @@
|
|||
%code{% RETVAL = THIS->polygon.to_SV(); %};
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->polygon.to_SV_pureperl(); %};
|
||||
void reverse()
|
||||
%code{% THIS->polygon.reverse(); %};
|
||||
ExtrusionPath* split_at_index(int index)
|
||||
%code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_index(index); %};
|
||||
ExtrusionPath* split_at_first_point()
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
void pop_back()
|
||||
%code{% THIS->polyline.points.pop_back(); %};
|
||||
void reverse();
|
||||
Lines lines()
|
||||
%code{% RETVAL = THIS->polyline.lines(); %};
|
||||
%{
|
||||
|
||||
ExtrusionPath*
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
Point* b()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->b); %};
|
||||
void reverse();
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
%{
|
||||
|
||||
Line*
|
||||
|
@ -29,6 +31,16 @@ Line::new(...)
|
|||
RETVAL->b.from_SV_check( ST(2) );
|
||||
OUTPUT:
|
||||
RETVAL
|
||||
}
|
||||
|
||||
void
|
||||
Line::rotate(angle, center_sv)
|
||||
double angle;
|
||||
SV* center_sv;
|
||||
CODE:
|
||||
Point center;
|
||||
center.from_SV_check(center_sv);
|
||||
THIS->rotate(angle, ¢er);
|
||||
|
||||
%}
|
||||
};
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
%}
|
||||
|
||||
%name{Slic3r::Point} class Point {
|
||||
Point(unsigned long _x = 0, unsigned long _y = 0);
|
||||
Point(long _x = 0, long _y = 0);
|
||||
~Point();
|
||||
Point* clone()
|
||||
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*THIS); %};
|
||||
|
@ -14,9 +14,11 @@
|
|||
void translate(double x, double y);
|
||||
SV* arrayref()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
unsigned long x()
|
||||
SV* pp()
|
||||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
long x()
|
||||
%code{% RETVAL = THIS->x; %};
|
||||
unsigned long y()
|
||||
long y()
|
||||
%code{% RETVAL = THIS->y; %};
|
||||
|
||||
%{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
%code{% RETVAL = THIS->to_SV_pureperl(); %};
|
||||
void scale(double factor);
|
||||
void translate(double x, double y);
|
||||
void reverse();
|
||||
Lines lines();
|
||||
Polyline* split_at_index(int index)
|
||||
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %};
|
||||
|
|
|
@ -38,7 +38,7 @@ Polyline::append(...)
|
|||
CODE:
|
||||
for (unsigned int i = 1; i < items; i++) {
|
||||
Point p;
|
||||
p.from_SV_check( ST(1) );
|
||||
p.from_SV_check( ST(i) );
|
||||
THIS->points.push_back(p);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue