Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel_23: Add function squared_length() #8008

Merged
merged 4 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Kernel_23/doc/Kernel_23/CGAL/Kernel/global_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
16 changes: 16 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_internal_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Kernel_23/test/Kernel_23/include/CGAL/_test_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
43 changes: 43 additions & 0 deletions Kernel_23/test/Kernel_23/include/CGAL/_test_fct_segment_3.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Kernel_23/test/Kernel_23/include/CGAL/_test_fct_vector_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) );
Expand Down