From fbd24d665d6d5947bfca85eadbc2584809d62d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 9 Oct 2023 12:30:37 +0200 Subject: [PATCH] add version for Point_2/Vector_2 --- .../include/CGAL/Cartesian/Point_2.h | 5 +++++ .../include/CGAL/Cartesian/Vector_2.h | 6 +++++- .../include/CGAL/Cartesian/function_objects.h | 18 ++++++++++++++++-- Kernel_23/include/CGAL/Point_2.h | 8 +++++++- Kernel_23/include/CGAL/Vector_2.h | 6 ++++++ 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h b/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h index 92a71f42557..0869bd792aa 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Point_2.h @@ -47,6 +47,11 @@ public: PointC2(const FT &x, const FT &y) : base(x, y) {} + template + PointC2(T1 &&x, T2 &&y) + : base(std::forward(x), std::forward(y)) + {} + PointC2(const FT &hx, const FT &hy, const FT &hw) : base(hx, hy, hw) {} diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h b/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h index 575df5d0728..04c71866631 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Vector_2.h @@ -50,7 +50,11 @@ public: VectorC2() {} VectorC2(const FT &x, const FT &y) - : base(CGAL::make_array(x, y)) {} + : base(Rep{x, y}) {} + + template + VectorC2(T1 &&x, T2 &&y) + : base(fwd_make_array(std::forward(x), std::forward(y))) {} VectorC2(const FT &hx, const FT &hy, const FT &hw) : base( hw != FT(1) ? CGAL::make_array(hx/hw, hy/hw) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 1a014253fd6..4af46fbcbd8 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -3084,6 +3084,11 @@ namespace CartesianKernelFunctors { operator()(Return_base_tag, const RT& x, const RT& y) const { return Rep(x, y); } + template + Rep + operator()(T1&& x, T2&& y) const + { return Rep(std::forward(x), std::forward(y)); } + Rep // Point_2 operator()(Return_base_tag, const RT& x, const RT& y, const RT& w) const { return Rep(x, y, w); } @@ -3533,6 +3538,12 @@ namespace CartesianKernelFunctors { operator()(Return_base_tag, const Point_2& p, const Point_2& q) const { return Rep(q.x() - p.x(), q.y() - p.y()); } + // note that compared to Vector_3 this one is needed as it could be ambiguous + // with operator()(Rbt,FT,FT) version + Rep // Vector_2 + operator()(Return_base_tag, Point_2&& p, Point_2&& q) const + { return Rep(q.x() - p.x(), q.y() - p.y()); } + Rep // Vector_2 operator()(Return_base_tag, const Origin&, const Point_2& q) const { return Rep(q.x(), q.y()); } @@ -3565,12 +3576,15 @@ namespace CartesianKernelFunctors { operator()(Return_base_tag, const RT& x, const RT& y) const { return Rep(x, y); } + template + Rep // Vector_2 + operator()(Return_base_tag, T1&& x, T2&& y) const + { return Rep(/* std::forward(x), std::forward(y) */); } + Rep // Vector_2 operator()(Return_base_tag, const RT& x, const RT& y, const RT& w) const { return Rep(x, y, w); } - - Vector_2 operator()( const Point_2& p, const Point_2& q) const { return this->operator()(Return_base_tag(), p, q); } diff --git a/Kernel_23/include/CGAL/Point_2.h b/Kernel_23/include/CGAL/Point_2.h index 87728264781..497354ded42 100644 --- a/Kernel_23/include/CGAL/Point_2.h +++ b/Kernel_23/include/CGAL/Point_2.h @@ -84,6 +84,12 @@ public: : Rep(typename R::Construct_point_2()(Return_base_tag(), x, y)) {} + template < typename T1, typename T2> + Point_2(T1&& x, T2&& y) + : Rep(typename R::Construct_point_2()(Return_base_tag(), std::forward(x), + std::forward(y))) + {} + Point_2(const RT& hx, const RT& hy, const RT& hw) : RPoint_2(typename R::Construct_point_2()(Return_base_tag(), hx, hy, hw)) {} @@ -255,7 +261,7 @@ extract(std::istream& is, Point_2& p, const Cartesian_tag&) break; } if (is) - p = Point_2(x, y); + p = Point_2(std::move(x), std::move(y)); return is; } diff --git a/Kernel_23/include/CGAL/Vector_2.h b/Kernel_23/include/CGAL/Vector_2.h index 6e62f77fa5d..6066d684716 100644 --- a/Kernel_23/include/CGAL/Vector_2.h +++ b/Kernel_23/include/CGAL/Vector_2.h @@ -91,6 +91,12 @@ public: Vector_2(const T1 &x, const T2 &y) : RVector_2(typename R::Construct_vector_2()(Return_base_tag(), x,y)) {} + template < typename T1, typename T2 > + Vector_2(T1&& x, T2&& y) + : RVector_2(typename R::Construct_vector_2()(Return_base_tag(), std::forward(x), + std::forward(y))) + {} + Vector_2(const RT &x, const RT &y, const RT &w) : RVector_2(typename R::Construct_vector_2()(Return_base_tag(), x,y,w)) {}