Further Perl eradication

This commit is contained in:
Vojtech Bubnik 2022-10-27 20:01:55 +02:00
parent 57db091612
commit 2eb0417018
17 changed files with 6 additions and 255 deletions

View File

@ -32,18 +32,12 @@ use Moo 1.003001;
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
use Slic3r::Config;
use Slic3r::ExPolygon;
use Slic3r::ExtrusionLoop;
use Slic3r::ExtrusionPath;
use Slic3r::GCode::Reader;
use Slic3r::Layer;
use Slic3r::Line;
use Slic3r::Model;
use Slic3r::Point;
use Slic3r::Polygon;
use Slic3r::Polyline;
use Slic3r::Print::Object;
use Slic3r::Surface;
our $build = eval "use Slic3r::Build; 1";
# Scaling between the float and integer coordinates.

View File

@ -1,12 +0,0 @@
package Slic3r::ExPolygon;
use strict;
use warnings;
# an ExPolygon is a polygon with holes
sub bounding_box {
my $self = shift;
return $self->contour->bounding_box;
}
1;

View File

@ -1,12 +0,0 @@
package Slic3r::ExtrusionLoop;
use strict;
use warnings;
use parent qw(Exporter);
our @EXPORT_OK = qw(EXTRL_ROLE_DEFAULT
EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER EXTRL_ROLE_SKIRT);
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
1;

View File

@ -1,13 +0,0 @@
package Slic3r::ExtrusionPath;
use strict;
use warnings;
use parent qw(Exporter);
our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_EXTERNAL_PERIMETER EXTR_ROLE_OVERHANG_PERIMETER
EXTR_ROLE_FILL EXTR_ROLE_SOLIDFILL EXTR_ROLE_TOPSOLIDFILL EXTR_ROLE_GAPFILL EXTR_ROLE_BRIDGE
EXTR_ROLE_SKIRT EXTR_ROLE_SUPPORTMATERIAL EXTR_ROLE_SUPPORTMATERIAL_INTERFACE
EXTR_ROLE_NONE);
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
1;

View File

@ -34,21 +34,4 @@ sub scaled_epsilon () { epsilon / &Slic3r::SCALING_FACTOR }
sub scale ($) { $_[0] / &Slic3r::SCALING_FACTOR }
sub unscale ($) { $_[0] * &Slic3r::SCALING_FACTOR }
# 2D
sub bounding_box {
my ($points) = @_;
my @x = map $_->x, @$points;
my @y = map $_->y, @$points; #,,
my @bb = (undef, undef, undef, undef);
for (0..$#x) {
$bb[X1] = $x[$_] if !defined $bb[X1] || $x[$_] < $bb[X1];
$bb[X2] = $x[$_] if !defined $bb[X2] || $x[$_] > $bb[X2];
$bb[Y1] = $y[$_] if !defined $bb[Y1] || $y[$_] < $bb[Y1];
$bb[Y2] = $y[$_] if !defined $bb[Y2] || $y[$_] > $bb[Y2];
}
return @bb[X1,Y1,X2,Y2];
}
1;

View File

@ -1,18 +0,0 @@
# Extends the C++ class Slic3r::Layer.
package Slic3r::Layer;
use strict;
use warnings;
# the following two were previously generated by Moo
sub print {
my $self = shift;
return $self->object->print;
}
sub config {
my $self = shift;
return $self->object->config;
}
1;

View File

@ -1,9 +0,0 @@
package Slic3r::Print::Object;
# extends c++ class Slic3r::PrintObject (Print.xsp)
use strict;
use warnings;
use List::Util qw(min max sum first);
use Slic3r::Surface ':types';
1;

View File

@ -1,15 +0,0 @@
package Slic3r::Surface;
use strict;
use warnings;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(S_TYPE_TOP S_TYPE_BOTTOM S_TYPE_BOTTOMBRIDGE S_TYPE_INTERNAL S_TYPE_INTERNALSOLID S_TYPE_INTERNALBRIDGE S_TYPE_INTERNALVOID);
our %EXPORT_TAGS = (types => \@EXPORT_OK);
sub p {
my $self = shift;
return @{$self->polygons};
}
1;

View File

@ -2,7 +2,7 @@ use Test::More;
use strict;
use warnings;
plan tests => 11;
plan tests => 10;
BEGIN {
use FindBin;
@ -57,11 +57,11 @@ my $polygons = [
#==========================================================
{
my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), [0, 1], [10, 2], [20, 2] ]);
$bb->scale(2);
is_deeply [ $bb->min_point->pp, $bb->max_point->pp ], [ [0,2], [40,4] ], 'bounding box is scaled correctly';
}
#{
# my $bb = Slic3r::Geometry::BoundingBox->new_from_points([ map Slic3r::Point->new(@$_), [0, 1], [10, 2], [20, 2] ]);
# $bb->scale(2);
# is_deeply [ $bb->min_point->pp, $bb->max_point->pp ], [ [0,2], [40,4] ], 'bounding box is scaled correctly';
#}
#==========================================================

View File

