diff --git a/xs/src/libslic3r/BridgeDetector.cpp b/xs/src/libslic3r/BridgeDetector.cpp index e8b0315e4..5eeca86a5 100644 --- a/xs/src/libslic3r/BridgeDetector.cpp +++ b/xs/src/libslic3r/BridgeDetector.cpp @@ -145,8 +145,8 @@ BridgeDetector::detect_angle() // remove any line not having both endpoints within anchors for (size_t i = 0; i < clipped_lines.size(); ++i) { Line &line = clipped_lines[i]; - if (!Slic3r::Geometry::contains_point(my_anchors, line.a) - || !Slic3r::Geometry::contains_point(my_anchors, line.b)) { + if (!Slic3r::Geometry::contains(my_anchors, line.a) + || !Slic3r::Geometry::contains(my_anchors, line.b)) { clipped_lines.erase(clipped_lines.begin() + i); --i; } diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index 2bfa1c494..34b75940b 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -82,13 +82,13 @@ ExPolygon::is_valid() const } bool -ExPolygon::contains_line(const Line &line) const +ExPolygon::contains(const Line &line) const { - return this->contains_polyline(line); + return this->contains((Polyline)line); } bool -ExPolygon::contains_polyline(const Polyline &polyline) const +ExPolygon::contains(const Polyline &polyline) const { Polylines pl_out; diff((Polylines)polyline, *this, &pl_out); @@ -96,11 +96,11 @@ ExPolygon::contains_polyline(const Polyline &polyline) const } bool -ExPolygon::contains_point(const Point &point) const +ExPolygon::contains(const Point &point) const { - if (!this->contour.contains_point(point)) return false; + if (!this->contour.contains(point)) return false; for (Polygons::const_iterator it = this->holes.begin(); it != this->holes.end(); ++it) { - if (it->contains_point(point)) return false; + if (it->contains(point)) return false; } return true; } diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index be6065914..9d65fcb2a 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -22,9 +22,9 @@ class ExPolygon void rotate(double angle, const Point ¢er); double area() const; bool is_valid() const; - bool contains_line(const Line &line) const; - bool contains_polyline(const Polyline &polyline) const; - bool contains_point(const Point &point) const; + bool contains(const Line &line) const; + bool contains(const Polyline &polyline) const; + bool contains(const Point &point) const; Polygons simplify_p(double tolerance) const; ExPolygons simplify(double tolerance) const; void simplify(double tolerance, ExPolygons &expolygons) const; diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index 181288c95..6f29dbb0d 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/xs/src/libslic3r/ExPolygonCollection.cpp @@ -55,32 +55,18 @@ ExPolygonCollection::rotate(double angle, const Point ¢er) } } +template bool -ExPolygonCollection::contains_point(const Point &point) const +ExPolygonCollection::contains(const T &item) const { for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) { - if (it->contains_point(point)) return true; - } - return false; -} - -bool -ExPolygonCollection::contains_line(const Line &line) const -{ - for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) { - if (it->contains_line(line)) return true; - } - return false; -} - -bool -ExPolygonCollection::contains_polyline(const Polyline &polyline) const -{ - for (ExPolygons::const_iterator it = this->expolygons.begin(); it != this->expolygons.end(); ++it) { - if (it->contains_polyline(polyline)) return true; + if (it->contains(item)) return true; } return false; } +template bool ExPolygonCollection::contains(const Point &item) const; +template bool ExPolygonCollection::contains(const Line &item) const; +template bool ExPolygonCollection::contains(const Polyline &item) const; void ExPolygonCollection::simplify(double tolerance) diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index 07532ccf4..6aa5b0a56 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -24,9 +24,7 @@ class ExPolygonCollection void scale(double factor); void translate(double x, double y); void rotate(double angle, const Point ¢er); - bool contains_point(const Point &point) const; - bool contains_line(const Line &line) const; - bool contains_polyline(const Polyline &polyline) const; + template bool contains(const T &item) const; void simplify(double tolerance); void convex_hull(Polygon* hull) const; }; diff --git a/xs/src/libslic3r/Geometry.cpp b/xs/src/libslic3r/Geometry.cpp index 4cdd9e36b..996d3fe10 100644 --- a/xs/src/libslic3r/Geometry.cpp +++ b/xs/src/libslic3r/Geometry.cpp @@ -114,14 +114,14 @@ directions_parallel(double angle1, double angle2, double max_diff) template bool -contains_point(const std::vector &vector, const Point &point) +contains(const std::vector &vector, const Point &point) { for (typename std::vector::const_iterator it = vector.begin(); it != vector.end(); ++it) { - if (it->contains_point(point)) return true; + if (it->contains(point)) return true; } return false; } -template bool contains_point(const ExPolygons &vector, const Point &point); +template bool contains(const ExPolygons &vector, const Point &point); double rad2deg(double angle) diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index a5ef6d97c..e7f2f08f3 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/xs/src/libslic3r/Geometry.hpp @@ -17,7 +17,7 @@ void chained_path(const Points &points, std::vector &retval, void chained_path(const Points &points, std::vector &retval); template void chained_path_items(Points &points, T &items, T &retval); bool directions_parallel(double angle1, double angle2, double max_diff = 0); -template bool contains_point(const std::vector &vector, const Point &point); +template bool contains(const std::vector &vector, const Point &point); double rad2deg(double angle); double rad2deg_dir(double angle); double deg2rad(double angle); diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index 89c767959..88b69ef82 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -86,10 +86,10 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl // Are both points in the same island? int island_idx = -1; for (ExPolygons::const_iterator island = this->islands.begin(); island != this->islands.end(); ++island) { - if (island->contains_point(from) && island->contains_point(to)) { + if (island->contains(from) && island->contains(to)) { // 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(Line(from, to))) { + if (island->contains(Line(from, to))) { polyline->points.push_back(from); polyline->points.push_back(to); return; @@ -104,20 +104,20 @@ MotionPlanner::shortest_path(const Point &from, const Point &to, Polyline* polyl Point inner_to = to; bool from_is_inside, to_is_inside; if (island_idx == -1) { - if (!(from_is_inside = this->outer.contains_point(from))) { + if (!(from_is_inside = this->outer.contains(from))) { // Find the closest inner point to start from. from.nearest_point(this->outer, &inner_from); } - if (!(to_is_inside = this->outer.contains_point(to))) { + if (!(to_is_inside = this->outer.contains(to))) { // Find the closest inner point to start from. to.nearest_point(this->outer, &inner_to); } } else { - if (!(from_is_inside = this->inner[island_idx].contains_point(from))) { + if (!(from_is_inside = this->inner[island_idx].contains(from))) { // Find the closest inner point to start from. from.nearest_point(this->inner[island_idx], &inner_from); } - if (!(to_is_inside = this->inner[island_idx].contains_point(to))) { + if (!(to_is_inside = this->inner[island_idx].contains(to))) { // Find the closest inner point to start from. to.nearest_point(this->inner[island_idx], &inner_to); } @@ -175,12 +175,12 @@ MotionPlanner::init_graph(int island_idx) const VD::vertex_type* v1 = edge->vertex1(); Point p0 = Point(v0->x(), v0->y()); Point p1 = Point(v1->x(), v1->y()); - // contains_point() should probably be faster than contains_line(), + // contains() should probably be faster than contains(), // and should it fail on any boundary points it's not a big problem if (island_idx == -1) { - if (!this->outer.contains_point(p0) || !this->outer.contains_point(p1)) continue; + if (!this->outer.contains(p0) || !this->outer.contains(p1)) continue; } else { - if (!this->inner[island_idx].contains_point(p0) || !this->inner[island_idx].contains_point(p1)) continue; + if (!this->inner[island_idx].contains(p0) || !this->inner[island_idx].contains(p1)) continue; } t_vd_vertices::const_iterator i_v0 = vd_vertices.find(v0); diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index cc20b524c..7fc6f0091 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -141,7 +141,7 @@ Polygon::is_valid() const } bool -Polygon::contains_point(const Point &point) const +Polygon::contains(const Point &point) const { // http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html bool result = false; diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index e842f1848..5220220f3 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -32,7 +32,7 @@ class Polygon : public MultiPoint { bool make_counter_clockwise(); bool make_clockwise(); bool is_valid() const; - bool contains_point(const Point &point) const; + bool contains(const Point &point) const; Polygons simplify(double tolerance) const; void simplify(double tolerance, Polygons &polygons) const; void triangulate_convex(Polygons* polygons) const; diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 21198e6d4..bc86fc4c1 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -788,7 +788,7 @@ TriangleMeshSlicer::make_expolygons_simple(std::vector &lines, int slice_idx = -1; double current_contour_area = -1; for (ExPolygons::iterator slice = slices->begin(); slice != slices->end(); ++slice) { - if (slice->contour.contains_point(loop->points.front())) { + if (slice->contour.contains(loop->points.front())) { double area = slice->contour.area(); if (area < current_contour_area || current_contour_area == -1) { slice_idx = slice - slices->begin(); @@ -816,7 +816,7 @@ TriangleMeshSlicer::make_expolygons(const Polygons &loops, ExPolygons* slices) supply everything to offset() instead of performing several union/diff calls. we sort by area assuming that the outermost loops have larger area; - the previous sorting method, based on $b->contains_point($a->[0]), failed to nest + the previous sorting method, based on $b->contains($a->[0]), failed to nest loops correctly in some edge cases when original model had overlapping facets */ diff --git a/xs/xsp/ExPolygon.xsp b/xs/xsp/ExPolygon.xsp index ef43e3514..75777fa56 100644 --- a/xs/xsp/ExPolygon.xsp +++ b/xs/xsp/ExPolygon.xsp @@ -22,11 +22,11 @@ double area(); bool is_valid(); bool contains_line(Line* line) - %code{% RETVAL = THIS->contains_line(*line); %}; + %code{% RETVAL = THIS->contains(*line); %}; bool contains_polyline(Polyline* polyline) - %code{% RETVAL = THIS->contains_polyline(*polyline); %}; + %code{% RETVAL = THIS->contains(*polyline); %}; bool contains_point(Point* point) - %code{% RETVAL = THIS->contains_point(*point); %}; + %code{% RETVAL = THIS->contains(*point); %}; ExPolygons simplify(double tolerance); Polygons simplify_p(double tolerance); Polylines medial_axis(double max_width, double min_width) diff --git a/xs/xsp/ExPolygonCollection.xsp b/xs/xsp/ExPolygonCollection.xsp index 902494b34..4ae1a9156 100644 --- a/xs/xsp/ExPolygonCollection.xsp +++ b/xs/xsp/ExPolygonCollection.xsp @@ -18,11 +18,11 @@ int count() %code{% RETVAL = THIS->expolygons.size(); %}; bool contains_point(Point* point) - %code{% RETVAL = THIS->contains_point(*point); %}; + %code{% RETVAL = THIS->contains(*point); %}; bool contains_line(Line* line) - %code{% RETVAL = THIS->contains_line(*line); %}; + %code{% RETVAL = THIS->contains(*line); %}; bool contains_polyline(Polyline* polyline) - %code{% RETVAL = THIS->contains_polyline(*polyline); %}; + %code{% RETVAL = THIS->contains(*polyline); %}; void simplify(double tolerance); Polygons polygons() %code{% RETVAL = *THIS; %}; diff --git a/xs/xsp/Polygon.xsp b/xs/xsp/Polygon.xsp index cad1907ff..99ff1d644 100644 --- a/xs/xsp/Polygon.xsp +++ b/xs/xsp/Polygon.xsp @@ -36,7 +36,7 @@ bool is_valid(); Clone first_point(); bool contains_point(Point* point) - %code{% RETVAL = THIS->contains_point(*point); %}; + %code{% RETVAL = THIS->contains(*point); %}; Polygons simplify(double tolerance); Polygons triangulate_convex() %code{% THIS->triangulate_convex(&RETVAL); %};