From 30e969ccff64ee2b4e55101dee30582e2b8678bd Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Mon, 11 Jan 2010 12:50:50 +0000 Subject: [PATCH] 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. --- .../Triangulation_2_ref/Weighted_point.tex | 10 ++++- Triangulation_2/include/CGAL/Weighted_point.h | 38 ++++++++++++++++++- .../CGAL/_test_cls_regular_triangulation_2.h | 6 +++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/Triangulation_2/doc_tex/Triangulation_2_ref/Weighted_point.tex b/Triangulation_2/doc_tex/Triangulation_2_ref/Weighted_point.tex index a2a7a4f4b87..f07f5e34f9d 100644 --- a/Triangulation_2/doc_tex/Triangulation_2_ref/Weighted_point.tex +++ b/Triangulation_2/doc_tex/Triangulation_2_ref/Weighted_point.tex @@ -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;}{} diff --git a/Triangulation_2/include/CGAL/Weighted_point.h b/Triangulation_2/include/CGAL/Weighted_point.h index b80f354f182..dca7a1cb6d5 100644 --- a/Triangulation_2/include/CGAL/Weighted_point.h +++ b/Triangulation_2/include/CGAL/Weighted_point.h @@ -21,11 +21,22 @@ #ifndef CGAL_WEIGHTED_POINT_H #define CGAL_WEIGHTED_POINT_H -CGAL_BEGIN_NAMESPACE +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace CGAL { template < class Pt, class We > class Weighted_point : public Pt { + typedef typename Kernel_traits::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, + boost::mpl::bool_::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, + boost::is_convertible, + boost::mpl::bool_::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 &wp) return is; } -CGAL_END_NAMESPACE +} // namespace CGAL #endif // CGAL_WEIGHTED_POINT_H diff --git a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h index 1140af84426..57899088a9b 100644 --- a/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h +++ b/Triangulation_2/test/Triangulation_2/include/CGAL/_test_cls_regular_triangulation_2.h @@ -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::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);