Merge pull request #8008 from afabri/Kernel_23-squared_length-GF

Kernel_23:  Add function squared_length()
This commit is contained in:
Laurent Rineau 2024-02-22 10:23:04 +01:00
commit fd0dfc6f24
10 changed files with 151 additions and 0 deletions

View File

@ -2691,6 +2691,42 @@ const CGAL::Point_3<Kernel>& r);
/// \defgroup squared_distance_grp CGAL::squared_distance()
/// \ingroup kernel_global_function
/// \defgroup squared_length_grp CGAL::squared_length()
/// \ingroup kernel_global_function
/// @{
/*!
compute the squared length of vector `v`.
*/
template <typename Kernel>
FT
squared_length(const CGAL::Vector_2<Kernel>& v);
/*!
compute the squared length of segment `s`.
*/
template <typename Kernel>
FT
squared_length(const CGAL::Segment_2<Kernel>& s);
/*!
compute the squared length of vector `v`.
*/
template <typename Kernel>
FT
squared_length(const CGAL::Vector_3<Kernel>& v);
/*!
compute the squared length of segment `s`.
*/
template <typename Kernel>
FT
squared_length(const CGAL::Segment_3<Kernel>& s);
/// @}
/// \defgroup squared_radius_grp CGAL::squared_radius()
/// \ingroup kernel_global_function
/// \sa `Circle_2<Kernel>_grp`

View File

@ -1114,6 +1114,22 @@ side_of_oriented_circle(const Point_2<K> &p,
return internal::side_of_oriented_circle(p, q, r, t, K());
}
template < class K >
inline
typename K::FT
squared_length(const Vector_2<K> &v)
{
return internal::squared_length(v, K());
}
template < class K >
inline
typename K::FT
squared_length(const Segment_2<K> &s)
{
return internal::squared_length(s, K());
}
template < class K >
inline
typename K::FT

View File

@ -1276,6 +1276,22 @@ squared_area(const Point_3<K> &p, const Point_3<K> &q, const Point_3<K> &r)
return internal::squared_area(p, q, r, K());
}
template < class K >
inline
typename K::FT
squared_length(const Vector_3<K> &v)
{
return internal::squared_length(v, K());
}
template < class K >
inline
typename K::FT
squared_length(const Segment_3<K> &s)
{
return internal::squared_length(s, K());
}
template < class K >
inline
typename K::FT

View File

@ -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 <typename K>
inline
typename K::FT
squared_length(const typename K::Vector_2 &v, const K &k)
{
return k.compute_squared_length_2_object()(v);
}
template <typename K>
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

View File

@ -1112,6 +1112,22 @@ squared_area(const typename K::Point_3 &p,
return k.compute_squared_area_3_object()(p, q, r);
}
template <typename K>
inline
typename K::FT
squared_length(const typename K::Vector_3 &v, const K &k)
{
return k.compute_squared_length_3_object()(v);
}
template <typename K>
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

View File

@ -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 )

View File

@ -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;
}

View File

@ -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 <class R>
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

View File

@ -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<R>( n1, n2) == v1 * RT(2));
assert( CGAL::Vector_2<R>( n5, n6) == v2 * RT(3));
assert( CGAL::Vector_2<R>( n1, n2) == RT(2) * v1);

View File

@ -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) );