Merge pull request #5545 from Dig-Doug/segment-midpoint

Segment_2/Segment_3 midpoint()
This commit is contained in:
Laurent Rineau 2021-07-07 14:37:38 +02:00
commit 0f906ae606
10 changed files with 106 additions and 0 deletions

View File

@ -2741,6 +2741,7 @@ namespace CartesianKernelFunctors {
{
typedef typename K::FT FT;
typedef typename K::Point_2 Point_2;
typedef typename K::Segment_2 Segment_2;
public:
typedef Point_2 result_type;
@ -2752,6 +2753,17 @@ namespace CartesianKernelFunctors {
midpointC2(p.x(), p.y(), q.x(), q.y(), x, y);
return construct_point_2(x, y);
}
Point_2
operator()(const Segment_2& s) const
{
typename K::Construct_point_2 construct_point_2;
FT x, y;
const Point_2& p = s.source();
const Point_2& q = s.target();
midpointC2(p.x(), p.y(), q.x(), q.y(), x, y);
return construct_point_2(x, y);
}
};
template <typename K>
@ -2759,6 +2771,7 @@ namespace CartesianKernelFunctors {
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point_3;
typedef typename K::Segment_3 Segment_3;
public:
typedef Point_3 result_type;
@ -2770,6 +2783,17 @@ namespace CartesianKernelFunctors {
midpointC3(p.x(), p.y(), p.z(), q.x(), q.y(), q.z(), x, y, z);
return construct_point_3(x, y, z);
}
Point_3
operator()(const Segment_3& s) const
{
const Point_3& p = s.source();
const Point_3& q = s.target();
typename K::Construct_point_3 construct_point_3;
FT x, y, z;
midpointC3(p.x(), p.y(), p.z(), q.x(), q.y(), q.z(), x, y, z);
return construct_point_3(x, y, z);
}
};
template <typename K>

View File

@ -2950,6 +2950,7 @@ namespace HomogeneousKernelFunctors {
{
typedef typename K::FT FT;
typedef typename K::Point_2 Point_2;
typedef typename K::Segment_2 Segment_2;
public:
typedef Point_2 result_type;
@ -2963,6 +2964,19 @@ namespace HomogeneousKernelFunctors {
p.hy()*qhw + q.hy()*phw,
phw * qhw * RT( 2));
}
Point_2
operator()(const Segment_2& s) const
{
typedef typename K::RT RT;
const Point_2& p = s.source();
const Point_2& q = s.target();
const RT& phw = p.hw();
const RT& qhw = q.hw();
return Point_2( p.hx()*qhw + q.hx()*phw,
p.hy()*qhw + q.hy()*phw,
phw * qhw * RT( 2));
}
};
template <typename K>
@ -2970,6 +2984,7 @@ namespace HomogeneousKernelFunctors {
{
typedef typename K::FT FT;
typedef typename K::Point_3 Point_3;
typedef typename K::Segment_3 Segment_3;
public:
typedef Point_3 result_type;
@ -2984,6 +2999,20 @@ namespace HomogeneousKernelFunctors {
p.hz()*qhw + q.hz()*phw,
RT(2) * phw * qhw );
}
Point_3
operator()(const Segment_3& s) const
{
typedef typename K::RT RT;
const Point_3& p = s.source();
const Point_3& q = s.target();
RT phw = p.hw();
RT qhw = q.hw();
return Point_3( p.hx()*qhw + q.hx()*phw,
p.hy()*qhw + q.hy()*phw,
p.hz()*qhw + q.hz()*phw,
RT(2) * phw * qhw );
}
};
// TODO ...

View File

@ -2242,12 +2242,25 @@ template <typename Kernel>
CGAL::Point_2<Kernel> midpoint( const CGAL::Point_2<Kernel>& p,
const CGAL::Point_2<Kernel>& q );
/*!
computes the midpoint of the segment `s`.
*/
template <typename Kernel>
CGAL::Point_2<Kernel> midpoint( const CGAL::Segment_2<Kernel>& s);
/*!
computes the midpoint of the segment `pq`.
*/
template <typename Kernel>
CGAL::Point_3<Kernel> midpoint( const CGAL::Point_3<Kernel>& p, const CGAL::Point_3<Kernel>& q );
/*!
computes the midpoint of the segment `s`.
*/
template <typename Kernel>
CGAL::Point_3<Kernel> midpoint( const CGAL::Segment_3<Kernel>& s );
/// @}
/// \defgroup min_vertex_grp CGAL::min_vertex()

View File

@ -4996,6 +4996,10 @@ public:
*/
Kernel::Point_2 operator()(const Kernel::Point_2& p,
const Kernel::Point_2& q );
/*!
computes the midpoint of the segment `s`.
*/
Kernel::Point_2 operator()(const Kernel::Segment_2& s);
/// @}
@ -5023,6 +5027,11 @@ public:
Kernel::Point_3 operator()(const Kernel::Point_3& p,
const Kernel::Point_3& q );
/*!
computes the midpoint of the segment `s`.
*/
Kernel::Point_3 operator()(const Kernel::Segment_3& s);
/// @}

View File

@ -754,6 +754,12 @@ midpoint(const Point_2<K> &p, const Point_2<K> &q)
return internal::midpoint(p, q, K());
}
template < class K >
inline typename K::Point_2 midpoint(const Segment_2<K> &s)
{
return internal::midpoint(s, K());
}
template < class K >
inline
typename K::Point_2

View File

@ -738,6 +738,12 @@ midpoint(const Point_3<K> &p, const Point_3<K> &q)
return internal::midpoint(p, q, K());
}
template < class K >
inline typename K::Point_3 midpoint(const Segment_3<K> &s)
{
return internal::midpoint(s, K());
}
template < class K >
inline
typename K::Point_3

View File

@ -788,6 +788,14 @@ midpoint(const typename K::Point_2 &p,
return k.construct_midpoint_2_object()(p, q);
}
template < class K >
inline
typename K::Point_2
midpoint(const typename K::Segment_2 &s, const K &k)
{
return k.construct_midpoint_2_object()(s);
}
template < class K >
inline
typename K::Point_2

View File

@ -829,6 +829,14 @@ midpoint(const typename K::Point_3 &p,
return k.construct_midpoint_3_object()(p, q);
}
template < class K >
inline
typename K::Point_3
midpoint(const typename K::Segment_3 &s, const K &k)
{
return k.construct_midpoint_3_object()(s);
}
template < class K >
inline
typename K::Point_3

View File

@ -24,6 +24,7 @@ _test_fct_constructions_2(const R&)
{
typedef typename R::RT RT;
typedef CGAL::Point_2<R> Point;
typedef CGAL::Segment_2<R> Segment;
typedef CGAL::Weighted_point_2<R> Weighted_Point;
typedef CGAL::Triangle_2<R> Triangle;
typedef CGAL::Vector_2<R> Vector;
@ -52,6 +53,7 @@ _test_fct_constructions_2(const R&)
// midpoint
assert( CGAL::midpoint( pne, psw) == p);
assert( CGAL::midpoint( pnw, pse) == p);
assert( CGAL::midpoint( Segment{pnw, pse}) == p);
// circumcenter
assert( CGAL::circumcenter( pne, pne ) == pne);

View File

@ -69,6 +69,7 @@ _test_fct_constructions_3(const R& r)
assert( CGAL::midpoint( p110, p001) == p);
assert( CGAL::midpoint( p010, p101) == p);
assert( CGAL::midpoint( p100, p011) == p);
assert( CGAL::midpoint( Segment{p100, p011}) == p);
// circumcenter
assert( CGAL::circumcenter( p111, p001, p010, p000) == p);