From 57db091612262949f8acab43c3e97c0a60b5e0b7 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Thu, 27 Oct 2022 19:43:56 +0200 Subject: [PATCH] Removed Surface and SurfaceCollection from Perl bindings. --- xs/CMakeLists.txt | 2 - xs/lib/Slic3r/XS.pm | 58 ------------------- xs/src/perlglue.cpp | 3 - xs/t/05_surface.t | 71 ----------------------- xs/xsp/Surface.xsp | 107 ----------------------------------- xs/xsp/SurfaceCollection.xsp | 70 ----------------------- xs/xsp/my.map | 8 --- xs/xsp/typemap.xspt | 8 --- 8 files changed, 327 deletions(-) delete mode 100644 xs/t/05_surface.t delete mode 100644 xs/xsp/Surface.xsp delete mode 100644 xs/xsp/SurfaceCollection.xsp diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index 237fb0a9a..f8e0d0fe2 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -53,8 +53,6 @@ set(XS_XSP_FILES ${XSP_DIR}/Polygon.xsp ${XSP_DIR}/Polyline.xsp ${XSP_DIR}/Print.xsp - ${XSP_DIR}/Surface.xsp - ${XSP_DIR}/SurfaceCollection.xsp ${XSP_DIR}/TriangleMesh.xsp ${XSP_DIR}/XS.xsp ) diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index de3ff0102..dee25afb8 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -48,61 +48,6 @@ use overload '@{}' => sub { $_[0]->arrayref }, 'fallback' => 1; -package Slic3r::ExtrusionPath::Collection; -use overload - '@{}' => sub { $_[0]->arrayref }, - 'fallback' => 1; - -sub new { - my ($class, @paths) = @_; - - my $self = $class->_new; - $self->append(@paths); - return $self; -} - -package Slic3r::ExtrusionLoop; -use overload - '@{}' => sub { $_[0]->arrayref }, - 'fallback' => 1; - -sub new_from_paths { - my ($class, @paths) = @_; - - my $loop = $class->new; - $loop->append($_) for @paths; - return $loop; -} - -package Slic3r::ExtrusionPath; -use overload - '@{}' => sub { $_[0]->arrayref }, - 'fallback' => 1; - -sub new { - my ($class, %args) = @_; - - return $class->_new( - $args{polyline}, # required - $args{role}, # required - $args{mm3_per_mm} // die("Missing required mm3_per_mm in ExtrusionPath constructor"), - $args{width} // -1, - $args{height} // -1, - ); -} - -sub clone { - my ($self, %args) = @_; - - return __PACKAGE__->_new( - $args{polyline} // $self->polyline, - $args{role} // $self->role, - $args{mm3_per_mm} // $self->mm3_per_mm, - $args{width} // $self->width, - $args{height} // $self->height, - ); -} - package Slic3r::Surface; sub new { @@ -155,9 +100,6 @@ for my $class (qw( Slic3r::Config::Print Slic3r::Config::Static Slic3r::ExPolygon - Slic3r::ExtrusionLoop - Slic3r::ExtrusionPath - Slic3r::ExtrusionPath::Collection Slic3r::Geometry::BoundingBox Slic3r::Line Slic3r::Model diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 62a80d018..3f75617dd 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -4,9 +4,6 @@ namespace Slic3r { REGISTER_CLASS(ExPolygon, "ExPolygon"); -REGISTER_CLASS(ExtrusionPath, "ExtrusionPath"); -REGISTER_CLASS(ExtrusionLoop, "ExtrusionLoop"); -REGISTER_CLASS(ExtrusionEntityCollection, "ExtrusionPath::Collection"); REGISTER_CLASS(GCode, "GCode"); REGISTER_CLASS(Line, "Line"); REGISTER_CLASS(Polygon, "Polygon"); diff --git a/xs/t/05_surface.t b/xs/t/05_surface.t deleted file mode 100644 index 4d9eb5b89..000000000 --- a/xs/t/05_surface.t +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use Slic3r::XS; -use Test::More tests => 11; - -my $square = [ # ccw - [100, 100], - [200, 100], - [200, 200], - [100, 200], -]; -my $hole_in_square = [ # cw - [140, 140], - [140, 160], - [160, 160], - [160, 140], -]; - -my $expolygon = Slic3r::ExPolygon->new($square, $hole_in_square); -my $surface = Slic3r::Surface->new( - expolygon => $expolygon, - surface_type => Slic3r::Surface::S_TYPE_INTERNAL, -); - -$surface = $surface->clone; - -is $surface->surface_type, Slic3r::Surface::S_TYPE_INTERNAL, 'surface_type'; -$surface->surface_type(Slic3r::Surface::S_TYPE_BOTTOM); -is $surface->surface_type, Slic3r::Surface::S_TYPE_BOTTOM, 'modify surface_type'; - -$surface->bridge_angle(30); -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; - $collection->append($_) for $surface, $surface->clone; - is scalar(@$collection), 2, 'collection has the right number of items'; - is_deeply $collection->[0]->expolygon->pp, [$square, $hole_in_square], - 'collection returns a correct surface expolygon'; - $collection->clear; - is scalar(@$collection), 0, 'clear collection'; - $collection->append($surface); - is scalar(@$collection), 1, 'append to collection'; - - my $item = $collection->[0]; - $item->surface_type(Slic3r::Surface::S_TYPE_INTERNAL); - is $item->surface_type, $collection->[0]->surface_type, 'collection returns items by reference'; -} - -{ - my $collection = Slic3r::Surface::Collection->new; - $collection->append($_) for - Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM), - Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_BOTTOM), - Slic3r::Surface->new(expolygon => $expolygon, surface_type => Slic3r::Surface::S_TYPE_TOP); - is scalar(@{$collection->group}), 2, 'group() returns correct number of groups'; -} - -__END__ diff --git a/xs/xsp/Surface.xsp b/xs/xsp/Surface.xsp deleted file mode 100644 index 3fffea9ab..000000000 --- a/xs/xsp/Surface.xsp +++ /dev/null @@ -1,107 +0,0 @@ -%module{Slic3r::XS}; - -%{ -#include -#include "libslic3r/Surface.hpp" -%} - -%name{Slic3r::Surface} class Surface { - ~Surface(); - Ref expolygon() - %code{% RETVAL = &(THIS->expolygon); %}; - double thickness() - %code{% RETVAL = THIS->thickness; %}; - unsigned short thickness_layers() - %code{% RETVAL = THIS->thickness_layers; %}; - double area(); - bool is_solid() const; - bool is_external() const; - bool is_internal() const; - bool is_bottom() const; - bool is_bridge() const; -%{ - -Surface* -_new(CLASS, expolygon, surface_type, thickness, thickness_layers, bridge_angle, extra_perimeters) - char* CLASS; - ExPolygon* expolygon; - SurfaceType surface_type; - double thickness; - unsigned short thickness_layers; - double bridge_angle; - unsigned short extra_perimeters; - CODE: - RETVAL = new Surface (surface_type, *expolygon); - RETVAL->thickness = thickness; - RETVAL->thickness_layers = thickness_layers; - RETVAL->bridge_angle = bridge_angle; - RETVAL->extra_perimeters = extra_perimeters; - // we don't delete expolygon here because it's referenced by a Perl SV - // whose DESTROY will take care of destruction - OUTPUT: - RETVAL - -SurfaceType -Surface::surface_type(...) - CODE: - if (items > 1) { - THIS->surface_type = (SurfaceType)SvUV(ST(1)); - } - RETVAL = THIS->surface_type; - OUTPUT: - RETVAL - -double -Surface::bridge_angle(...) - CODE: - if (items > 1) { - THIS->bridge_angle = (double)SvNV(ST(1)); - } - RETVAL = THIS->bridge_angle; - OUTPUT: - RETVAL - -unsigned short -Surface::extra_perimeters(...) - CODE: - if (items > 1) { - THIS->extra_perimeters = (double)SvUV(ST(1)); - } - RETVAL = THIS->extra_perimeters; - OUTPUT: - RETVAL - -Polygons -Surface::polygons() - CODE: - RETVAL.push_back(THIS->expolygon.contour); - for (Polygons::iterator it = THIS->expolygon.holes.begin(); it != THIS->expolygon.holes.end(); ++it) { - RETVAL.push_back((*it)); - } - OUTPUT: - RETVAL - -%} -}; - -%package{Slic3r::Surface}; -%{ - -IV -_constant() - ALIAS: - S_TYPE_TOP = stTop - S_TYPE_BOTTOM = stBottom - S_TYPE_BOTTOMBRIDGE = stBottomBridge - S_TYPE_INTERNAL = stInternal - S_TYPE_INTERNALSOLID = stInternalSolid - S_TYPE_INTERNALBRIDGE = stInternalBridge - S_TYPE_INTERNALVOID = stInternalVoid - S_TYPW_PERIMETER = stPerimeter - PROTOTYPE: - CODE: - RETVAL = ix; - OUTPUT: RETVAL - -%} - diff --git a/xs/xsp/SurfaceCollection.xsp b/xs/xsp/SurfaceCollection.xsp deleted file mode 100644 index 0d31c5ae3..000000000 --- a/xs/xsp/SurfaceCollection.xsp +++ /dev/null @@ -1,70 +0,0 @@ -%module{Slic3r::XS}; - -%{ -#include -#include "libslic3r/SurfaceCollection.hpp" -%} - -%name{Slic3r::Surface::Collection} class SurfaceCollection { - %name{_new} SurfaceCollection(); - ~SurfaceCollection(); - void clear() - %code{% THIS->surfaces.clear(); %}; - void append(Surface* surface) - %code{% THIS->surfaces.push_back(*surface); %}; - int count() - %code{% RETVAL = THIS->surfaces.size(); %}; - void simplify(double tolerance); -%{ - -SV* -SurfaceCollection::arrayref() - CODE: - AV* av = newAV(); - av_fill(av, THIS->surfaces.size()-1); - int i = 0; - for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) { - av_store(av, i++, perl_to_SV_ref(*it)); - } - RETVAL = newRV_noinc((SV*)av); - OUTPUT: - RETVAL - -SV* -SurfaceCollection::filter_by_type(surface_type) - SurfaceType surface_type; - CODE: - AV* av = newAV(); - for (Surfaces::iterator it = THIS->surfaces.begin(); it != THIS->surfaces.end(); ++it) { - if ((*it).surface_type == surface_type) av_push(av, perl_to_SV_ref(*it)); - } - RETVAL = newRV_noinc((SV*)av); - OUTPUT: - RETVAL - -SV* -SurfaceCollection::group() - CODE: - // perform grouping - std::vector groups; - THIS->group(&groups); - - // build return arrayref - AV* av = newAV(); - av_fill(av, groups.size()-1); - size_t i = 0; - for (std::vector::iterator it = groups.begin(); it != groups.end(); ++it) { - AV* innerav = newAV(); - av_fill(innerav, it->size()-1); - size_t j = 0; - for (SurfacesPtr::iterator it_s = it->begin(); it_s != it->end(); ++it_s) { - av_store(innerav, j++, perl_to_SV_clone_ref(**it_s)); - } - av_store(av, i++, newRV_noinc((SV*)innerav)); - } - RETVAL = newRV_noinc((SV*)av); - OUTPUT: - RETVAL - -%} -}; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index dcf20bdab..5c5d10781 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -70,13 +70,6 @@ ExPolygon* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T -Surface* O_OBJECT_SLIC3R -Ref O_OBJECT_SLIC3R_T -Clone O_OBJECT_SLIC3R_T - -SurfaceCollection* O_OBJECT_SLIC3R -Ref O_OBJECT_SLIC3R_T - Model* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T @@ -119,7 +112,6 @@ Lines T_ARRAYREF Polygons T_ARRAYREF Polylines T_ARRAYREF ExPolygons T_ARRAYREF -Surfaces T_ARRAYREF # we return these types whenever we want the items to be returned # by reference and marked ::Ref because they're contained in another diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index e5bba9812..7fc61fe3f 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -56,13 +56,6 @@ %typemap{TriangleMesh*}; %typemap{Ref}{simple}; %typemap{Clone}{simple}; -%typemap{SurfaceCollection*}; -%typemap{Ref}{simple}; -%typemap{Clone}{simple}; - -%typemap{Surface*}; -%typemap{Ref}{simple}; -%typemap{Clone}{simple}; %typemap{PrintState*}; %typemap{Ref}{simple}; @@ -83,7 +76,6 @@ %typemap{Polygons}; %typemap{Polylines}; %typemap{ExPolygons}; -%typemap{Surfaces}; %typemap{Polygons*}; %typemap{TriangleMesh*}; %typemap{Model*};