From ab19b99105cb81f4b96df167155b3c39defa9e6c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Jan 2024 16:16:17 +0000 Subject: [PATCH 1/4] Kernel_23: Add function squared_length() --- .../Kernel_23/CGAL/Kernel/global_functions.h | 34 +++++++++++++++++++ .../include/CGAL/Kernel/global_functions_2.h | 16 +++++++++ .../include/CGAL/Kernel/global_functions_3.h | 16 +++++++++ .../CGAL/Kernel/global_functions_internal_2.h | 17 ++++++++++ .../CGAL/Kernel/global_functions_internal_3.h | 16 +++++++++ 5 files changed, 99 insertions(+) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index 243ca48a93e1..b26638c84b18 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -2691,6 +2691,40 @@ const CGAL::Point_3& r); /// \defgroup squared_distance_grp CGAL::squared_distance() /// \ingroup kernel_global_function +/// \defgroup squared_radius_grp CGAL::squared_length() +/// \ingroup kernel_global_function + +/*! +compute the squared length of vector `v`. +*/ +template +FT +squared_length(const CGAL::Vector_2& v); + +/*! +compute the squared length of segment `s`. +*/ +template +FT +squared_length(const CGAL::Segment_2& s); + +/*! +compute the squared length of vector `v`. +*/ +template +FT +squared_length(const CGAL::Vector_3& v); + +/*! +compute the squared length of segment `s`. +*/ +template +FT +squared_length(const CGAL::Segment_3& s); + +/// @} + + /// \defgroup squared_radius_grp CGAL::squared_radius() /// \ingroup kernel_global_function /// \sa `Circle_2_grp` diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index e974eae730dc..ad67bff10419 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -1114,6 +1114,22 @@ side_of_oriented_circle(const Point_2 &p, return internal::side_of_oriented_circle(p, q, r, t, K()); } +template < class K > +inline +typename K::FT +squared_length(const Vector_2 &v) +{ + return internal::squared_length(v, K()); +} + +template < class K > +inline +typename K::FT +squared_length(const Segment_2 &s) +{ + return internal::squared_length(s, K()); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_3.h index e17211e184be..aa16e5d7cb8c 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_3.h @@ -1276,6 +1276,22 @@ squared_area(const Point_3 &p, const Point_3 &q, const Point_3 &r) return internal::squared_area(p, q, r, K()); } +template < class K > +inline +typename K::FT +squared_length(const Vector_3 &v) +{ + return internal::squared_length(v, K()); +} + +template < class K > +inline +typename K::FT +squared_length(const Segment_3 &s) +{ + return internal::squared_length(s, K()); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h index 7212eb7ed60e..a7407a9fd74c 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -988,6 +988,23 @@ side_of_oriented_circle(const typename K::Point_2 &p, return k.side_of_oriented_circle_2_object()(p, q, r, t); } + +template +inline +typename K::FT +squared_length(const typename K::Vector_2 &v, const K &k) +{ + return k.compute_squared_length_2_object()(v); +} + +template +inline +typename K::FT +squared_length(const typename K::Segment_2 &s, const K &k) +{ + return k.compute_squared_length_2_object()(s); +} + template < class K > inline typename K::FT diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h index e48ec201f389..8ae26a9c787d 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h @@ -1112,6 +1112,22 @@ squared_area(const typename K::Point_3 &p, return k.compute_squared_area_3_object()(p, q, r); } +template +inline +typename K::FT +squared_length(const typename K::Vector_3 &v, const K &k) +{ + return k.compute_squared_length_3_object()(v); +} + +template +inline +typename K::FT +squared_length(const typename K::Segment_3 &s, const K &k) +{ + return k.compute_squared_length_3_object()(s); +} + template < class K > inline typename K::FT From 276857a49cf4027b25d633209cf679baaa4ee64a Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Jan 2024 16:22:20 +0000 Subject: [PATCH 2/4] fix grp --- Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index b26638c84b18..59823ac96c88 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -2688,12 +2688,14 @@ const CGAL::Point_3& r); // The same reason as do_intersect. -/// \defgroup squared_distance_grp CGAL::squared_distance() +/// \defgroup squared_length_grp CGAL::squared_distance() /// \ingroup kernel_global_function /// \defgroup squared_radius_grp CGAL::squared_length() /// \ingroup kernel_global_function +/// @{ + /*! compute the squared length of vector `v`. */ From e3ee9990246b7ca94adfd45bd320823ac349ef37 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 29 Jan 2024 16:26:29 +0000 Subject: [PATCH 3/4] fix grp --- Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h index 59823ac96c88..f0e1e50973fb 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h +++ b/Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h @@ -2688,10 +2688,10 @@ const CGAL::Point_3& r); // The same reason as do_intersect. -/// \defgroup squared_length_grp CGAL::squared_distance() +/// \defgroup squared_distance_grp CGAL::squared_distance() /// \ingroup kernel_global_function -/// \defgroup squared_radius_grp CGAL::squared_length() +/// \defgroup squared_length_grp CGAL::squared_length() /// \ingroup kernel_global_function /// @{ From 4b574dca8ebff69dd34a51de55f196b965f60e07 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 14 Feb 2024 11:43:34 +0000 Subject: [PATCH 4/4] Add tests --- .../test/Kernel_23/include/CGAL/_test_3.h | 2 + .../include/CGAL/_test_fct_segment_2.h | 3 ++ .../include/CGAL/_test_fct_segment_3.h | 43 +++++++++++++++++++ .../include/CGAL/_test_fct_vector_2.h | 1 + .../include/CGAL/_test_fct_vector_3.h | 1 + 5 files changed, 50 insertions(+) create mode 100644 Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_3.h diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_3.h index 02a5e6cf20ce..40b992a857e7 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_3.h @@ -31,6 +31,7 @@ #include "_test_cls_plane_3.h" #include "_test_cls_line_3.h" #include "_test_cls_segment_3.h" +#include "_test_fct_segment_3.h" #include "_test_cls_sphere_3.h" #include "_test_cls_ray_3.h" #include "_test_cls_triangle_3.h" @@ -51,6 +52,7 @@ _test_3(const R& r) && _test_fct_point_3(r) && _test_fct_weighted_point_3(r) && _test_fct_plane_3(r) + && _test_fct_segment_3(r) && _test_further_fct_point_plane_3(r) && _test_cls_direction_3(r) && _test_cls_plane_3( r ) diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h index d97d8c0b1111..9ed30767567c 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h @@ -111,6 +111,9 @@ _test_fct_segment_2(const R& ) assert( CGAL::compare_slope(l6, l9) == CGAL::LARGER ); assert( CGAL::compare_slope(l9, l7) == CGAL::SMALLER ); + std::cout <<'.'; + assert( CGAL::squared_distance(l9.source(), l9.target()) == CGAL::squared_length(l9) ); + std::cout << "done" << std::endl; return true; } diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_3.h new file mode 100644 index 000000000000..ad0d419ae462 --- /dev/null +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_3.h @@ -0,0 +1,43 @@ +// Copyright (c) 1999 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later +// +// +// Author(s) : Susan Hert + + +#ifndef CGAL__TEST_FCT_SEGMENT_3_H +#define CGAL__TEST_FCT_SEGMENT_3_H + +template +bool +_test_fct_segment_3(const R& ) +{ + std::cout << "Testing functions Segment_3" ; + + typedef typename R::RT RT; + + typedef typename R::Point_3 Point_3; + typedef typename R::Segment_3 Segment_3; + + Point_3 p1 ( RT(0), RT(0), RT(0), RT(1) ); + Point_3 p2 ( RT(1), RT(1), RT(1), RT(1) ); + + + Segment_3 l1(p1, p2); + assert( CGAL::squared_distance(l1.source(), l1.target()) == CGAL::squared_length(l1) ); + + std::cout << "done" << std::endl; + return true; +} + +#endif // CGAL__TEST_FCT_SEGMENT_3_H diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_2.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_2.h index 7731765f24e7..3140f54902e4 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_2.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_2.h @@ -87,6 +87,7 @@ _test_fct_vector_2(const R& ) assert( CGAL::scalar_product(v1, v2) == FT(30) ); assert( v1 * v0 == FT(0) ); assert( v1.squared_length() == FT(40) ); + assert( v1.squared_length() == CGAL::squared_length(v1) ); assert( CGAL::Vector_2( n1, n2) == v1 * RT(2)); assert( CGAL::Vector_2( n5, n6) == v2 * RT(3)); assert( CGAL::Vector_2( n1, n2) == RT(2) * v1); diff --git a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_3.h b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_3.h index 70e273d1e680..d1c090353efc 100644 --- a/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_3.h +++ b/Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_3.h @@ -101,6 +101,7 @@ _test_fct_vector_3(const R& ) std::cout << '.'; + assert( v1.squared_length() == CGAL::squared_length(v1) ); assert( v1.squared_length() == FT(49) ); assert( v1 * v2 == FT(66) ); assert( v1 * v0 == FT(0) );