Просмотр исходного кода

Cleanup of some method signatures and of XS return types

Alessandro Ranellucci 10 лет назад
Родитель
Сommit
8791f5a493

+ 1 - 1
lib/Slic3r/GUI.pm

@@ -29,7 +29,7 @@ use Slic3r::GUI::Tab;
 
 our $have_OpenGL = eval "use Slic3r::GUI::3DScene; 1";
 our $have_LWP    = eval "use LWP::UserAgent; 1";
-
+$have_OpenGL = 0;
 use Wx 0.9901 qw(:bitmap :dialog :icon :id :misc :systemsettings :toplevelwindow
     :filedialog);
 use Wx::Event qw(EVT_IDLE);

+ 6 - 6
lib/Slic3r/GUI/Plater.pm

@@ -874,8 +874,8 @@ sub schedule_background_process {
     
     if (defined $self->{apply_config_timer}) {
         $self->{apply_config_timer}->Start(PROCESS_DELAY, 1);  # 1 = one shot
-        $self->{toolpaths2D}->reload_print;
-        $self->{preview3D}->reload_print;
+        $self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
+        $self->{preview3D}->reload_print if $self->{preview3D};
     }
 }
 
@@ -954,8 +954,8 @@ sub stop_background_process {
     $self->statusbar->SetCancelCallback(undef);
     $self->statusbar->StopBusy;
     $self->statusbar->SetStatusText("");
-    $self->{toolpaths2D}->reload_print;
-    $self->{preview3D}->reload_print;
+    $self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
+    $self->{preview3D}->reload_print if $self->{preview3D};
     
     if ($self->{process_thread}) {
         Slic3r::debugf "Killing background process.\n";
@@ -1079,8 +1079,8 @@ sub on_process_completed {
     $self->{process_thread} = undef;
     
     return if $error;
-    $self->{toolpaths2D}->reload_print;
-    $self->{preview3D}->reload_print;
+    $self->{toolpaths2D}->reload_print if $self->{toolpaths2D};
+    $self->{preview3D}->reload_print if $self->{preview3D};
     
     # if we have an export filename, start a new thread for exporting G-code
     if ($self->{export_gcode_output_file}) {

+ 1 - 2
xs/src/libslic3r/BridgeDetector.cpp

@@ -89,8 +89,7 @@ BridgeDetector::detect_angle()
     {
         Polygons pp = this->expolygon;
         for (Polygons::const_iterator p = pp.begin(); p != pp.end(); ++p) {
-            Lines lines;
-            p->lines(&lines);
+            Lines lines = p->lines();
             for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line)
                 angles.push_back(line->direction());
         }

+ 10 - 7
xs/src/libslic3r/ExPolygon.cpp

@@ -167,9 +167,11 @@ ExPolygon::medial_axis(double max_width, double min_width, Polylines* polylines)
     Slic3r::Geometry::MedialAxis ma(max_width, min_width);
     
     // populate list of segments for the Voronoi diagram
-    this->contour.lines(&ma.lines);
-    for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole)
-        hole->lines(&ma.lines);
+    ma.lines = this->contour.lines();
+    for (Polygons::const_iterator hole = this->holes.begin(); hole != this->holes.end(); ++hole) {
+        Lines lines = hole->lines();
+        ma.lines.insert(ma.lines.end(), lines.begin(), lines.end());
+    }
     
     // compute the Voronoi diagram
     ma.build(polylines);
@@ -384,10 +386,11 @@ ExPolygon::triangulate_p2t(Polygons* polygons) const
 Lines
 ExPolygon::lines() const
 {
-    Lines lines;
-    this->contour.lines(&lines);
-    for (Polygons::const_iterator h = this->holes.begin(); h != this->holes.end(); ++h)
-        h->lines(&lines);
+    Lines lines = this->contour.lines();
+    for (Polygons::const_iterator h = this->holes.begin(); h != this->holes.end(); ++h) {
+        Lines hole_lines = h->lines();
+        lines.insert(lines.end(), hole_lines.begin(), hole_lines.end());
+    }
     return lines;
 }
 

+ 3 - 3
xs/src/libslic3r/ExPolygonCollection.cpp

@@ -92,13 +92,13 @@ ExPolygonCollection::simplify(double tolerance)
     this->expolygons = expp;
 }
 
-void
-ExPolygonCollection::convex_hull(Polygon* hull) const
+Polygon
+ExPolygonCollection::convex_hull() const
 {
     Points pp;
     for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it)
         pp.insert(pp.end(), it->contour.points.begin(), it->contour.points.end());
-    Slic3r::Geometry::convex_hull(pp, hull);
+    return Slic3r::Geometry::convex_hull(pp);
 }
 
 Lines

+ 1 - 1
xs/src/libslic3r/ExPolygonCollection.hpp

@@ -28,7 +28,7 @@ class ExPolygonCollection
     template <class T> bool contains(const T &item) const;
     bool contains_b(const Point &point) const;
     void simplify(double tolerance);
-    void convex_hull(Polygon* hull) const;
+    Polygon convex_hull() const;
     Lines lines() const;
 };
 

