diff --git a/src/libslic3r/Execution/Execution.hpp b/src/libslic3r/Execution/Execution.hpp index e4bad9f237..62e49cfeb3 100644 --- a/src/libslic3r/Execution/Execution.hpp +++ b/src/libslic3r/Execution/Execution.hpp @@ -10,10 +10,6 @@ namespace Slic3r { -// Borrowed from C++20 -template -using remove_cvref_t = std::remove_reference_t>; - // Override for valid execution policies template struct IsExecutionPolicy_ : public std::false_type {}; diff --git a/src/libslic3r/Fill/FillBase.cpp b/src/libslic3r/Fill/FillBase.cpp index 6d1d94ff8c..a41a11cb79 100644 --- a/src/libslic3r/Fill/FillBase.cpp +++ b/src/libslic3r/Fill/FillBase.cpp @@ -595,7 +595,6 @@ static inline bool line_rounded_thick_segment_collision( // Very short line vector. Just test whether the center point is inside the offset line. Vec2d lpt = 0.5 * (line_a + line_b); if (segment_l > SCALED_EPSILON) { - struct Linef { Vec2d a, b; }; intersects = line_alg::distance_to_squared(Linef{ segment_a, segment_b }, lpt) < offset2; } else intersects = (0.5 * (segment_a + segment_b) - lpt).squaredNorm() < offset2; @@ -1196,8 +1195,6 @@ static inline void mark_boundary_segments_overlapping_infill( // Spacing (width) of the infill lines. const double spacing) { - struct Linef { Vec2d a; Vec2d b; }; - for (ContourIntersectionPoint &cp : graph.map_infill_end_point_to_boundary) { const Points &contour = graph.boundary[cp.contour_idx]; const std::vector &contour_params = graph.boundary_params[cp.contour_idx]; @@ -2003,9 +2000,8 @@ static double evaluate_support_arch_cost(const Polyline &pl) double dmax = 0; // Maximum distance in Y axis out of the (ymin, ymax) band and from the (front, back) line. - struct Linef { Vec2d a, b; }; Linef line { front.cast(), back.cast() }; - for (const Point pt : pl.points) + for (const Point &pt : pl.points) dmax = std::max(std::max(dmax, line_alg::distance_to(line, Vec2d(pt.cast()))), std::max(pt.y() - ymax, ymin - pt.y())); return dmax; } diff --git a/src/libslic3r/Line.hpp b/src/libslic3r/Line.hpp index 72532b4e33..b62775bfe4 100644 --- a/src/libslic3r/Line.hpp +++ b/src/libslic3r/Line.hpp @@ -4,6 +4,8 @@ #include "libslic3r.h" #include "Point.hpp" +#include + namespace Slic3r { class BoundingBox; @@ -20,12 +22,28 @@ Linef3 transform(const Linef3& line, const Transform3d& t); namespace line_alg { +template struct Traits { + static constexpr int Dim = L::Dim; + using Scalar = typename L::Scalar; + + static Vec& get_a(L &l) { return l.a; } + static Vec& get_b(L &l) { return l.b; } + static const Vec& get_a(const L &l) { return l.a; } + static const Vec& get_b(const L &l) { return l.b; } +}; + +template const constexpr int Dim = Traits>::Dim; +template using Scalar = typename Traits>::Scalar; + +template auto get_a(L &&l) { return Traits>::get_a(l); } +template auto get_b(L &&l) { return Traits>::get_b(l); } + // Distance to the closest point of line. -template -double distance_to_squared(const L &line, const Vec &point) +template +double distance_to_squared(const L &line, const Vec, Scalar> &point) { - const Vec v = (line.b - line.a).template cast(); - const Vec va = (point - line.a).template cast(); + const Vec, double> v = (get_b(line) - get_a(line)).template cast(); + const Vec, double> va = (point - get_a(line)).template cast(); const double l2 = v.squaredNorm(); // avoid a sqrt if (l2 == 0.0) // a == b case @@ -35,12 +53,12 @@ double distance_to_squared(const L &line, const Vec &point) // It falls where t = [(this-a) . (b-a)] / |b-a|^2 const double t = va.dot(v) / l2; if (t < 0.0) return va.squaredNorm(); // beyond the 'a' end of the segment - else if (t > 1.0) return (point - line.b).template cast().squaredNorm(); // beyond the 'b' end of the segment + else if (t > 1.0) return (point - get_b(line)).template cast().squaredNorm(); // beyond the 'b' end of the segment return (t * v - va).squaredNorm(); } -template -double distance_to(const L &line, const Vec &point) +template +double distance_to(const L &line, const Vec, Scalar> &point) { return std::sqrt(distance_to_squared(line, point)); } @@ -84,6 +102,9 @@ public: Point a; Point b; + + static const constexpr int Dim = 2; + using Scalar = Point::Scalar; }; class ThickLine : public Line @@ -107,6 +128,9 @@ public: Vec3crd a; Vec3crd b; + + static const constexpr int Dim = 3; + using Scalar = Vec3crd::Scalar; }; class Linef @@ -117,6 +141,9 @@ public: Vec2d a; Vec2d b; + + static const constexpr int Dim = 2; + using Scalar = Vec2d::Scalar; }; class Linef3 @@ -133,6 +160,9 @@ public: Vec3d a; Vec3d b; + + static const constexpr int Dim = 3; + using Scalar = Vec3d::Scalar; }; BoundingBox get_extents(const Lines &lines); diff --git a/src/libslic3r/MTUtils.hpp b/src/libslic3r/MTUtils.hpp index 7b903f66c8..9e77aa90af 100644 --- a/src/libslic3r/MTUtils.hpp +++ b/src/libslic3r/MTUtils.hpp @@ -106,8 +106,8 @@ template bool all_of(const C &container) }); } -template -using remove_cvref_t = std::remove_reference_t>; +//template +//using remove_cvref_t = std::remove_reference_t>; /// Exactly like Matlab https://www.mathworks.com/help/matlab/ref/linspace.html template> diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index efdecbac8f..2b0c94161d 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -308,6 +308,10 @@ IntegerOnly> reserve_vector(I capacity) return ret; } +// Borrowed from C++20 +template +using remove_cvref_t = std::remove_cv_t>; + } // namespace Slic3r #endif