From 8791f5a493d476c3e42a4d5c91f5a4b182fe2b18 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 19 Jan 2015 18:53:04 +0100 Subject: [PATCH] Cleanup of some method signatures and of XS return types --- lib/Slic3r/GUI.pm | 2 +- lib/Slic3r/GUI/Plater.pm | 12 +-- xs/src/libslic3r/BridgeDetector.cpp | 3 +- xs/src/libslic3r/ExPolygon.cpp | 17 ++-- xs/src/libslic3r/ExPolygonCollection.cpp | 6 +- xs/src/libslic3r/ExPolygonCollection.hpp | 2 +- xs/src/libslic3r/Geometry.cpp | 29 +++--- xs/src/libslic3r/Geometry.hpp | 4 +- xs/src/libslic3r/Line.cpp | 4 +- xs/src/libslic3r/Line.hpp | 2 +- xs/src/libslic3r/Model.cpp | 98 +++++++++----------- xs/src/libslic3r/Model.hpp | 16 ++-- xs/src/libslic3r/MotionPlanner.cpp | 49 +++++----- xs/src/libslic3r/MotionPlanner.hpp | 4 +- xs/src/libslic3r/MultiPoint.cpp | 6 +- xs/src/libslic3r/MultiPoint.hpp | 2 +- xs/src/libslic3r/Polygon.cpp | 109 ++++++++++------------- xs/src/libslic3r/Polygon.hpp | 15 ++-- xs/src/libslic3r/Polyline.cpp | 12 +-- xs/src/libslic3r/Polyline.hpp | 2 +- xs/src/libslic3r/Print.cpp | 8 +- xs/src/libslic3r/Print.hpp | 2 +- xs/src/libslic3r/PrintObject.cpp | 6 +- xs/src/libslic3r/TriangleMesh.cpp | 30 +++---- xs/src/libslic3r/TriangleMesh.hpp | 5 +- xs/xsp/BoundingBox.xsp | 3 +- xs/xsp/ExPolygonCollection.xsp | 9 +- xs/xsp/ExtrusionLoop.xsp | 4 +- xs/xsp/Geometry.xsp | 5 +- xs/xsp/Layer.xsp | 4 +- xs/xsp/Line.xsp | 6 +- xs/xsp/Model.xsp | 36 ++------ xs/xsp/MotionPlanner.xsp | 4 +- xs/xsp/Point.xsp | 4 +- xs/xsp/Polygon.xsp | 25 ++---- xs/xsp/Polyline.xsp | 9 +- xs/xsp/Print.xsp | 10 +-- xs/xsp/TriangleMesh.xsp | 26 ++---- xs/xsp/my.map | 1 - 39 files changed, 252 insertions(+), 339 deletions(-) diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 52b28cd26..13e338ec0 100644 --- a/lib/Slic3r/GUI.pm +++ b/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); diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 1a53c72a8..b4063c8a8 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/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}) { diff --git a/xs/src/libslic3r/BridgeDetector.cpp b/xs/src/libslic3r/BridgeDetector.cpp index 5eeca86a5..dfc145422 100644 --- a/xs/src/libslic3r/BridgeDetector.cpp +++ b/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()); } diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index 2c5246aad..9a4215864 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/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; } diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index aaa747d8d..3b47c29b3 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/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 diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index cca6064d5..86f77cbcb 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -28,7 +28,7 @@ class ExPolygonCollection template 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; }; diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index e30e73702..8169da5a3 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/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 diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index e7f2f08f3..a402e0251 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/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 &retval, Point start_near); void chained_path(const Points &points, std::vector &retval); template void chained_path_items(Points &points, T &items, T &retval); diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index 15771ea7c..84ba10a5b 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/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 diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index a7e5d26ff..327ff4d1e 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -26,7 +26,7 @@ class Line void rotate(double angle, const Point ¢er); 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; diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 224ad67a7..d03a2916c 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -130,8 +130,7 @@ Model::duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance) ModelObject* object = this->objects.front(); object->clear_instances(); - BoundingBoxf3 bb; - object->bounding_box(&bb); + BoundingBoxf3 bb = object->bounding_box(); Sizef3 size = bb.size(); for (unsigned int x_copy = 1; x_copy <= x; ++x_copy) { @@ -174,21 +173,20 @@ Model::add_default_instances() } // this returns the bounding box of the *transformed* instances -void -Model::bounding_box(BoundingBoxf3* bb) +BoundingBoxf3 +Model::bounding_box() const { + BoundingBoxf3 bb; for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) { - BoundingBoxf3 obb; - (*o)->bounding_box(&obb); - bb->merge(obb); + bb.merge((*o)->bounding_box()); } + return bb; } void Model::center_instances_around_point(const Pointf &point) { - BoundingBoxf3 bb; - this->bounding_box(&bb); + BoundingBoxf3 bb = this->bounding_box(); Sizef3 size = bb.size(); double shift_x = -bb.min.x + point.x - size.x/2; @@ -205,8 +203,7 @@ Model::center_instances_around_point(const Pointf &point) void Model::align_instances_to_origin() { - BoundingBoxf3 bb; - this->bounding_box(&bb); + BoundingBoxf3 bb = this->bounding_box(); Pointf new_center = (Pointf)bb.size(); new_center.translate(-new_center.x/2, -new_center.y/2); @@ -222,25 +219,25 @@ Model::translate(coordf_t x, coordf_t y, coordf_t z) } // flattens everything to a single mesh -void -Model::mesh(TriangleMesh* mesh) const +TriangleMesh +Model::mesh() const { + TriangleMesh mesh; for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) { - TriangleMesh omesh; - (*o)->mesh(&omesh); - mesh->merge(omesh); + mesh.merge((*o)->mesh()); } + return mesh; } // flattens everything to a single mesh -void -Model::raw_mesh(TriangleMesh* mesh) const +TriangleMesh +Model::raw_mesh() const { + TriangleMesh mesh; for (ModelObjectPtrs::const_iterator o = this->objects.begin(); o != this->objects.end(); ++o) { - TriangleMesh omesh; - (*o)->raw_mesh(&omesh); - mesh->merge(omesh); + mesh.merge((*o)->raw_mesh()); } + return mesh; } #ifdef SLIC3RXS @@ -393,11 +390,11 @@ ModelObject::clear_instances() } // this returns the bounding box of the *transformed* instances -void -ModelObject::bounding_box(BoundingBoxf3* bb) +BoundingBoxf3 +ModelObject::bounding_box() { if (!this->_bounding_box_valid) this->update_bounding_box(); - *bb = this->_bounding_box; + return this->_bounding_box; } void @@ -409,40 +406,40 @@ ModelObject::invalidate_bounding_box() void ModelObject::update_bounding_box() { - TriangleMesh mesh; - this->mesh(&mesh); - - mesh.bounding_box(&this->_bounding_box); + this->_bounding_box = this->mesh().bounding_box(); this->_bounding_box_valid = true; } // flattens all volumes and instances into a single mesh -void -ModelObject::mesh(TriangleMesh* mesh) const +TriangleMesh +ModelObject::mesh() const { - TriangleMesh raw_mesh; - this->raw_mesh(&raw_mesh); - + TriangleMesh mesh; + TriangleMesh raw_mesh = this->raw_mesh(); for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i) { TriangleMesh m = raw_mesh; (*i)->transform_mesh(&m); - mesh->merge(m); + mesh.merge(m); } + return mesh; } -void -ModelObject::raw_mesh(TriangleMesh* mesh) const +TriangleMesh +ModelObject::raw_mesh() const { + TriangleMesh mesh; for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { if ((*v)->modifier) continue; - mesh->merge((*v)->mesh); + mesh.merge((*v)->mesh); } + return mesh; } -void -ModelObject::raw_bounding_box(BoundingBoxf3* bb) const +BoundingBoxf3 +ModelObject::raw_bounding_box() const { + BoundingBoxf3 bb; for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { if ((*v)->modifier) continue; TriangleMesh mesh = (*v)->mesh; @@ -450,22 +447,18 @@ ModelObject::raw_bounding_box(BoundingBoxf3* bb) const if (this->instances.empty()) CONFESS("Can't call raw_bounding_box() with no instances"); this->instances.front()->transform_mesh(&mesh, true); - BoundingBoxf3 mbb; - mesh.bounding_box(&mbb); - bb->merge(mbb); + bb.merge(mesh.bounding_box()); } + return bb; } // this returns the bounding box of the *transformed* given instance -void -ModelObject::instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const +BoundingBoxf3 +ModelObject::instance_bounding_box(size_t instance_idx) const { - TriangleMesh mesh; - this->raw_mesh(&mesh); - + TriangleMesh mesh = this->raw_mesh(); this->instances[instance_idx]->transform_mesh(&mesh); - - mesh.bounding_box(bb); + return mesh.bounding_box(); } void @@ -473,12 +466,7 @@ ModelObject::center_around_origin() { // calculate the displacements needed to // center this object around the origin - BoundingBoxf3 bb; - { - TriangleMesh mesh; - this->raw_mesh(&mesh); - mesh.bounding_box(&bb); - } + BoundingBoxf3 bb = this->raw_mesh().bounding_box(); // first align to origin on XYZ Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z); diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index 56700d7a3..2ec7c5b08 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -54,12 +54,12 @@ class Model // void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb); bool has_objects_with_no_instances() const; bool add_default_instances(); - void bounding_box(BoundingBoxf3* bb); + BoundingBoxf3 bounding_box() const; void center_instances_around_point(const Pointf &point); void align_instances_to_origin(); void translate(coordf_t x, coordf_t y, coordf_t z); - void mesh(TriangleMesh* mesh) const; - void raw_mesh(TriangleMesh* mesh) const; + TriangleMesh mesh() const; + TriangleMesh raw_mesh() const; // std::string get_material_name(t_model_material_id material_id); @@ -118,13 +118,13 @@ class ModelObject void delete_last_instance(); void clear_instances(); - void bounding_box(BoundingBoxf3* bb); + BoundingBoxf3 bounding_box(); void invalidate_bounding_box(); - void mesh(TriangleMesh* mesh) const; - void raw_mesh(TriangleMesh* mesh) const; - void raw_bounding_box(BoundingBoxf3* bb) const; - void instance_bounding_box(size_t instance_idx, BoundingBoxf3* bb) const; + TriangleMesh mesh() const; + TriangleMesh raw_mesh() const; + BoundingBoxf3 raw_bounding_box() const; + BoundingBoxf3 instance_bounding_box(size_t instance_idx) const; void center_around_origin(); void translate(const Vectorf3 &vector); void translate(coordf_t x, coordf_t y, coordf_t z); diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index 47e058497..124f96891 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -82,17 +82,18 @@ MotionPlanner::get_env(size_t island_idx) const } } -void -MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyline) +Polyline +MotionPlanner::shortest_path(const Point &from, const Point &to) { // lazy generation of configuration space if (!this->initialized) this->initialize(); // if we have an empty configuration space, return a straight move if (this->islands.empty()) { - polyline->points.push_back(from); - polyline->points.push_back(to); - return; + Polyline p; + p.points.push_back(from); + p.points.push_back(to); + return p; } // Are both points in the same island? @@ -102,9 +103,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl // since both points are in the same island, is a direct move possible? // if so, we avoid generating the visibility environment if (island->contains(Line(from, to))) { - polyline->points.push_back(from); - polyline->points.push_back(to); - return; + Polyline p; + p.points.push_back(from); + p.points.push_back(to); + return p; } island_idx = island - this->islands.begin(); break; @@ -116,9 +118,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl if (env.expolygons.empty()) { // if this environment is empty (probably because it's too small), perform straight move // and avoid running the algorithms on empty dataset - polyline->points.push_back(from); - polyline->points.push_back(to); - return; // bye bye + Polyline p; + p.points.push_back(from); + p.points.push_back(to); + return p; // bye bye } // Now check whether points are inside the environment. @@ -137,10 +140,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl // perform actual path search MotionPlannerGraph* graph = this->init_graph(island_idx); - graph->shortest_path(graph->find_node(inner_from), graph->find_node(inner_to), polyline); + Polyline polyline = graph->shortest_path(graph->find_node(inner_from), graph->find_node(inner_to)); - polyline->points.insert(polyline->points.begin(), from); - polyline->points.push_back(to); + polyline.points.insert(polyline.points.begin(), from); + polyline.points.push_back(to); { // grow our environment slightly in order for simplify_by_visibility() @@ -149,7 +152,7 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl offset(env, &grown_env.expolygons, +SCALED_EPSILON); // remove unnecessary vertices - polyline->simplify_by_visibility(grown_env); + polyline.simplify_by_visibility(grown_env); } /* @@ -171,6 +174,8 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl svg.draw(*polyline, "red"); svg.Close(); */ + + return polyline; } Point @@ -310,11 +315,11 @@ MotionPlannerGraph::find_node(const Point &point) const return point.nearest_point_index(this->nodes); } -void -MotionPlannerGraph::shortest_path(size_t from, size_t to, Polyline* polyline) +Polyline +MotionPlannerGraph::shortest_path(size_t from, size_t to) { // this prevents a crash in case for some reason we got here with an empty adjacency list - if (this->adjacency_list.empty()) return; + if (this->adjacency_list.empty()) return Polyline(); const weight_t max_weight = std::numeric_limits::infinity(); @@ -379,10 +384,12 @@ MotionPlannerGraph::shortest_path(size_t from, size_t to, Polyline* polyline) } } + Polyline polyline; for (node_t vertex = to; vertex != -1; vertex = previous[vertex]) - polyline->points.push_back(this->nodes[vertex]); - polyline->points.push_back(this->nodes[from]); - polyline->reverse(); + polyline.points.push_back(this->nodes[vertex]); + polyline.points.push_back(this->nodes[from]); + polyline.reverse(); + return polyline; } #ifdef SLIC3RXS diff --git a/xs/src/libslic3r/MotionPlanner.hpp b/xs/src/libslic3r/MotionPlanner.hpp index c1617e184..608f01681 100644 --- a/xs/src/libslic3r/MotionPlanner.hpp +++ b/xs/src/libslic3r/MotionPlanner.hpp @@ -21,7 +21,7 @@ class MotionPlanner public: MotionPlanner(const ExPolygons &islands); ~MotionPlanner(); - void shortest_path(const Point &from, const Point &to, Polyline* polyline); + Polyline shortest_path(const Point &from, const Point &to); size_t islands_count() const; private: @@ -58,7 +58,7 @@ class MotionPlannerGraph //std::map, double> edges; void add_edge(size_t from, size_t to, double weight); size_t find_node(const Point &point) const; - void shortest_path(size_t from, size_t to, Polyline* polyline); + Polyline shortest_path(size_t from, size_t to); }; } diff --git a/xs/src/libslic3r/MultiPoint.cpp b/xs/src/libslic3r/MultiPoint.cpp index 6ed430cf7..61c84a802 100644 --- a/xs/src/libslic3r/MultiPoint.cpp +++ b/xs/src/libslic3r/MultiPoint.cpp @@ -83,10 +83,10 @@ MultiPoint::has_boundary_point(const Point &point) const return dist < SCALED_EPSILON; } -void -MultiPoint::bounding_box(BoundingBox* bb) const +BoundingBox +MultiPoint::bounding_box() const { - *bb = BoundingBox(this->points); + return BoundingBox(this->points); } Points diff --git a/xs/src/libslic3r/MultiPoint.hpp b/xs/src/libslic3r/MultiPoint.hpp index 96c2876f5..e87c5166e 100644 --- a/xs/src/libslic3r/MultiPoint.hpp +++ b/xs/src/libslic3r/MultiPoint.hpp @@ -31,7 +31,7 @@ class MultiPoint bool is_valid() const; int find_point(const Point &point) const; bool has_boundary_point(const Point &point) const; - void bounding_box(BoundingBox* bb) const; + BoundingBox bounding_box() const; static Points _douglas_peucker(const Points &points, const double tolerance); diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index 4c73de092..80287e663 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -14,9 +14,7 @@ Polygon::operator Polygons() const Polygon::operator Polyline() const { - Polyline polyline; - this->split_at_first_point(&polyline); - return polyline; + return this->split_at_first_point(); } Point& @@ -41,55 +39,49 @@ Lines Polygon::lines() const { Lines lines; - this->lines(&lines); + lines.reserve(this->points.size()); + for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) { + lines.push_back(Line(*it, *(it + 1))); + } + lines.push_back(Line(this->points.back(), this->points.front())); return lines; } -void -Polygon::lines(Lines* lines) const -{ - lines->reserve(lines->size() + this->points.size()); - for (Points::const_iterator it = this->points.begin(); it != this->points.end()-1; ++it) { - lines->push_back(Line(*it, *(it + 1))); - } - lines->push_back(Line(this->points.back(), this->points.front())); -} - -void -Polygon::split_at_vertex(const Point &point, Polyline* polyline) const +Polyline +Polygon::split_at_vertex(const Point &point) const { // find index of point for (Points::const_iterator it = this->points.begin(); it != this->points.end(); ++it) { if (it->coincides_with(point)) { - this->split_at_index(it - this->points.begin(), polyline); - return; + return this->split_at_index(it - this->points.begin()); } } CONFESS("Point not found"); + return Polyline(); } -void -Polygon::split_at_index(int index, Polyline* polyline) const -{ - polyline->points.reserve(this->points.size() + 1); - for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it) - polyline->points.push_back(*it); - for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it) - polyline->points.push_back(*it); -} - -void -Polygon::split_at_first_point(Polyline* polyline) const -{ - this->split_at_index(0, polyline); -} - -void -Polygon::equally_spaced_points(double distance, Points* points) const +Polyline +Polygon::split_at_index(int index) const { Polyline polyline; - this->split_at_first_point(&polyline); - polyline.equally_spaced_points(distance, points); + polyline.points.reserve(this->points.size() + 1); + for (Points::const_iterator it = this->points.begin() + index; it != this->points.end(); ++it) + polyline.points.push_back(*it); + for (Points::const_iterator it = this->points.begin(); it != this->points.begin() + index + 1; ++it) + polyline.points.push_back(*it); + return polyline; +} + +Polyline +Polygon::split_at_first_point() const +{ + return this->split_at_index(0); +} + +Points +Polygon::equally_spaced_points(double distance) const +{ + return this->split_at_first_point().equally_spaced_points(distance); } double @@ -203,8 +195,7 @@ Polygon::centroid() const double x_temp = 0; double y_temp = 0; - Polyline polyline; - this->split_at_first_point(&polyline); + Polyline polyline = this->split_at_first_point(); for (Points::const_iterator point = polyline.points.begin(); point != polyline.points.end() - 1; ++point) { x_temp += (double)( point->x + (point+1)->x ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y ); y_temp += (double)( point->y + (point+1)->y ) * ( (double)point->x*(point+1)->y - (double)(point+1)->x*point->y ); @@ -227,55 +218,49 @@ Polygon::wkt() const } // find all concave vertices (i.e. having an internal angle greater than the supplied angle) */ -void -Polygon::concave_points(double angle, Points* points) const +Points +Polygon::concave_points(double angle) const { + Points points; angle = 2*PI - angle; // check whether first point forms a concave angle if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) <= angle) - points->push_back(this->points.front()); + points.push_back(this->points.front()); // check whether points 1..(n-1) form concave angles for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) { - if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points->push_back(*p); + if (p->ccw_angle(*(p-1), *(p+1)) <= angle) points.push_back(*p); } // check whether last point forms a concave angle if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) <= angle) - points->push_back(this->points.back()); -} - -void -Polygon::concave_points(Points* points) const -{ - this->concave_points(PI, points); + points.push_back(this->points.back()); + + return points; } // find all convex vertices (i.e. having an internal angle smaller than the supplied angle) */ -void -Polygon::convex_points(double angle, Points* points) const +Points +Polygon::convex_points(double angle) const { + Points points; angle = 2*PI - angle; // check whether first point forms a convex angle if (this->points.front().ccw_angle(this->points.back(), *(this->points.begin()+1)) >= angle) - points->push_back(this->points.front()); + points.push_back(this->points.front()); // check whether points 1..(n-1) form convex angles for (Points::const_iterator p = this->points.begin()+1; p != this->points.end()-1; ++p) { - if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points->push_back(*p); + if (p->ccw_angle(*(p-1), *(p+1)) >= angle) points.push_back(*p); } // check whether last point forms a convex angle if (this->points.back().ccw_angle(*(this->points.end()-2), this->points.front()) >= angle) - points->push_back(this->points.back()); -} - -void -Polygon::convex_points(Points* points) const -{ - this->convex_points(PI, points); + points.push_back(this->points.back()); + + return points; } #ifdef SLIC3RXS diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index 778825f3e..bed80e177 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -24,11 +24,10 @@ class Polygon : public MultiPoint { explicit Polygon(const Points &points): MultiPoint(points) {}; Point last_point() const; Lines lines() const; - void lines(Lines* lines) const; - void split_at_vertex(const Point &point, Polyline* polyline) const; - void split_at_index(int index, Polyline* polyline) const; - void split_at_first_point(Polyline* polyline) const; - void equally_spaced_points(double distance, Points* points) const; + Polyline split_at_vertex(const Point &point) const; + Polyline split_at_index(int index) const; + Polyline split_at_first_point() const; + Points equally_spaced_points(double distance) const; double area() const; bool is_counter_clockwise() const; bool is_clockwise() const; @@ -41,10 +40,8 @@ class Polygon : public MultiPoint { void triangulate_convex(Polygons* polygons) const; Point centroid() const; std::string wkt() const; - void concave_points(double angle, Points* points) const; - void concave_points(Points* points) const; - void convex_points(double angle, Points* points) const; - void convex_points(Points* points) const; + Points concave_points(double angle = PI) const; + Points convex_points(double angle = PI) const; #ifdef SLIC3RXS void from_SV_check(SV* poly_sv); diff --git a/xs/src/libslic3r/Polyline.cpp b/xs/src/libslic3r/Polyline.cpp index f56dd03b9..710ca9bd1 100644 --- a/xs/src/libslic3r/Polyline.cpp +++ b/xs/src/libslic3r/Polyline.cpp @@ -98,10 +98,11 @@ Polyline::extend_start(double distance) /* this method returns a collection of points picked on the polygon contour so that they are evenly spaced according to the input distance */ -void -Polyline::equally_spaced_points(double distance, Points* points) const +Points +Polyline::equally_spaced_points(double distance) const { - points->push_back(this->first_point()); + Points points; + points.push_back(this->first_point()); double len = 0; for (Points::const_iterator it = this->points.begin() + 1; it != this->points.end(); ++it) { @@ -110,17 +111,18 @@ Polyline::equally_spaced_points(double distance, Points* points) const if (len < distance) continue; if (len == distance) { - points->push_back(*it); + points.push_back(*it); len = 0; continue; } double take = segment_length - (len - distance); // how much we take of this segment Line segment(*(it-1), *it); - points->push_back(segment.point_at(take)); + points.push_back(segment.point_at(take)); it--; len = -take; } + return points; } void diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index 3fe89f26e..cf91b7184 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -22,7 +22,7 @@ class Polyline : public MultiPoint { void clip_start(double distance); void extend_end(double distance); void extend_start(double distance); - void equally_spaced_points(double distance, Points* points) const; + Points equally_spaced_points(double distance) const; void simplify(double tolerance); template void simplify_by_visibility(const T &area); void split_at(const Point &point, Polyline* p1, Polyline* p2) const; diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 47faf2a13..1944f22d3 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -358,8 +358,7 @@ Print::add_model_object(ModelObject* model_object, int idx) // initialize print object and store it at the given position PrintObject* o; { - BoundingBoxf3 bb; - model_object->raw_bounding_box(&bb); + BoundingBoxf3 bb = model_object->raw_bounding_box(); if (idx != -1) { // replacing existing object PrintObjectPtrs::iterator old_it = this->objects.begin() + idx; @@ -569,14 +568,13 @@ Print::validate() const Polygons mesh_convex_hulls; for (size_t i = 0; i < this->regions.size(); ++i) { for (std::vector::const_iterator it = object->region_volumes[i].begin(); it != object->region_volumes[i].end(); ++it) { - Polygon hull; - object->model_object()->volumes[*it]->mesh.convex_hull(&hull); + Polygon hull = object->model_object()->volumes[*it]->mesh.convex_hull(); mesh_convex_hulls.push_back(hull); } } // make a single convex hull for all of them - Slic3r::Geometry::convex_hull(mesh_convex_hulls, &convex_hull); + convex_hull = Slic3r::Geometry::convex_hull(mesh_convex_hulls); } // apply the same transformations we apply to the actual meshes when slicing them diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index aa67e1c6d..2e557dcc0 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -111,7 +111,7 @@ class PrintObject bool delete_all_copies(); bool set_copies(const Points &points); bool reload_model_instances(); - void bounding_box(BoundingBox* bb) const; + BoundingBox bounding_box() const; // adds region_id, too, if necessary void add_region_volume(int region_id, int volume_id); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 1d33fbc00..c37c4437d 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -110,14 +110,14 @@ PrintObject::reload_model_instances() return this->set_copies(copies); } -void -PrintObject::bounding_box(BoundingBox* bb) const +BoundingBox +PrintObject::bounding_box() const { // since the object is aligned to origin, bounding box coincides with size Points pp; pp.push_back(Point(0,0)); pp.push_back(this->size); - *bb = BoundingBox(pp); + return BoundingBox(pp); } void diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 7c2a0a344..4e620a7f7 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -319,8 +319,8 @@ TriangleMesh::merge(const TriangleMesh &mesh) } /* this will return scaled ExPolygons */ -void -TriangleMesh::horizontal_projection(ExPolygons &retval) const +ExPolygons +TriangleMesh::horizontal_projection() const { Polygons pp; pp.reserve(this->stl.stats.number_of_facets); @@ -337,11 +337,13 @@ TriangleMesh::horizontal_projection(ExPolygons &retval) const // the offset factor was tuned using groovemount.stl offset(pp, &pp, 0.01 / SCALING_FACTOR); + ExPolygons retval; union_(pp, &retval, true); + return retval; } -void -TriangleMesh::convex_hull(Polygon* hull) +Polygon +TriangleMesh::convex_hull() { this->require_shared_vertices(); Points pp; @@ -350,25 +352,19 @@ TriangleMesh::convex_hull(Polygon* hull) stl_vertex* v = &this->stl.v_shared[i]; pp.push_back(Point(v->x / SCALING_FACTOR, v->y / SCALING_FACTOR)); } - Slic3r::Geometry::convex_hull(pp, hull); -} - -void -TriangleMesh::bounding_box(BoundingBoxf3* bb) const -{ - bb->min.x = this->stl.stats.min.x; - bb->min.y = this->stl.stats.min.y; - bb->min.z = this->stl.stats.min.z; - bb->max.x = this->stl.stats.max.x; - bb->max.y = this->stl.stats.max.y; - bb->max.z = this->stl.stats.max.z; + return Slic3r::Geometry::convex_hull(pp); } BoundingBoxf3 TriangleMesh::bounding_box() const { BoundingBoxf3 bb; - this->bounding_box(&bb); + bb.min.x = this->stl.stats.min.x; + bb.min.y = this->stl.stats.min.y; + bb.min.z = this->stl.stats.min.z; + bb.max.x = this->stl.stats.max.x; + bb.max.y = this->stl.stats.max.y; + bb.max.z = this->stl.stats.max.z; return bb; } diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 227bceae0..43ac68419 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -42,9 +42,8 @@ class TriangleMesh void rotate(double angle, Point* center); TriangleMeshPtrs split() const; void merge(const TriangleMesh &mesh); - void horizontal_projection(ExPolygons &retval) const; - void convex_hull(Polygon* hull); - void bounding_box(BoundingBoxf3* bb) const; + ExPolygons horizontal_projection() const; + Polygon convex_hull(); BoundingBoxf3 bounding_box() const; void reset_repair_stats(); bool needed_repair() const; diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index ec4543681..22eb0ea7d 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -16,8 +16,7 @@ void scale(double factor); void translate(double x, double y); void offset(double delta); - Polygon* polygon() - %code{% RETVAL = new Polygon(); THIS->polygon(RETVAL); %}; + Clone polygon(); Clone size(); Clone center(); Clone min_point() %code{% RETVAL = THIS->min; %}; diff --git a/xs/xsp/ExPolygonCollection.xsp b/xs/xsp/ExPolygonCollection.xsp index 4ae1a9156..99ef69608 100644 --- a/xs/xsp/ExPolygonCollection.xsp +++ b/xs/xsp/ExPolygonCollection.xsp @@ -26,6 +26,7 @@ void simplify(double tolerance); Polygons polygons() %code{% RETVAL = *THIS; %}; + Clone convex_hull(); %{ ExPolygonCollection* @@ -76,13 +77,5 @@ ExPolygonCollection::append(...) THIS->expolygons.push_back(expolygon); } -Polygon* -ExPolygonCollection::convex_hull() - CODE: - RETVAL = new Polygon (); - THIS->convex_hull(RETVAL); - OUTPUT: - RETVAL - %} }; diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index 9319fc24b..a0f8de27c 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -15,8 +15,8 @@ bool make_counter_clockwise(); Clone first_point(); Clone last_point(); - Polygon* polygon() - %code{% RETVAL = new Polygon (*THIS); %}; + Clone polygon() + %code{% RETVAL = Polygon(*THIS); %}; void append(ExtrusionPath* path) %code{% THIS->paths.push_back(*path); %}; double length(); diff --git a/xs/xsp/Geometry.xsp b/xs/xsp/Geometry.xsp index 8a587415c..5a3be4c9e 100644 --- a/xs/xsp/Geometry.xsp +++ b/xs/xsp/Geometry.xsp @@ -29,12 +29,11 @@ directions_parallel_within(angle1, angle2, max_diff) OUTPUT: RETVAL -Polygon* +Clone convex_hull(points) Points points CODE: - RETVAL = new Polygon (); - Slic3r::Geometry::convex_hull(points, RETVAL); + RETVAL = Slic3r::Geometry::convex_hull(points); OUTPUT: RETVAL diff --git a/xs/xsp/Layer.xsp b/xs/xsp/Layer.xsp index 02ac5fc2b..a48f8d156 100644 --- a/xs/xsp/Layer.xsp +++ b/xs/xsp/Layer.xsp @@ -26,8 +26,8 @@ Ref fills() %code%{ RETVAL = &THIS->fills; %}; - Flow* flow(FlowRole role, bool bridge = false, double width = -1) - %code%{ RETVAL = new Flow(THIS->flow(role, bridge, width)); %}; + Clone flow(FlowRole role, bool bridge = false, double width = -1) + %code%{ RETVAL = THIS->flow(role, bridge, width); %}; void merge_slices(); }; diff --git a/xs/xsp/Line.xsp b/xs/xsp/Line.xsp index e5bc63c28..7ee644494 100644 --- a/xs/xsp/Line.xsp +++ b/xs/xsp/Line.xsp @@ -28,7 +28,7 @@ bool parallel_to(double angle); bool parallel_to_line(Line* line) %code{% RETVAL = THIS->parallel_to(*line); %}; - Point* midpoint(); + Clone midpoint(); Clone point_at(double distance); Clone intersection_infinite(Line* other) %code{% @@ -37,8 +37,8 @@ if (!res) CONFESS("Intersection failed"); RETVAL = p; %}; - Polyline* as_polyline() - %code{% RETVAL = new Polyline(*THIS); %}; + Clone as_polyline() + %code{% RETVAL = Polyline(*THIS); %}; Clone normal(); Clone vector(); %{ diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 2252d357d..9870d7dd5 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -59,19 +59,13 @@ // void duplicate(size_t copies_num, coordf_t distance, const BoundingBox &bb); bool has_objects_with_no_instances(); bool add_default_instances(); - BoundingBoxf3* bounding_box() - %code%{ - RETVAL = new BoundingBoxf3(); - THIS->bounding_box(RETVAL); - %}; + Clone bounding_box(); void center_instances_around_point(Pointf* point) %code%{ THIS->center_instances_around_point(*point); %}; void align_instances_to_origin(); void translate(double x, double y, double z); - TriangleMesh* mesh() - %code%{ RETVAL = new TriangleMesh(); THIS->mesh(RETVAL); %}; - TriangleMesh* raw_mesh() - %code%{ RETVAL = new TriangleMesh(); THIS->raw_mesh(RETVAL); %}; + Clone mesh(); + Clone raw_mesh(); // void split_meshes(); // std::string get_material_name(t_model_material_id material_id); @@ -119,20 +113,10 @@ ModelMaterial::attributes() void invalidate_bounding_box(); void update_bounding_box(); - TriangleMesh* mesh() - %code%{ RETVAL = new TriangleMesh(); THIS->mesh(RETVAL); %}; - TriangleMesh* raw_mesh() - %code%{ RETVAL = new TriangleMesh(); THIS->raw_mesh(RETVAL); %}; - BoundingBoxf3* raw_bounding_box() - %code%{ - RETVAL = new BoundingBoxf3(); - THIS->raw_bounding_box(RETVAL); - %}; - BoundingBoxf3* instance_bounding_box(int idx) - %code%{ - RETVAL = new BoundingBoxf3(); - THIS->instance_bounding_box(idx, RETVAL); - %}; + Clone mesh(); + Clone raw_mesh(); + Clone raw_bounding_box(); + Clone instance_bounding_box(int idx); Ref _bounding_box(BoundingBoxf3* new_bbox = NULL) %code{% @@ -147,11 +131,7 @@ ModelMaterial::attributes() RETVAL = &THIS->_bounding_box; %}; - BoundingBoxf3* bounding_box() - %code%{ - RETVAL = new BoundingBoxf3(); - THIS->bounding_box(RETVAL); - %}; + Clone bounding_box(); %name{_add_volume} Ref add_volume(TriangleMesh* mesh) %code%{ RETVAL = THIS->add_volume(*mesh); %}; diff --git a/xs/xsp/MotionPlanner.xsp b/xs/xsp/MotionPlanner.xsp index fc4bae715..896923307 100644 --- a/xs/xsp/MotionPlanner.xsp +++ b/xs/xsp/MotionPlanner.xsp @@ -10,6 +10,6 @@ ~MotionPlanner(); int islands_count(); - Polyline* shortest_path(Point* from, Point* to) - %code%{ RETVAL = new Polyline(); THIS->shortest_path(*from, *to, RETVAL); %}; + Clone shortest_path(Point* from, Point* to) + %code%{ RETVAL = THIS->shortest_path(*from, *to); %}; }; diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 8386b146b..34017a3b4 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -27,8 +27,8 @@ void set_y(long val) %code{% THIS->y = val; %}; int nearest_point_index(Points points); - Point* nearest_point(Points points) - %code{% RETVAL = new Point(); THIS->nearest_point(points, RETVAL); %}; + Clone nearest_point(Points points) + %code{% Point p; THIS->nearest_point(points, &p); RETVAL = p; %}; double distance_to(Point* point) %code{% RETVAL = THIS->distance_to(*point); %}; double distance_to_line(Line* line) diff --git a/xs/xsp/Polygon.xsp b/xs/xsp/Polygon.xsp index 6a8eac99c..824a65310 100644 --- a/xs/xsp/Polygon.xsp +++ b/xs/xsp/Polygon.xsp @@ -19,14 +19,11 @@ void translate(double x, double y); void reverse(); Lines lines(); - Polyline* split_at_vertex(Point* point) - %code{% RETVAL = new Polyline(); THIS->split_at_vertex(*point, RETVAL); %}; - Polyline* split_at_index(int index) - %code{% RETVAL = new Polyline(); THIS->split_at_index(index, RETVAL); %}; - Polyline* split_at_first_point() - %code{% RETVAL = new Polyline(); THIS->split_at_first_point(RETVAL); %}; - Points equally_spaced_points(double distance) - %code{% THIS->equally_spaced_points(distance, &RETVAL); %}; + Clone split_at_vertex(Point* point) + %code{% RETVAL = THIS->split_at_vertex(*point); %}; + Clone split_at_index(int index); + Clone split_at_first_point(); + Points equally_spaced_points(double distance); double length(); double area(); bool is_counter_clockwise(); @@ -41,16 +38,10 @@ Polygons triangulate_convex() %code{% THIS->triangulate_convex(&RETVAL); %}; Clone centroid(); - BoundingBox* bounding_box() - %code{% - RETVAL = new BoundingBox(); - THIS->bounding_box(RETVAL); - %}; + Clone bounding_box(); std::string wkt(); - Points concave_points(double angle) - %code{% THIS->concave_points(angle, &RETVAL); %}; - Points convex_points(double angle) - %code{% THIS->convex_points(angle, &RETVAL); %}; + Points concave_points(double angle); + Points convex_points(double angle); %{ Polygon* diff --git a/xs/xsp/Polyline.xsp b/xs/xsp/Polyline.xsp index a8eb527d5..3300f12c3 100644 --- a/xs/xsp/Polyline.xsp +++ b/xs/xsp/Polyline.xsp @@ -23,8 +23,7 @@ Lines lines(); Clone first_point(); Clone last_point(); - Points equally_spaced_points(double distance) - %code{% THIS->equally_spaced_points(distance, &RETVAL); %}; + Points equally_spaced_points(double distance); double length(); bool is_valid(); void clip_end(double distance); @@ -37,11 +36,7 @@ void split_at(Point* point, Polyline* p1, Polyline* p2) %code{% THIS->split_at(*point, p1, p2); %}; bool is_straight(); - BoundingBox* bounding_box() - %code{% - RETVAL = new BoundingBox(); - THIS->bounding_box(RETVAL); - %}; + Clone bounding_box(); std::string wkt(); %{ diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index fb0d17721..37876ee68 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -35,8 +35,8 @@ _constant() %code%{ RETVAL = &THIS->config; %}; Ref print(); - Flow* flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object) - %code%{ RETVAL = new Flow(THIS->flow(role, layer_height, bridge, first_layer, width, *object)); %}; + Clone flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object) + %code%{ RETVAL = THIS->flow(role, layer_height, bridge, first_layer, width, *object); %}; }; @@ -61,11 +61,7 @@ _constant() %code%{ RETVAL = THIS->layer_height_ranges; %}; Ref size() %code%{ RETVAL = &THIS->size; %}; - BoundingBox* bounding_box() - %code{% - RETVAL = new BoundingBox(); - THIS->bounding_box(RETVAL); - %}; + Clone bounding_box(); Ref _copies_shift() %code%{ RETVAL = &THIS->_copies_shift; %}; diff --git a/xs/xsp/TriangleMesh.xsp b/xs/xsp/TriangleMesh.xsp index 122a84f48..d87030693 100644 --- a/xs/xsp/TriangleMesh.xsp +++ b/xs/xsp/TriangleMesh.xsp @@ -31,19 +31,11 @@ TriangleMeshPtrs split(); void merge(TriangleMesh* mesh) %code{% THIS->merge(*mesh); %}; - ExPolygons horizontal_projection() - %code{% THIS->horizontal_projection(RETVAL); %}; - BoundingBoxf3* bounding_box() - %code{% - RETVAL = new BoundingBoxf3(); - THIS->bounding_box(RETVAL); - %}; - Pointf3* center() - %code{% - BoundingBoxf3 bb; - THIS->bounding_box(&bb); - RETVAL = new Pointf3(bb.center()); - %}; + ExPolygons horizontal_projection(); + Clone convex_hull(); + Clone bounding_box(); + Clone center() + %code{% RETVAL = THIS->bounding_box().center(); %}; int facets_count(); void reset_repair_stats(); %{ @@ -196,14 +188,6 @@ TriangleMesh::bb3() OUTPUT: RETVAL -Polygon* -TriangleMesh::convex_hull() - CODE: - RETVAL = new Polygon (); - THIS->convex_hull(RETVAL); - OUTPUT: - RETVAL - %} }; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index e295dbeeb..e7c4ac9b4 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -454,7 +454,6 @@ T_ARRAYREF for (${type}::const_iterator it = $var.begin(); it != $var.end(); ++it) { av_store(av, i++, perl_to_SV_clone_ref(*it)); } - $var.clear(); T_ARRAYREF_PTR AV* av = newAV();