Skip to content
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
24 changes: 24 additions & 0 deletions Cartesian_kernel/include/CGAL/Cartesian/function_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -2752,13 +2753,25 @@ 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>
class Construct_midpoint_3
{
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;

Expand All @@ -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>
Expand Down
29 changes: 29 additions & 0 deletions Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -2963,13 +2964,27 @@ 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>
class Construct_midpoint_3
{
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;

Expand All @@ -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 ...
Expand Down
13 changes: 13 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 @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions Kernel_23/doc/Kernel_23/Concepts/FunctionObjectConcepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -4996,6 +4996,10 @@ class ConstructMidpoint_2 {
*/
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);

/// @}

Expand Down Expand Up @@ -5023,6 +5027,11 @@ class ConstructMidpoint_3 {
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);


/// @}

Expand Down
6 changes: 6 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Kernel_23/include/CGAL/Kernel/global_functions_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 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 @@ -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
Expand Down
8 changes: 8 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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down