diff --git a/.gitattributes b/.gitattributes index 96cc506eff0..cc1cf3a2a09 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1827,8 +1827,7 @@ Jet_fitting_3/doc_tex/Jet_fitting_3_ref/template_dependence.jpg -text svneol=uns Jet_fitting_3/doc_tex/Jet_fitting_3_ref/template_dependence.pdf -text svneol=unset#application/pdf Jet_fitting_3/examples/Jet_fitting_3/data/ellipe0.003.off -text svneol=unset#application/octet-stream Kernel_23/doc_tex/Kernel_23/fig/pointSegmentTriangle.png -text -Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_2.tex -text -Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_3.tex -text +Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits.tex -text Kernel_23/doc_tex/Kernel_23_ref/Kernel_ConstructRadicalLine_2.tex -text Kernel_23/doc_tex/Kernel_23_ref/compare_lexicographically.tex -text Kernel_23/doc_tex/Kernel_23_ref/fig/IsoCuboid.gif -text svneol=unset#image/gif @@ -1858,13 +1857,13 @@ Kernel_23/examples/Kernel_23/MyConstruct_coord_iterator.h -text Kernel_23/examples/Kernel_23/MyConstruct_point_2.h -text Kernel_23/examples/Kernel_23/MyPointC2_iostream.h -text Kernel_23/examples/Kernel_23/cartesian_converter.cpp -text +Kernel_23/examples/Kernel_23/intersections.cpp -text Kernel_23/include/CGAL/functions_on_enums.h -text Kernel_23/include/CGAL/internal/Projection_traits_3.h -text Kernel_23/test/Kernel_23/CMakeLists.txt -text Kernel_23/test/Kernel_23/overload_bug.cpp -text Kernel_d/doc_tex/Kernel_d/hypercube.png -text Kernel_d/doc_tex/Kernel_d_ref/Do_intersect_d.tex -text -Kernel_d/doc_tex/Kernel_d_ref/Intersection_traits_d.tex -text Kernel_d/doc_tex/Kernel_d_ref/Kernel_Compute_coordinate_d.tex -text Kernel_d/doc_tex/Kernel_d_ref/Kernel_Less_coordinate_d.tex -text Kernel_d/doc_tex/Kernel_d_ref/Kernel_Point_dimension_d.tex -text @@ -3339,6 +3338,9 @@ Ridges_3/examples/Ridges_3/skip_vcproj_auto_generation -text Ridges_3/test/Ridges_3/data/ellipsoid.off -text svneol=unset#application/octet-stream Robustness/demo/Robustness/help/index.html svneol=native#text/html STL_Extension/doc_tex/STL_Extension/plusplus.png -text +STL_Extension/doc_tex/STL_Extension_ref/overload.tex -text +STL_Extension/examples/STL_Extension/Dispatch_output_iterator.cpp -text +STL_Extension/examples/STL_Extension/Overload.cpp -text STL_Extension/include/CGAL/Overload.h -text STL_Extension/include/CGAL/internal/boost/array_binary_tree.hpp -text STL_Extension/include/CGAL/internal/boost/mutable_heap.hpp -text diff --git a/Kernel_23/doc_tex/Kernel_23/kernel_toc.tex b/Kernel_23/doc_tex/Kernel_23/kernel_toc.tex index dbb38ce5ba4..ef5f47330d3 100644 --- a/Kernel_23/doc_tex/Kernel_23/kernel_toc.tex +++ b/Kernel_23/doc_tex/Kernel_23/kernel_toc.tex @@ -91,6 +91,7 @@ \ccRefIdfierPage{CGAL::do_intersect} \\ \ccRefIdfierPage{CGAL::intersection} \\ +\ccRefIdfierPage{CGAL::Intersection_traits, B} \\ \ccRefIdfierPage{CGAL::squared_distance} \\ \subsubsection*{Predicates and Constructions} diff --git a/Kernel_23/doc_tex/Kernel_23/predicates_constructions.tex b/Kernel_23/doc_tex/Kernel_23/predicates_constructions.tex index a3dedae7e87..eb076e26ff1 100644 --- a/Kernel_23/doc_tex/Kernel_23/predicates_constructions.tex +++ b/Kernel_23/doc_tex/Kernel_23/predicates_constructions.tex @@ -62,28 +62,19 @@ There are number types on which no \ccStyle{sqrt} operation is defined, especially integer types and rationals. \end{itemize} -\subsection{Polymorphic Return Values} -Some functions can return different types of objects. A typical -\CC\ solution to this problem is to derive all possible return -types from a common base class, to return a pointer to this -class and to perform a dynamic cast on this pointer. The class -\ccc{Object} provides an abstraction. -An object \ccStyle{obj} of the class \ccc{Object} can -represent an arbitrary class. The only operations it provides is -to make copies and assignments, so that you can put them in lists -or arrays. Note that \ccc{Object} is NOT a common base class for the -elementary classes. Therefore, there is no -automatic conversion from these classes to \ccc{Object}. Rather -this is done with the global function \ccc{make_object()}. This -encapsulation mechanism requires the use of -\ccc{object_cast} to access the encapsulated class (a less -efficient way, which is now discouraged, used to be to -use the \ccc{assign} function). +\subsection{Intersections and variant return values} +Some functions can return different types of objects. To achieve this +in a type safe way {\cgal} uses return values of +\ccStyle{boost::optional< boost::variant< T \ldots\ >} were +T\textellipsis\ is a list of all possible resulting geometric objects. +The exact result type of an intersection can be determined by using the +\ccStyle{Intersection_traits} class. \ccExample -In the following example, the object class is used as return value for the -\ccHtmlNoLinksFrom{intersection} computation, as there are possibly different return values. +In the following example, the traits class is used to provide the return value for the +\ccHtmlNoLinksFrom{intersection} computation: +\ccHtmlLinksOff% \begin{cprog} { typedef Cartesian K; @@ -93,54 +84,23 @@ In the following example, the object class is used as return value for the Segment_2 segment_1, segment_2; std::cin >> segment_1 >> segment_2; - - Object obj = intersection(segment_1, segment_2); - - if (const Point_2 *point = object_cast(&obj)) { - /* do something with *point */ - } else if (const Segment_2 *segment = object_cast(&obj)) { - /* do something with *segment*/ + + /* IT is an alias for Intersection_traits */ + IT< K, Segment_2, Segment_2>::result_type + v = intersection(s1, s2); + if(v) { + /* not empty */ + if (const Point_2 *p = boost::get(&*v) ) { + /* do something with *p */ + } else if (const Segment_2 *s = boost::get(&*v) ) { + /* do something with *s */ + } + } else { + /* empty intersection */ } \end{cprog} -\ccHtmlLinksOff% -\begin{cprog} - /* there was no intersection */ -} -\end{cprog} \ccHtmlLinksOn% - -\medskip -The \ccHtmlNoLinksFrom{intersection} routine itself looks roughly as follows: - -\begin{cprog} - -template < class Kernel > -Object intersection(Segment_2 s1, Segment_2 s2) -{ -\end{cprog} -\ccHtmlLinksOff% -\begin{cprog} - if (/* intersection in a point */ ) { -\end{cprog} -\ccHtmlLinksOn% -\begin{cprog} - Point_2 p = ... ; - return make_object(p); -\end{cprog} -\ccHtmlLinksOff% -\begin{cprog} - } else if (/* intersection in a segment */ ) { -\end{cprog} -\ccHtmlLinksOn% -\begin{cprog} - Segment_2 s = ... ; - return make_object(s); - } - return Object(); -} -\end{cprog} - \subsection{Constructive Predicates} For testing where a point $p$ lies with respect to a plane defined by three points $q$, $r$ and $s$, one may be tempted to construct the plane diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits.tex b/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits.tex new file mode 100644 index 00000000000..b55e11e53a0 --- /dev/null +++ b/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits.tex @@ -0,0 +1,18 @@ +\begin{ccRefClass}{Intersection_traits, B} + +\ccInclude{CGAL/Intersection_traits.h} + +\ccDefinition + +The traits class \ccClassTemplateName\ provides a typedef for the +return type of the \ccc{intersection} function objects belonging to a +model of \ccc{Kernel}. The value of \ccStyle{result_type} can be found +in the \ccc{intersection} documentation of the corresponding kernel. + +For convenience the alias \ccStyle{IT} is provided. + +\ccTypes + +\ccStyle{result_type} The type of the resulting intersection between \ccStyle{A} and \ccStyle{B}. +\end{ccRefClass} + diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_2.tex b/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_2.tex deleted file mode 100644 index bd9f509ab15..00000000000 --- a/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_2.tex +++ /dev/null @@ -1,17 +0,0 @@ -\begin{ccRefClass}{Intersection_traits_2< Kernel, A, B >} - -\ccInclude{CGAL/Intersection_traits_2.h} - -\ccDefinition - -The traits class \ccClassTemplateName\ provides a typedef for the -return type of the \ccc{intersection} function when called on -2-dimensional objects belonging to a model of \ccc{Kernel}. - -For convenience the alias \ccStyle{IT2} is provided. - -\ccTypes - -\ccStyle{result_type} The type of the resulting intersection between A and B -\end{ccRefClass} - diff --git a/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_3.tex b/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_3.tex deleted file mode 100644 index 863c17ab76f..00000000000 --- a/Kernel_23/doc_tex/Kernel_23_ref/Intersection_traits_3.tex +++ /dev/null @@ -1,17 +0,0 @@ -\begin{ccRefClass}{Intersection_traits_3< Kernel, A, B >} - -\ccInclude{CGAL/Intersection_traits_3.h} - -\ccDefinition - -The traits class \ccClassTemplateName\ provides a typedef for the -return type of the \ccc{intersection} function when called on -3-dimensional objects belonging to a model of \ccc{Kernel}. - -For convenience the alias \ccStyle{IT3} is provided. - -\ccTypes - -\ccStyle{result_type} The type of the resulting intersection between A and B -\end{ccRefClass} - diff --git a/Kernel_23/doc_tex/Kernel_23_ref/intersection.tex b/Kernel_23/doc_tex/Kernel_23_ref/intersection.tex index 8cd6320dbdd..46ea6984d43 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/intersection.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/intersection.tex @@ -4,6 +4,15 @@ Depending on which \cgal\ \ccHtmlNoLinksFrom{kernel} is used, different versions of this global function are available. This is described below. +\paragraph{Notes on Backwards compatibility} + +The \ccStyle{intersection} function used to return +\ccStyle{CGAL::Object} but starting with {\cgal} VERSION HERE the +return type is determined by a dedicated traits class. To preserve +backwards compatibility \ccStyle{CGAL::Object} can be constructed from +the new return types implicitly, but switching to the new style is +advocated. + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \paragraph{With the basic 2D and 3D Kernel} (see Chapter~\ref{chapter-kernel-23}) @@ -11,7 +20,7 @@ described below. \ccUnchecked{ \ccRefLabel{Kernel::intersection} -\ccFunction{Object intersection(Type1 obj1, Type2 obj2);} +\ccFunction{IT< Kernel, Type1, Type2 >::result_type intersection(Type1 obj1, Type2 obj2);} {Two objects \ccStyle{obj1} and \ccStyle{obj2} intersect if there is a point \ccStyle{p} that is part of both \ccStyle{obj1} and \ccStyle{obj2}. The \ccHtmlNoLinksFrom{intersection} region of those two objects is defined as the set of all @@ -22,10 +31,10 @@ If a segment lies completely inside a triangle, then those two objects intersect and the \ccHtmlNoLinksFrom{intersection} region is the complete segment. }} -The possible value for types \ccStyle{Type1} and \ccStyle{Type2} and the -possible return values wrapped in \ccc{Object} are the -following: +The same functionality is also available through the functors \ccc{Kernel::Intersect_2} and \ccc{Kernel::Intersect_2}. +The possible values for types \ccStyle{Type1} and \ccStyle{Type2} and +the value for T\ldots in \ccStyle{boost::optional< boost::variant< T\ldots >} are the following: \begin{ccTexOnly} \begin{longtable}[c]{|l|l|l|} @@ -105,6 +114,13 @@ type A & type B & \parbox{4 cm}{\vspace{1 mm}{return type}} \\ \\ \ccStyle{Segment_2} \vspace{1 mm}} \\ \hline +\ccStyle{Iso_rectangle_2} & \ccStyle{Triangle_2} & \parbox{4 cm}{\vspace{1 mm} + \ccStyle{Point_2} + \\ \ccStyle{Segment_2} + \\ \ccStyle{Triangle_2} + \\ \ccStyle{_2} + \vspace{1 mm}} \\ +\hline \ccStyle{Iso_rectangle_2} & \ccStyle{Iso_rectangle_2} & \parbox{4 cm}{\vspace{1 mm} \ccStyle{Iso_rectangle_2} \vspace{1 mm}} \\ @@ -470,9 +486,10 @@ type A & type B & \parbox{4 cm}{\vspace{1 mm}{return type}} \\ There is also an intersection function between 3 planes. -\ccFunction{Object intersection(const Plane_3& pl1, - const Plane_3& pl2, - const Plane_3& pl3);} +\ccFunction{optional< variant< Point_3, Line_3, Plane_3 > > + intersection(const Plane_3& pl1, + const Plane_3& pl2, + const Plane_3& pl3);} {returns the intersection of 3 planes, which can be either a point, a line, a plane, or empty.} @@ -485,9 +502,12 @@ If this kernel is used, in addition to the function and the combination of 2D types described above, another version of the function is provided. +The iterator versions of those functions can be used in conjunction +with \ccc{CGAL::Dispatch_output_iterator}. + Since both the number of intersections, if any, and their type, -depend on the arguments, the function returns an output -iterator on \ccc{Object}'s, as presented below. +depend on the arguments, the function expects an output +iterator on \ccc{Intersection_Traits< K, Type1, Type2 >}, as presented below. \ccFunction{template < class OutputIterator > OutputIterator @@ -495,7 +515,7 @@ intersection(const Type1 &obj1, const Type2 &obj2, OutputIterator intersections);} {Copies in the output iterator the intersection elements between the two objects. \ccc{intersections} iterates on -elements of type \ccc{CGAL::Object}, in lexicographic order,} +elements of type \ccStyle{IT< K, Type1, Type2 >}, in lexicographic order,} where \ccStyle{Type1} and \ccStyle{Type2} can both be either \begin{itemize} @@ -529,9 +549,12 @@ If this kernel is used, in addition to the function and the combination of 3D types described above, two other versions of the function are provided. +The iterator versions of those functions can be used in conjunction +with \ccc{CGAL::Dispatch_output_iterator}. + Since both the number of intersections, if any, and their type, -depend on the arguments, the functions return an output -iterator on \ccStyle{Object}'s, as presented below. +depend on the arguments, the functions expects an output +iterator on \ccStyle{Intersection_Traits, Type2}, as presented below. The \textbf{first function} is: @@ -541,7 +564,7 @@ intersection(const Type1 &obj1, const Type2 &obj2, OutputIterator intersections);} {Copies in the output iterator the intersection elements between the two objects. \ccc{intersections} iterates on -elements of type \ccStyle{CGAL::Object}, in lexicographic order, +elements of type \ccStyle{IT, B}, in lexicographic order, when this ordering is defined on the computed objects,} where \ccStyle{Type1} and \ccStyle{Type2} can both be either: @@ -555,7 +578,7 @@ where \ccStyle{Type1} and \ccStyle{Type2} can both be either: \end{itemize} and depending on the types \ccStyle{Type1} and \ccStyle{Type2}, the computed -\ccStyle{CGAL::Object}s can be assigned to +type can be: \begin{itemize} \item {} \ccStyle{std::pair, unsigned>}, where the unsigned integer is the multiplicity of the corresponding @@ -580,7 +603,8 @@ intersection(const Type1 &obj1, const Type2 &obj2, const Type3 &obj3, OutputIterator intersections);} {Copies in the output iterator the intersection elements between the three objects. \ccc{intersections} iterates on -elements of type \ccStyle{CGAL::Object}, in lexicographic order +elements of type \ccStyle{boost::optional< boost::variant< std::pair, unsigned>, +Circle_3, Sphere_3, Plane_3 >}, in lexicographic order when this ordering is defined on the computed objects} where \ccStyle{Type1}, \ccStyle{Type2} and \ccStyle{Type3} @@ -590,8 +614,7 @@ can be either \item {} \ccStyle{Plane_3} \end{itemize} -and depending of these types, the computed \ccStyle{CGAL::Object}s can be -assigned to +and depending of these types, the computed return value \begin{itemize} \item {} \ccStyle{std::pair, unsigned>}, where the unsigned integer is the multiplicity of the corresponding @@ -607,35 +630,23 @@ and \ccc{obj3} are equal. The following example demonstrates the most common use of \ccc{intersection} routines with the basic 2D and 3D Kernels. +\ccHtmlLinksOff% \begin{verbatim} #include -void foo(CGAL::Segment_2 seg, CGAL::Line_2 line) +template +struct Intersection_visitor { + typedef result_type void; + void operator()(const Point_2& p) const { /* handle point */ } + void operator()(const Segment_2& s) const { /* handle segment */ } +}; + +template +void foo(Segment_2 seg, Line_2 lin) { - CGAL::Object result = CGAL::intersection(seg, line); - if (const CGAL::Point_2 *ipoint = CGAL::object_cast >(&result)) { -\end{verbatim}% -\ccHtmlLinksOff% -\begin{verbatim} - // handle the point intersection case with *ipoint. -\end{verbatim}% -\ccHtmlLinksOn% -\begin{verbatim} - } else - if (const CGAL::Segment_2 *iseg = CGAL::object_cast >(&result)) { -\end{verbatim}% -\ccHtmlLinksOff% -\begin{verbatim} - // handle the segment intersection case with *iseg. -\end{verbatim}% -\ccHtmlLinksOn% -\begin{verbatim} - } else { -\end{verbatim}% -\ccHtmlLinksOff% -\begin{verbatim} - // handle the no intersection case. - } + ITd< R, Segment_2, Line_2 >::result_type result = intersection(seg, lin); + if(result) { boost::apply_visitor(Intersection_visitor(), *result); } + else { /* no intersection */ } } \end{verbatim}% \ccHtmlLinksOn% @@ -646,8 +657,9 @@ in Chapters~\ref{chapter-circular-kernel} and~\ref{chapter-spherical-kernel}. \ccSeeAlso -% \ccRefIdfierPage{CGAL::assign} \\ -\ccRefIdfierPage{CGAL::do_intersect} \\ -\ccRefIdfierPage{CGAL::Object} \\ +\ccRefIdfierPage{CGAL::do_intersect}, \\ +\ccRefIdfierPage{CGAL::Intersection_traits, B}, \\ +\ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional}, \\ +\ccAnchor{www.boost.org/doc/html/variant.html}{boost::variant} \end{ccRefFunction} diff --git a/Kernel_23/doc_tex/Kernel_23_ref/main.tex b/Kernel_23/doc_tex/Kernel_23_ref/main.tex index 72b6922ff57..697c980d865 100644 --- a/Kernel_23/doc_tex/Kernel_23_ref/main.tex +++ b/Kernel_23/doc_tex/Kernel_23_ref/main.tex @@ -44,8 +44,6 @@ in the kernel. \input{Kernel_23_ref/Simple_cartesian.tex} \input{Kernel_23_ref/Simple_homogeneous.tex} \input{Kernel_23_ref/Projection_traits_xy_3.tex} -\input{Kernel_23_ref/Intersection_traits_2.tex} -\input{Kernel_23_ref/Intersection_traits_3.tex} \clearpage \section{Predefined Kernels} @@ -191,6 +189,7 @@ in the kernel. \input{Kernel_23_ref/has_smaller_signed_distance_to_line.tex} \input{Kernel_23_ref/has_smaller_signed_distance_to_plane.tex} \input{Kernel_23_ref/intersection.tex} +\input{Kernel_23_ref/Intersection_traits.tex} \input{Kernel_23_ref/left_turn.tex} \input{Kernel_23_ref/lexicographically_xyz_smaller.tex} \input{Kernel_23_ref/lexicographically_xyz_smaller_or_equal.tex} diff --git a/Kernel_23/examples/Kernel_23/intersections.cpp b/Kernel_23/examples/Kernel_23/intersections.cpp new file mode 100644 index 00000000000..0bc256e883e --- /dev/null +++ b/Kernel_23/examples/Kernel_23/intersections.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +using namespace CGAL; + +typedef Cartesian K; +typedef K::Point_2 Point; +typedef Creator_uniform_2 Pt_creator; +typedef K::Segment_2 Segment; + +int main() +{ + std::vector input; + + // Prepare point generator for the horizontal segment, length 200. + typedef Random_points_on_segment_2 P1; + P1 p1( Point(-100,0), Point(100,0)); + + // Prepare point generator for random points on circle, radius 250. + typedef Random_points_on_circle_2 P2; + P2 p2( 250); + + // Create segments. + typedef Creator_uniform_2< Point, Segment> Seg_creator; + typedef Join_input_iterator_2< P1, P2, Seg_creator> Seg_iterator; + Seg_iterator g( p1, p2); + copy_n( g, seg_count, std::back_inserter(input)); + + + std::vector points; + std::vector segments; + + typedef Dispatch_output_iterator< + cpp0x::tuple, cpp0x::tuple< std::back_insert_iterator >, + std::back_insert_iterator > > > + Dispatcher; + + Dispatcher disp = dispatch_output( std::back_inserter(points),std::back_inserter(segments) ); + + // intersections of many objects, directly dispatched + std::transform(input.begin(), input.end(), disp, + // XXX fix binder + boost::bind(intersection, input.front(), _1)); + std::cout << "Point intersections: " << points.size() << std::endl; + std::cout << "Segment intersections: " << segments.size() << std::endl; + + // intersections of a single object + IT2 v = intersection(input.back(), input.front()); + return 0; +} diff --git a/Kernel_d/doc_tex/Kernel_d/kernel_d_toc.tex b/Kernel_d/doc_tex/Kernel_d/kernel_d_toc.tex index 97e397a94ff..43775a2064b 100644 --- a/Kernel_d/doc_tex/Kernel_d/kernel_d_toc.tex +++ b/Kernel_d/doc_tex/Kernel_d/kernel_d_toc.tex @@ -44,6 +44,6 @@ \subsubsection*{Intersection operations} \ccRefIdfierPage{CGAL::do_intersect}\\ -\ccRefIdfierPage{CGAL::intersection} - +\ccRefIdfierPage{CGAL::intersection}\\ +\ccRefIdfierPage{CGAL::Intersection_traits} diff --git a/Kernel_d/doc_tex/Kernel_d/predicates_constructions_d.tex b/Kernel_d/doc_tex/Kernel_d/predicates_constructions_d.tex index 9e2ca790424..8dcd59b58a8 100644 --- a/Kernel_d/doc_tex/Kernel_d/predicates_constructions_d.tex +++ b/Kernel_d/doc_tex/Kernel_d/predicates_constructions_d.tex @@ -58,7 +58,7 @@ routine, The problem of a distance routine is that it needs the defined, especially integer types and rationals. \end{itemize} -\subsection{Intersection} +\subsection{Intersections} Intersections on kernel objects currently cover only those objects that are part of flats (\ccc{Segment_d}, \ccc{Ray_d}, @@ -67,7 +67,7 @@ $o1$, $o2$ of these types the operation \ccc{intersection(o1,o2)} returns a \ccStyle{boost::optional< boost::variant< T \ldots\ >} were T\textellipsis\ is a list of all possible resulting geometric objects. -The traits class \ccc{Intersection_traits_d} provides a typedef for +The traits class \ccc{Intersection_traits} provides a typedef for the \ccStyle{result_type} of the \ccc{intersection} function when called with d-dimensional kernel objects. @@ -79,7 +79,7 @@ d-dimensional kernel objects. typedef Segment_d< K > Segment; Segment s1, s2; std::cin >> s1 >> s2; - ITd< K, Segment, Segment>::result_type + IT::result_type v = intersection(s1, s2); if(v) { /* not empty */ diff --git a/Kernel_d/doc_tex/Kernel_d_ref/Intersection_traits_d.tex b/Kernel_d/doc_tex/Kernel_d_ref/Intersection_traits_d.tex deleted file mode 100644 index c0854e582ab..00000000000 --- a/Kernel_d/doc_tex/Kernel_d_ref/Intersection_traits_d.tex +++ /dev/null @@ -1,17 +0,0 @@ -\begin{ccRefClass}{Intersection_traits_d< Kernel, A, B >} - -\ccInclude{CGAL/Intersection_traits_d.h} - -\ccDefinition - -The traits class \ccClassTemplateName\ provides a typedef for the -return type of the \ccc{intersection} function when called on objects -belonging to a model of \ccc{Kernel_d}. - -For convenience the alias \ccStyle{ITd} is provided. - -\ccTypes - -\ccStyle{result_type} The type of the resulting intersection between A and B -\end{ccRefClass} - diff --git a/Kernel_d/doc_tex/Kernel_d_ref/Kernel_Intersect_d.tex b/Kernel_d/doc_tex/Kernel_d_ref/Kernel_Intersect_d.tex index 9d646dcfe62..ae94dbdb902 100644 --- a/Kernel_d/doc_tex/Kernel_d_ref/Kernel_Intersect_d.tex +++ b/Kernel_d/doc_tex/Kernel_d_ref/Kernel_Intersect_d.tex @@ -4,7 +4,7 @@ A model for this must provide: \ccCreationVariable{fo} \ccMemberFunction{ - Intersection_traits_d, Type2 >::result_type + Intersection_traits, Type2 >::result_type operator()(const Type1& p, const Type2& q);} {returns the result of the intersection of $p$ and $q$ in form of a polymorphic object. \ccc{Kernel_object} may be any of diff --git a/Kernel_d/doc_tex/Kernel_d_ref/intersection.tex b/Kernel_d/doc_tex/Kernel_d_ref/intersection.tex index 51ed1331bdc..3891d389725 100644 --- a/Kernel_d/doc_tex/Kernel_d_ref/intersection.tex +++ b/Kernel_d/doc_tex/Kernel_d_ref/intersection.tex @@ -1,7 +1,7 @@ \begin{ccRefFunction}{intersection} \ccInclude{CGAL/intersections_d.h} -\ccFunction{Intersection_traits_d, Type2 >::result_type +\ccFunction{Intersection_traits, Type2 >::result_type intersection(Type1 f1, Type2 f2);} { returns the intersection result of $f1$ and $f2$. \ccPrecond The objects are of the same dimension.} @@ -152,25 +152,25 @@ The following example demonstrates the most common use of \begin{verbatim} #include +template struct Intersection_visitor { typedef result_type void; - void operator()(const Point_d& p) { /* handle point */ } - void operator()(const Segment_d& s) { /* handle segment */ } + void operator()(const Point_d& p) const { /* handle point */ } + void operator()(const Segment_d& s) const { /* handle segment */ } }; template void foo(Segment_d seg, Line_d lin) { ITd< R, Segment_d, Line_d >::result_type result = intersection(seg, lin); - if(result) { boost::apply_visitor(Intersection_visitor(), *result); } + if(result) { boost::apply_visitor(Intersection_visitor(), *result); } else { /* no intersection */ } } \end{verbatim}% \ccHtmlLinksOn% \ccSeeAlso \ccc{do_intersect}, \ccc{Kernel::Intersect_d} , -\ccc{Kernel::Do_intersect_d}, \ccc{Intersection_traits_d}, -\ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional}, +\ccc{Kernel::Do_intersect_d}, \ccAnchor{www.boost.org/doc/libs/release/libs/optional/index.html}{boost::optional}, \ccAnchor{www.boost.org/doc/html/variant.html}{boost::variant} \end{ccRefFunction} diff --git a/Kernel_d/doc_tex/Kernel_d_ref/main.tex b/Kernel_d/doc_tex/Kernel_d_ref/main.tex index dc13648b9fa..9ad0cc9a3d7 100644 --- a/Kernel_d/doc_tex/Kernel_d_ref/main.tex +++ b/Kernel_d/doc_tex/Kernel_d_ref/main.tex @@ -86,7 +86,6 @@ \input{Kernel_d_ref/Kernel_Equal_d.tex} \input{Kernel_d_ref/Kernel_Has_on_positive_side_d.tex} \input{Kernel_d_ref/Kernel_Intersect_d.tex} -\input{Kernel_d_ref/Intersection_traits_d.tex} \input{Kernel_d_ref/Kernel_Less_lexicographically_d.tex} \input{Kernel_d_ref/Kernel_Less_or_equal_lexicographically_d.tex} \input{Kernel_d_ref/Kernel_Less_coordinate_d.tex} diff --git a/STL_Extension/doc_tex/STL_Extension_ref/main.tex b/STL_Extension/doc_tex/STL_Extension_ref/main.tex index 6978aa689e3..b53da320382 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/main.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/main.tex @@ -35,6 +35,7 @@ \input{STL_Extension_ref/tuple.tex} \input{STL_Extension_ref/Complexity_tags.tex} \input{STL_Extension_ref/Default.tex} +\input{STL_Extension_ref/overload.tex} %%\cgalColumnLayout diff --git a/STL_Extension/doc_tex/STL_Extension_ref/overload.tex b/STL_Extension/doc_tex/STL_Extension_ref/overload.tex new file mode 100644 index 00000000000..b7b056e8ee9 --- /dev/null +++ b/STL_Extension/doc_tex/STL_Extension_ref/overload.tex @@ -0,0 +1,22 @@ +\begin{ccRefClass}{Overload} + +\ccInclude{CGAL/Overload.h} + +\ccDefinition + +A class to bundle multiple unary \ccStyle{std::function} or +\ccStyle{boost::function} objects into a single overload of +\ccStyle{operator()}. The return type of \ccStyle{operator()} is the +result_type of the first function of the \ccStyle{tuple} it was created from. + +\ccOperations + +\ccMethod{template result_type operator()(T& t);} +{Calls the function that matches the arguments best.} + +\ccFunctionTemplate{T}{template Overload make_overload(T&& c);} +{Creates an \ccStyle{Overload} from the \ccStyle{cpp0x::tuple} \ccStyle{c}.} + +\ccIncludeExampleCode{STL_Extension/Overload.cpp} + +\end{ccRefClass} diff --git a/STL_Extension/doc_tex/STL_Extension_ref/stl_extension.tex b/STL_Extension/doc_tex/STL_Extension_ref/stl_extension.tex index 4de0741fdb3..119c36decc7 100644 --- a/STL_Extension/doc_tex/STL_Extension_ref/stl_extension.tex +++ b/STL_Extension/doc_tex/STL_Extension_ref/stl_extension.tex @@ -244,6 +244,8 @@ dispatch_output(O... o);} {returns a \ccc{Dispatch_output_iterator} constructed from the arguments.} + \ccIncludeExampleCode{STL_Extension/Dispatch_output_iterator.cpp} + \ccSeeAlso \ccRefIdfierPage{CGAL::Dispatch_or_drop_output_iterator} diff --git a/STL_Extension/examples/STL_Extension/Dispatch_output_iterator.cpp b/STL_Extension/examples/STL_Extension/Dispatch_output_iterator.cpp new file mode 100644 index 00000000000..02d20f4d641 --- /dev/null +++ b/STL_Extension/examples/STL_Extension/Dispatch_output_iterator.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +int main() +{ + std::vector a; + std::vector b; + std::vector c; + + typedef CGAL::Dispatch_output_iterator< + CGAL::cpp0x::tuple, + CGAL::cpp0x::tuple >, + std::back_insert_iterator< std::vector >, + std::back_insert_iterator< std::vector > + > > Dispatch; + + Dispatch disp = CGAL::dispatch_output( + std::back_inserter(a), + std::back_inserter(b), + std::back_inserter(c)); + + var va = 23; var vb = 4.2; var vc = 'x'; + + // goes to a + *disp++ = va; + // goes to b + *disp++ = vb; + // goes to c + *disp++ = vc; + // goes to a + *disp++ = 42; + + return 0; +} diff --git a/STL_Extension/examples/STL_Extension/Overload.cpp b/STL_Extension/examples/STL_Extension/Overload.cpp new file mode 100644 index 00000000000..c74e685551a --- /dev/null +++ b/STL_Extension/examples/STL_Extension/Overload.cpp @@ -0,0 +1,19 @@ +#include +#include + +// This file requires a compiler with support for the C++0x features auto and lambda +int main() +{ + auto overload = make_overload( + std::make_tuple( + function([](int) { return 1; }), + function([](char) { return 2; }), + function([](double) { return 3; }) + ) + ); + + std::cout << o(1) << o('a') << " " << o(2.0) << std::endl; + + return 0; +} +