Weighted_point : add constructors from Cartesian coordinates (2D and 3D).

They hardcode weight=0 and do not provide room for an "hw" homogeneous
argument, in order to avoid any potential ambiguity.
This commit is contained in:
Sylvain Pion 2010-01-11 12:50:50 +00:00
parent 3eace192a7
commit 30e969ccff
3 changed files with 51 additions and 3 deletions

View File

@ -34,9 +34,17 @@ and \ccc{Regular_triangulation_euclidean_traits_3}.
\ccCreation
\ccCreationVariable{wp} %% choose variable name
\ccConstructor{Weighted_point(Weighted_point wq)}{copy constructor.}
\ccGlue
\ccConstructor{Weighted_point(Point p=Point(), Weight w= Weight(0))}{}
\ccGlue
\ccConstructor{Weighted_point(Weighted_point wq)}{copy constructor.}
\ccConstructor{Weighted_point(FT x, FT y)}{Constructs the point from \ccc{x}
and \ccc{y} coordinates, with a weight of 0. Requires that the ambient
dimension be 2.}
\ccGlue
\ccConstructor{Weighted_point(FT x, FT y, FT z)}{Constructs the point from
\ccc{x}, \ccc{y} and \ccc{z} coordinates, with a weight of 0. Requires that
the ambient dimension be 3.}
\ccAccessFunctions
\ccMethod{Point point() const;}{}

View File

@ -21,11 +21,22 @@
#ifndef CGAL_WEIGHTED_POINT_H
#define CGAL_WEIGHTED_POINT_H
CGAL_BEGIN_NAMESPACE
#include <iostream>
#include <CGAL/Kernel_traits.h>
#include <CGAL/Dimension.h>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/utility.hpp>
namespace CGAL {
template < class Pt, class We >
class Weighted_point : public Pt
{
typedef typename Kernel_traits<Pt>::Kernel::FT FT;
public:
typedef We Weight;
typedef Pt Point;
@ -43,6 +54,29 @@ public:
Weighted_point (const Point &p, const Weight &w)
: Point(p), _weight(w) {}
// Constructors from coordinates are also provided for convenience, except
// that they are only from Cartesian coordinates, and with no weight, so as
// to avoid any potential ambiguity between the homogeneous weight and the
// power weight (it should be easy enough to pass a Point explicitly in those
// cases).
// The enable_if complexity comes from the fact that we separate dimension 2 and 3.
template < typename Tx, typename Ty >
Weighted_point (const Tx &x, const Ty &y,
typename boost::enable_if< boost::mpl::and_<boost::is_convertible<Tx, FT>,
boost::is_convertible<Ty, FT>,
boost::mpl::bool_<Ambient_dimension<Point>::value == 2> > >::type* = 0)
: Point(x, y), _weight(0) {}
template < typename Tx, typename Ty, typename Tz >
Weighted_point (const Tx &x, const Ty &y, const Tz &z,
typename boost::enable_if< boost::mpl::and_<boost::is_convertible<Tx, FT>,
boost::is_convertible<Ty, FT>,
boost::is_convertible<Tz, FT>,
boost::mpl::bool_<Ambient_dimension<Point>::value == 3> > >::type* = 0)
: Point(x, y, z), _weight(0) {}
const Point & point() const
{
return *this;
@ -99,6 +133,6 @@ operator>>(std::istream &is, Weighted_point<Point,Weight> &wp)
return is;
}
CGAL_END_NAMESPACE
} // namespace CGAL
#endif // CGAL_WEIGHTED_POINT_H

View File

@ -136,6 +136,12 @@ _test_cls_regular_triangulation_2( const Triangulation & )
Weighted_point wp29(p9,22);
Weighted_point wp22(p12,300);
{
Weighted_point p15_bis(p15.x(), p15.y());
assert(p15_bis == p15);
CGAL::Weighted_point<CGAL::Simple_cartesian<double>::Point_3, double> w3(0, 0, 0);
}
Cls T;
assert(T.power_test(wp1,wp2,wp3) == CGAL::ON_NEGATIVE_SIDE);
assert(T.power_test(wp1,wp8,wp2) == CGAL::ON_POSITIVE_SIDE);