XS.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package Slic3r::XS;
  2. use warnings;
  3. use strict;
  4. our $VERSION = '0.01';
  5. use Carp qw();
  6. use XSLoader;
  7. XSLoader::load(__PACKAGE__, $VERSION);
  8. package Slic3r::Line;
  9. use overload
  10. '@{}' => sub { $_[0]->arrayref },
  11. 'fallback' => 1;
  12. package Slic3r::Point;
  13. use overload
  14. '@{}' => sub { $_[0]->arrayref },
  15. 'fallback' => 1;
  16. package Slic3r::Pointf;
  17. use overload
  18. '@{}' => sub { $_[0]->arrayref },
  19. 'fallback' => 1;
  20. package Slic3r::Pointf3;
  21. use overload
  22. '@{}' => sub { [ $_[0]->x, $_[0]->y, $_[0]->z ] }, #,
  23. 'fallback' => 1;
  24. sub pp {
  25. my ($self) = @_;
  26. return [ @$self ];
  27. }
  28. package Slic3r::ExPolygon;
  29. use overload
  30. '@{}' => sub { $_[0]->arrayref },
  31. 'fallback' => 1;
  32. package Slic3r::Polyline;
  33. use overload
  34. '@{}' => sub { $_[0]->arrayref },
  35. 'fallback' => 1;
  36. package Slic3r::Polygon;
  37. use overload
  38. '@{}' => sub { $_[0]->arrayref },
  39. 'fallback' => 1;
  40. package Slic3r::Surface;
  41. sub new {
  42. my ($class, %args) = @_;
  43. # defensive programming: make sure no negative bridge_angle is supplied
  44. die "Error: invalid negative bridge_angle\n"
  45. if defined $args{bridge_angle} && $args{bridge_angle} < 0;
  46. return $class->_new(
  47. $args{expolygon} // (die "Missing required expolygon\n"),
  48. $args{surface_type} // (die "Missing required surface_type\n"),
  49. $args{thickness} // -1,
  50. $args{thickness_layers} // 1,
  51. $args{bridge_angle} // -1,
  52. $args{extra_perimeters} // 0,
  53. );
  54. }
  55. sub clone {
  56. my ($self, %args) = @_;
  57. return (ref $self)->_new(
  58. delete $args{expolygon} // $self->expolygon,
  59. delete $args{surface_type} // $self->surface_type,
  60. delete $args{thickness} // $self->thickness,
  61. delete $args{thickness_layers} // $self->thickness_layers,
  62. delete $args{bridge_angle} // $self->bridge_angle,
  63. delete $args{extra_perimeters} // $self->extra_perimeters,
  64. );
  65. }
  66. package Slic3r::Surface::Collection;
  67. use overload
  68. '@{}' => sub { $_[0]->arrayref },
  69. 'fallback' => 1;
  70. sub new {
  71. my ($class, @surfaces) = @_;
  72. my $self = $class->_new;
  73. $self->append($_) for @surfaces;
  74. return $self;
  75. }
  76. package main;
  77. for my $class (qw(
  78. Slic3r::Config
  79. Slic3r::Config::GCode
  80. Slic3r::Config::Print
  81. Slic3r::Config::Static
  82. Slic3r::ExPolygon
  83. Slic3r::Line
  84. Slic3r::Model
  85. Slic3r::Model::Instance
  86. Slic3r::Model::Material
  87. Slic3r::Model::Object
  88. Slic3r::Model::Volume
  89. Slic3r::Point
  90. Slic3r::Point3
  91. Slic3r::Pointf
  92. Slic3r::Pointf3
  93. Slic3r::Polygon
  94. Slic3r::Polyline
  95. Slic3r::Polyline::Collection
  96. Slic3r::Print
  97. Slic3r::TriangleMesh
  98. ))
  99. {
  100. no strict 'refs';
  101. my $ref_class = $class . "::Ref";
  102. eval "package $ref_class; our \@ISA = '$class'; sub DESTROY {};";
  103. }
  104. 1;