From 5cba1e83199c017e07b22abca96d774c44f0a571 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 10 Oct 2022 14:14:55 +0200 Subject: [PATCH] Improved Point.hpp to_2d() and to_3d() templates to accept Eigen expressions --- src/libslic3r/Point.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Point.hpp b/src/libslic3r/Point.hpp index da558e438..949ddbad1 100644 --- a/src/libslic3r/Point.hpp +++ b/src/libslic3r/Point.hpp @@ -111,11 +111,17 @@ inline double angle(const Eigen::MatrixBase &v1, const Eigen::MatrixBas return atan2(cross2(v1d, v2d), v1d.dot(v2d)); } -template -Eigen::Matrix to_2d(const Eigen::MatrixBase> &ptN) { return { ptN.x(), ptN.y() }; } +template +Eigen::Matrix to_2d(const Eigen::MatrixBase &ptN) { + static_assert(Derived::IsVectorAtCompileTime && int(Derived::SizeAtCompileTime) >= 3, "to_2d(): first parameter is not a 3D or higher dimensional vector"); + return { ptN.x(), ptN.y() }; +} -template -Eigen::Matrix to_3d(const Eigen::MatrixBase> & pt, const T z) { return { pt.x(), pt.y(), z }; } +template +inline Eigen::Matrix to_3d(const Eigen::MatrixBase &pt, const typename Derived::Scalar z) { + static_assert(Derived::IsVectorAtCompileTime && int(Derived::SizeAtCompileTime) == 2, "to_3d(): first parameter is not a 2D vector"); + return { pt.x(), pt.y(), z }; +} inline Vec2d unscale(coord_t x, coord_t y) { return Vec2d(unscale(x), unscale(y)); } inline Vec2d unscale(const Vec2crd &pt) { return Vec2d(unscale(pt.x()), unscale(pt.y())); }