From d57a09558e692dc1f0975c8487dc33603762d5d9 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Fri, 27 Sep 2019 13:26:58 +0200 Subject: [PATCH] Several fixes of previous commits related to KDTreeIndirect.hpp and ShortestPath.cpp/.hpp --- src/libslic3r/KDTreeIndirect.hpp | 7 +++++-- src/libslic3r/ShortestPath.cpp | 13 +++++++------ src/libslic3r/ShortestPath.hpp | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/KDTreeIndirect.hpp b/src/libslic3r/KDTreeIndirect.hpp index f79dab9b3..4f71dd3e4 100644 --- a/src/libslic3r/KDTreeIndirect.hpp +++ b/src/libslic3r/KDTreeIndirect.hpp @@ -19,7 +19,10 @@ public: static constexpr size_t NumDimensions = ANumDimensions; using CoordinateFn = ACoordinateFn; using CoordType = ACoordType; - static constexpr size_t npos = size_t(-1); + // Following could be static constexpr size_t, but that would not link in C++11 + enum : size_t { + npos = size_t(-1) + }; KDTreeIndirect(CoordinateFn coordinate) : coordinate(coordinate) {} KDTreeIndirect(CoordinateFn coordinate, std::vector indices) : coordinate(coordinate) { this->build(std::move(indices)); } @@ -69,7 +72,7 @@ public: template void visit(Visitor &visitor) const { - return m_nodes.empty() ? npos : visit_recursive(0, 0, visitor); + visit_recursive(0, 0, visitor); } CoordinateFn coordinate; diff --git a/src/libslic3r/ShortestPath.cpp b/src/libslic3r/ShortestPath.cpp index b31a9d1f3..490bcf1dc 100644 --- a/src/libslic3r/ShortestPath.cpp +++ b/src/libslic3r/ShortestPath.cpp @@ -4,6 +4,7 @@ #undef assert #endif +#include "clipper.hpp" #include "ShortestPath.hpp" #include "KDTreeIndirect.hpp" #include "MutablePriorityQueue.hpp" @@ -34,7 +35,7 @@ std::vector> chain_segments(SegmentEndPointFunc end_poin { // Just sort the end points so that the first point visited is closest to start_near. out.emplace_back(0, start_near != nullptr && - (end_point_func(0, true) - *start_near).cast().squaredNorm() < (end_point_func(0, false) - *start_near).cast().squaredNorm()); + (end_point_func(0, true) - *start_near).template cast().squaredNorm() < (end_point_func(0, false) - *start_near).template cast().squaredNorm()); } else { @@ -55,8 +56,8 @@ std::vector> chain_segments(SegmentEndPointFunc end_poin std::vector end_points; end_points.reserve(num_segments * 2); for (size_t i = 0; i < num_segments; ++ i) { - end_points.emplace_back(end_point_func(i, true ).cast()); - end_points.emplace_back(end_point_func(i, false).cast()); + end_points.emplace_back(end_point_func(i, true ).template cast()); + end_points.emplace_back(end_point_func(i, false).template cast()); } // Construct the closest point KD tree over end points of segments. @@ -125,7 +126,7 @@ std::vector> chain_segments(SegmentEndPointFunc end_poin EndPoint *first_point = nullptr; size_t first_point_idx = std::numeric_limits::max(); if (start_near != nullptr) { - size_t idx = find_closest_point(kdtree, start_near->cast()); + size_t idx = find_closest_point(kdtree, start_near->template cast()); assert(idx < end_points.size()); first_point = &end_points[idx]; first_point->distance_out = 0.; @@ -309,7 +310,7 @@ std::vector> chain_extrusion_entities(std::vector &entities, std::vector> &chain) +void reorder_extrusion_entities(std::vector &entities, const std::vector> &chain) { assert(entities.size() == chain.size()); std::vector out; @@ -339,7 +340,7 @@ std::vector chain_points(const Points &points, Point *start_near) return out; } -Polylines chain_infill_polylines(Polylines &polylines) +Polylines chain_infill_polylines(Polylines &&polylines) { auto segment_end_point = [&polylines](size_t idx, bool first_point) -> const Point& { return first_point ? polylines[idx].first_point() : polylines[idx].last_point(); }; std::vector> ordered = chain_segments(segment_end_point, polylines.size(), nullptr); diff --git a/src/libslic3r/ShortestPath.hpp b/src/libslic3r/ShortestPath.hpp index b4d0b4737..06081e1fc 100644 --- a/src/libslic3r/ShortestPath.hpp +++ b/src/libslic3r/ShortestPath.hpp @@ -15,10 +15,10 @@ namespace Slic3r { std::vector chain_points(const Points &points, Point *start_near = nullptr); std::vector> chain_extrusion_entities(std::vector &entities, const Point *start_near = nullptr); -void reorder_extrusion_entities(std::vector &entities, std::vector> &chain); +void reorder_extrusion_entities(std::vector &entities, const std::vector> &chain); void chain_and_reorder_extrusion_entities(std::vector &entities, const Point *start_near = nullptr); -Polylines chain_infill_polylines(Polylines &src); +Polylines chain_infill_polylines(Polylines &&src); std::vector chain_clipper_polynodes(const Points &points, const std::vector &items);