@ -43,7 +43,6 @@ set(XS_MAIN_XS ${CMAKE_CURRENT_BINARY_DIR}/main.xs)
set(XSP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/xsp)
#FIXME list the dependecies explicitely, add dependency on the typemap.
set(XS_XSP_FILES
${XSP_DIR}/BoundingBox.xsp
${XSP_DIR}/Config.xsp
${XSP_DIR}/ExPolygon.xsp
${XSP_DIR}/Geometry.xsp

View File

@ -100,7 +100,6 @@ for my $class (qw(
Slic3r::Config::Print
Slic3r::Config::Static
Slic3r::ExPolygon
Slic3r::Geometry::BoundingBox
Slic3r::Line
Slic3r::Model
Slic3r::Model::Instance
@ -115,10 +114,6 @@ for my $class (qw(
Slic3r::Polyline
Slic3r::Polyline::Collection
Slic3r::Print
Slic3r::Print::Object
Slic3r::Print::Region
Slic3r::Surface
Slic3r::Surface::Collection
Slic3r::TriangleMesh
))
{

View File

@ -1,52 +0,0 @@
%module{Slic3r::XS};
%{
#include <xsinit.h>
#include "libslic3r/BoundingBox.hpp"
#include "libslic3r/Point.hpp"
%}
%name{Slic3r::Geometry::BoundingBox} class BoundingBox {
BoundingBox();
~BoundingBox();
Clone<BoundingBox> clone()
%code{% RETVAL = THIS; %};
void merge(BoundingBox* bb) %code{% THIS->merge(*bb); %};
void merge_point(Point* point) %code{% THIS->merge(*point); %};
void scale(double factor);
void translate(double x, double y);
void offset(double delta);
bool contains_point(Point* point) %code{% RETVAL = THIS->contains(*point); %};
bool overlap(BoundingBox* bbox) %code{% RETVAL = THIS->overlap(*bbox); %};
Clone<Polygon> polygon();
Clone<Point> size();
Clone<Point> center();
bool empty() %code{% RETVAL = empty(*THIS); %};
double radius();
Clone<Point> min_point() %code{% RETVAL = THIS->min; %};
Clone<Point> max_point() %code{% RETVAL = THIS->max; %};
int x_min() %code{% RETVAL = THIS->min(0); %};
int x_max() %code{% RETVAL = THIS->max(0); %};
int y_min() %code{% RETVAL = THIS->min(1); %};
int y_max() %code{% RETVAL = THIS->max(1); %};
void set_x_min(double val) %code{% THIS->min(0) = val; %};
void set_x_max(double val) %code{% THIS->max(0) = val; %};
void set_y_min(double val) %code{% THIS->min(1) = val; %};
void set_y_max(double val) %code{% THIS->max(1) = val; %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld;%ld,%ld", THIS->min(0), THIS->min(1), THIS->max(0), THIS->max(1)); RETVAL = buf; %};
bool defined() %code{% RETVAL = THIS->defined; %};
%{
BoundingBox*
new_from_points(CLASS, points)
char* CLASS
Points points
CODE:
RETVAL = new BoundingBox(points);
OUTPUT:
RETVAL
%}
};

View File

@ -2,9 +2,7 @@
%{
#include <xsinit.h>
#include "libslic3r/BoundingBox.hpp"
#include "libslic3r/Polygon.hpp"
#include "libslic3r/BoundingBox.hpp"
%}
%name{Slic3r::Polygon} class Polygon {
@ -35,7 +33,6 @@
%code{% RETVAL = THIS->contains(*point); %};
Polygons simplify(double tolerance);
Clone<Point> centroid();
Clone<BoundingBox> bounding_box();
Clone<Point> first_intersection(Line* line)
%code{%
Point p;

View File

@ -2,7 +2,6 @@
%{
#include <xsinit.h>
#include "libslic3r/BoundingBox.hpp"
#include "libslic3r/Polyline.hpp"
%}
@ -31,7 +30,6 @@
void simplify(double tolerance);
void split_at(Point* point, Polyline* p1, Polyline* p2)
%code{% THIS->split_at(*point, p1, p2); %};
Clone<BoundingBox> bounding_box();
%{
Polyline*

View File

@ -5,25 +5,6 @@
#include "libslic3r/Print.hpp"
%}
%name{Slic3r::Print::Region} class PrintRegion {
// owned by Print, no constructor/destructor
Ref<StaticPrintConfig> config()
%code%{ RETVAL = &THIS->config(); %};
};
%name{Slic3r::Print::Object} class PrintObject {
// owned by Print, no constructor/destructor
Ref<Print> print();
Ref<ModelObject> model_object();
Ref<StaticPrintConfig> config()
%code%{ RETVAL = &THIS->config(); %};
Clone<BoundingBox> bounding_box();
void slice();
};
%name{Slic3r::Print} class Print {
Print();
~Print();
@ -34,25 +15,6 @@
%code%{ RETVAL = const_cast<GCodeConfig*>(static_cast<const GCodeConfig*>(&THIS->config())); %};
double total_used_filament()
%code%{ RETVAL = THIS->print_statistics().total_used_filament; %};
double total_extruded_volume()
%code%{ RETVAL = THIS->print_statistics().total_extruded_volume; %};
double total_weight()
%code%{ RETVAL = THIS->print_statistics().total_weight; %};
double total_cost()
%code%{ RETVAL = THIS->print_statistics().total_cost; %};
double total_wipe_tower_cost()
%code%{ RETVAL = THIS->print_statistics().total_wipe_tower_cost; %};
double total_wipe_tower_filament()
%code%{ RETVAL = THIS->print_statistics().total_wipe_tower_filament; %};
int wipe_tower_number_of_toolchanges()
%code%{ RETVAL = THIS->wipe_tower_data().number_of_toolchanges; %};
PrintObjectPtrs* objects()
%code%{ RETVAL = const_cast<PrintObjectPtrs*>(&THIS->objects_mutable()); %};
Ref<PrintObject> get_object(int idx)
%code%{ RETVAL = THIS->objects_mutable()[idx]; %};
size_t object_count()
%code%{ RETVAL = THIS->objects().size(); %};
void auto_assign_extruders(ModelObject* model_object);
std::string output_filepath(std::string path = "")

View File

@ -14,10 +14,6 @@ std::vector<unsigned int> T_STD_VECTOR_UINT
std::vector<double> T_STD_VECTOR_DOUBLE
BoundingBox* O_OBJECT_SLIC3R
Ref<BoundingBox> O_OBJECT_SLIC3R_T
Clone<BoundingBox> O_OBJECT_SLIC3R_T
DynamicPrintConfig* O_OBJECT_SLIC3R
Ref<DynamicPrintConfig> O_OBJECT_SLIC3R_T
Clone<DynamicPrintConfig> O_OBJECT_SLIC3R_T
@ -90,12 +86,6 @@ ModelInstance* O_OBJECT_SLIC3R
Ref<ModelInstance> O_OBJECT_SLIC3R_T
Clone<ModelInstance> O_OBJECT_SLIC3R_T
PrintRegion* O_OBJECT_SLIC3R
Ref<PrintRegion> O_OBJECT_SLIC3R_T
PrintObject* O_OBJECT_SLIC3R
Ref<PrintObject> O_OBJECT_SLIC3R_T
Print* O_OBJECT_SLIC3R
Ref<Print> O_OBJECT_SLIC3R_T
Clone<Print> O_OBJECT_SLIC3R_T
@ -120,8 +110,6 @@ Polygons* T_ARRAYREF_PTR
ModelObjectPtrs* T_PTR_ARRAYREF_PTR
ModelVolumePtrs* T_PTR_ARRAYREF_PTR
ModelInstancePtrs* T_PTR_ARRAYREF_PTR
PrintRegionPtrs* T_PTR_ARRAYREF_PTR
PrintObjectPtrs* T_PTR_ARRAYREF_PTR
# we return these types whenever we want the items to be returned
# by reference and not marked ::Ref because they're newly allocated

View File

@ -27,9 +27,6 @@
%typemap{Vec3d*};
%typemap{Ref<Vec3d>}{simple};
%typemap{Clone<Vec3d>}{simple};
%typemap{BoundingBox*};
%typemap{Ref<BoundingBox>}{simple};
%typemap{Clone<BoundingBox>}{simple};
%typemap{DynamicPrintConfig*};
%typemap{Ref<DynamicPrintConfig>}{simple};
%typemap{Clone<DynamicPrintConfig>}{simple};
@ -57,15 +54,6 @@
%typemap{Ref<TriangleMesh>}{simple};
%typemap{Clone<TriangleMesh>}{simple};
%typemap{PrintState*};
%typemap{Ref<PrintState>}{simple};
%typemap{PrintRegion*};
%typemap{Ref<PrintRegion>}{simple};
%typemap{PrintObject*};
%typemap{Ref<PrintObject>}{simple};
%typemap{Print*};
%typemap{Ref<Print>}{simple};
%typemap{Clone<Print>}{simple};
@ -103,31 +91,9 @@
%typemap{Ref<ModelInstancePtrs>}{simple};
%typemap{Clone<ModelInstancePtrs>}{simple};
%typemap{PrintRegionPtrs*};
%typemap{PrintObjectPtrs*};
%typemap{LayerPtrs*};
%typemap{Axis}{parsed}{
%cpp_type{Axis};
%precall_code{%
$CVar = (Axis)SvUV($PerlVar);
%};
};
%typemap{SurfaceType}{parsed}{
%cpp_type{SurfaceType};
%precall_code{%
$CVar = (SurfaceType)SvUV($PerlVar);
%};
};
%typemap{ExtrusionLoopRole}{parsed}{
%cpp_type{ExtrusionLoopRole};
%precall_code{%
$CVar = (ExtrusionLoopRole)SvUV($PerlVar);
%};
};
%typemap{ExtrusionRole}{parsed}{
%cpp_type{ExtrusionRole};
%precall_code{%
$CVar = (ExtrusionRole)SvUV($PerlVar);
%};
};