Browse Source

Return Surface->expolygon by reference

Alessandro Ranellucci 11 years ago
parent
commit
bb45437526
3 changed files with 14 additions and 3 deletions
  1. 5 0
      xs/lib/Slic3r/XS.pm
  2. 8 2
      xs/t/05_surface.t
  3. 1 1
      xs/xsp/Surface.xsp

+ 5 - 0
xs/lib/Slic3r/XS.pm

@@ -22,6 +22,11 @@ use overload
     '@{}' => sub { $_[0]->arrayref },
     'fallback' => 1;
 
+package Slic3r::ExPolygon::Ref;
+our @ISA = 'Slic3r::ExPolygon';
+
+sub DESTROY {}
+
 package Slic3r::Polyline;
 use overload
     '@{}' => sub { $_[0]->arrayref },

+ 8 - 2
xs/t/05_surface.t

@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use Slic3r::XS;
-use Test::More tests => 12;
+use Test::More tests => 13;
 
 my $square = [  # ccw
     [100, 100],
@@ -27,7 +27,7 @@ my $surface = Slic3r::Surface->new(
 
 $surface = $surface->clone;
 
-isa_ok $surface->expolygon, 'Slic3r::ExPolygon', 'expolygon';
+isa_ok $surface->expolygon, 'Slic3r::ExPolygon::Ref', 'expolygon';
 is_deeply [ @{$surface->expolygon->pp} ], [$square, $hole_in_square], 'expolygon roundtrip';
 is scalar(@{$surface->polygons}), 2, 'polygons roundtrip';
 
@@ -41,6 +41,12 @@ is $surface->bridge_angle, 30, 'bridge_angle';
 $surface->extra_perimeters(2);
 is $surface->extra_perimeters, 2, 'extra_perimeters';
 
+{
+    my $surface2 = $surface->clone;
+    $surface2->expolygon->scale(2);
+    isnt $surface2->expolygon->area, $expolygon->area, 'expolygon is returned by reference';
+}
+
 {
     my $collection = Slic3r::Surface::Collection->new($surface, $surface->clone);
     is scalar(@$collection), 2, 'collection has the right number of items';

+ 1 - 1
xs/xsp/Surface.xsp

@@ -8,7 +8,7 @@
 %name{Slic3r::Surface} class Surface {
     ~Surface();
     ExPolygon* expolygon()
-        %code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(THIS->expolygon); %};
+        %code{% const char* CLASS = "Slic3r::ExPolygon::Ref"; RETVAL = &(THIS->expolygon); %};
     double thickness()
         %code{% RETVAL = THIS->thickness; %};
     unsigned short thickness_layers()