diff --git a/Build.PL b/Build.PL index b4bed05ce..b8921a8c0 100644 --- a/Build.PL +++ b/Build.PL @@ -26,6 +26,7 @@ my $build = Module::Build->new( 'IO::Scalar' => '0.10', }, recommends => { + 'Class::XSAccessor' => '0', 'Growl::GNTP' => '0.15', 'Net::DBus' => '0', 'XML::SAX::ExpatXS' => '0', diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 5bd91a288..0017d9257 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -991,7 +991,11 @@ END }; # generate accessors -{ +if (eval "use Class::XSAccessor; 1") { + Class::XSAccessor->import( + getters => { map { $_ => $_ } keys %$Options }, + ); +} else { no strict 'refs'; for my $opt_key (keys %$Options) { *{$opt_key} = sub { $_[0]{$opt_key} }; diff --git a/lib/Slic3r/Geometry.pm b/lib/Slic3r/Geometry.pm index 723345906..6a91a2046 100644 --- a/lib/Slic3r/Geometry.pm +++ b/lib/Slic3r/Geometry.pm @@ -229,15 +229,7 @@ sub point_is_on_left_of_segment { sub polyline_lines { my ($polygon) = @_; - - my @lines = (); - my $last_point; - foreach my $point (@$polygon) { - push @lines, Slic3r::Line->new($last_point, $point) if $last_point; - $last_point = $point; - } - - return @lines; + return map Slic3r::Line->new($polygon->[$_], $polygon->[$_+1]), 0 .. $#$polygon-1; } sub polygon_lines { diff --git a/lib/Slic3r/Surface.pm b/lib/Slic3r/Surface.pm index cb8aab313..e122358e5 100644 --- a/lib/Slic3r/Surface.pm +++ b/lib/Slic3r/Surface.pm @@ -39,6 +39,21 @@ sub depth_layers { $_[0][S_DEPTH_LAYERS] } # this integer represents the thic sub bridge_angle { $_[0][S_BRIDGE_ANGLE] = $_[1] if defined $_[1]; $_[0][S_BRIDGE_ANGLE] } sub extra_perimeters { $_[0][S_EXTRA_PERIMETERS] = $_[1] if defined $_[1]; $_[0][S_EXTRA_PERIMETERS] } +if (eval "use Class::XSAccessor::Array; 1") { + Class::XSAccessor::Array->import( + getters => { + expolygon => S_EXPOLYGON, + }, + accessors => { + surface_type => S_SURFACE_TYPE, + depth_layers => S_DEPTH_LAYERS, + bridge_angle => S_BRIDGE_ANGLE, + extra_perimeters => S_EXTRA_PERIMETERS, + }, + replace => 1, + ); +} + # delegate handles sub encloses_point { $_[0]->expolygon->encloses_point } sub lines { $_[0]->expolygon->lines } diff --git a/lib/Slic3r/TriangleMesh.pm b/lib/Slic3r/TriangleMesh.pm index 0f5df9a4e..ea9e664e5 100644 --- a/lib/Slic3r/TriangleMesh.pm +++ b/lib/Slic3r/TriangleMesh.pm @@ -163,10 +163,10 @@ sub check_manifoldness { sub unpack_line { my ($packed) = @_; - my @data = unpack I_FMT, $packed; - splice @data, 0, 2, [ @data[0,1] ]; - $data[$_] = undef for grep $data[$_] == -1, I_A_ID, I_B_ID, I_FACET_EDGE, I_PREV_FACET_INDEX, I_NEXT_FACET_INDEX; - return [@data]; + my $data = [ unpack I_FMT, $packed ]; + splice @$data, 0, 2, [ @$data[0,1] ]; + $data->[$_] = undef for grep $data->[$_] == -1, I_A_ID, I_B_ID, I_FACET_EDGE, I_PREV_FACET_INDEX, I_NEXT_FACET_INDEX; + return $data; } sub make_loops {