+ 16 - 13
xs/src/libslic3r/Geometry.cpp

@@ -25,42 +25,45 @@ sort_points (Point a, Point b)
 }
 
 /* This implementation is based on Andrew's monotone chain 2D convex hull algorithm */
-void
-convex_hull(Points points, Polygon* hull)
+Polygon
+convex_hull(Points points)
 {
     assert(points.size() >= 3);
     // sort input points
     std::sort(points.begin(), points.end(), sort_points);
     
     int n = points.size(), k = 0;
-    hull->points.resize(2*n);
+    Polygon hull;
+    hull.points.resize(2*n);
 
     // Build lower hull
     for (int i = 0; i < n; i++) {
-        while (k >= 2 && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
-        hull->points[k++] = points[i];
+        while (k >= 2 && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
+        hull.points[k++] = points[i];
     }
 
     // Build upper hull
     for (int i = n-2, t = k+1; i >= 0; i--) {
-        while (k >= t && points[i].ccw(hull->points[k-2], hull->points[k-1]) <= 0) k--;
-        hull->points[k++] = points[i];
+        while (k >= t && points[i].ccw(hull.points[k-2], hull.points[k-1]) <= 0) k--;
+        hull.points[k++] = points[i];
     }
 
-    hull->points.resize(k);
+    hull.points.resize(k);
+    
+    assert( hull.points.front().coincides_with(hull.points.back()) );
+    hull.points.pop_back();
     
-    assert( hull->points.front().coincides_with(hull->points.back()) );
-    hull->points.pop_back();
+    return hull;
 }
 
-void
-convex_hull(const Polygons &polygons, Polygon* hull)
+Polygon
+convex_hull(const Polygons &polygons)
 {
     Points pp;
     for (Polygons::const_iterator p = polygons.begin(); p != polygons.end(); ++p) {
         pp.insert(pp.end(), p->points.begin(), p->points.end());
     }
-    convex_hull(pp, hull);
+    return convex_hull(pp);
 }
 
 /* accepts an arrayref of points and returns a list of indices

+ 2 - 2
xs/src/libslic3r/Geometry.hpp

@@ -11,8 +11,8 @@ using boost::polygon::voronoi_diagram;
 
 namespace Slic3r { namespace Geometry {
 
-void convex_hull(Points points, Polygon* hull);
-void convex_hull(const Polygons &polygons, Polygon* hull);
+Polygon convex_hull(Points points);
+Polygon convex_hull(const Polygons &polygons);
 void chained_path(const Points &points, std::vector<Points::size_type> &retval, Point start_near);
 void chained_path(const Points &points, std::vector<Points::size_type> &retval);
 template<class T> void chained_path_items(Points &points, T &items, T &retval);

+ 2 - 2
xs/src/libslic3r/Line.cpp

@@ -64,10 +64,10 @@ Line::length() const
     return this->a.distance_to(this->b);
 }
 
-Point*
+Point
 Line::midpoint() const
 {
-    return new Point ((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
+    return Point((this->a.x + this->b.x) / 2.0, (this->a.y + this->b.y) / 2.0);
 }
 
 void

+ 1 - 1
xs/src/libslic3r/Line.hpp

@@ -26,7 +26,7 @@ class Line
     void rotate(double angle, const Point &center);
     void reverse();
     double length() const;
-    Point* midpoint() const;
+    Point midpoint() const;
     void point_at(double distance, Point* point) const;
     Point point_at(double distance) const;
     bool intersection_infinite(const Line &other, Point* point) const;

Некоторые файлы не были показаны из-за большого количества измененных файлов