replace \code with real examples

This commit is contained in:
Andreas Fabri 2015-02-09 10:54:24 +01:00
parent 2a78cd495e
commit 1f989622e7
7 changed files with 34 additions and 59 deletions

View File

@ -165,7 +165,7 @@ namespace internal {
inline inline
CGAL::Object intersection_return() { return CGAL::Object(); } CGAL::Object intersection_return() { return CGAL::Object(); }
#else #else
#if defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE) #if defined(CGAL_CFG_NO_CPP0X_RVALUE_REFERENCE)
template<typename F, typename A, typename B, typename T> template<typename F, typename A, typename B, typename T>
inline typename cpp11::result_of<F(A, B)>::type inline typename cpp11::result_of<F(A, B)>::type
intersection_return(const T& t) { return typename cpp11::result_of<F(A, B)>::type(t); } intersection_return(const T& t) { return typename cpp11::result_of<F(A, B)>::type(t); }

View File

@ -1564,8 +1564,9 @@ intersection(const typename K::Segment_3 &seg,
if (_max == _min) { if (_max == _min) {
return intersection_return<typename K::Intersect_3, typename K::Segment_3, typename K::Iso_cuboid_3>(Point_3(_ref_point + _dir * _min )); return intersection_return<typename K::Intersect_3, typename K::Segment_3, typename K::Iso_cuboid_3>(Point_3(_ref_point + _dir * _min ));
} }
return intersection_return<typename K::Intersect_3, typename K::Segment_3, typename K::Iso_cuboid_3>( return intersection_return<typename K::Intersect_3, typename K::Segment_3, typename K::Iso_cuboid_3>(
Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max));
} }

View File

@ -127,9 +127,9 @@ depending on the arguments.
The following tables give the possible values for `Type1` and `Type2`. The following tables give the possible values for `Type1` and `Type2`.
\cgalHeading{2D intersections} \cgalHeading{2D Intersections}
The return type can be obtained through `cpp11::result_of<Kernel::Intersect_2(A, B)>::%type`. The return type can be obtained through `CGAL::cpp11::result_of<Kernel::Intersect_2(A, B)>::%type`.
It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack. It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack.
<DIV ALIGN="CENTER"> <DIV ALIGN="CENTER">
@ -217,9 +217,9 @@ It is equivalent to `boost::optional< boost::variant< T... > >`, the last column
</TABLE> </TABLE>
</DIV> </DIV>
\cgalHeading{3D intersections} \cgalHeading{3D Intersections}
The return type can be obtained through `cpp11::result_of<Kernel::Intersect_3(A, B)>::%type`. The return type can be obtained through `CGAL::cpp11::result_of<Kernel::Intersect_3(A, B)>::%type`.
It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack. It is equivalent to `boost::optional< boost::variant< T... > >`, the last column in the table providing the template parameter pack.
<DIV ALIGN="CENTER"> <DIV ALIGN="CENTER">
@ -316,57 +316,30 @@ p <TD>Point_3, or Segment_3</TD>
</TABLE> </TABLE>
</DIV> </DIV>
\cgalHeading{Example} \cgalHeading{Examples}
The following example demonstrates the most common use of The following examples demonstrate the most common use of
`intersection` routines with the 2D and 3D Linear %Kernel. `intersection()` functions with the 2D and 3D Linear %Kernel.
\code In the first two examples we intersect a segment and a line.
#include <CGAL/intersections.h> The result type can be obtained with `CGAL::cpp11::result_of`. It looks simpler
if you use a C++ compiler which supports `auto`,
but you must anyways know that the result type is a `boost::optional<boost::variant<..> >`, in order to unpack the point or segment.
template <typename R> <A HREF="http://www.boost.org/libs/optional/">`boost::optional`</A> comes in
struct Intersection_visitor { as there might be no intersection. <A HREF="http://www.boost.org/libs/variant/">`boost::variant`</A> comes in
typedef void result_type; as, if there is an intersection, it is either a point or a segment.
void operator()(const Point_2<R>& p) const
{
// handle point
}
void operator()(const Segment_2<R>& s) const
{
// handle segment
}
};
template <typename R> As explained in the boost manual pages for <A HREF="http://www.boost.org/libs/variant/">`boost::variant`</A>, there are two ways to access the variants. The first examples uses `boost::get`.
void foo (const Segment_2<R>& seg, const Line_2<R>& lin)
{
// with C++11 support
// auto result = intersection(seg, lin);
// without C++11 \cgalExample{Kernel_23/intersection_get.cpp}
cpp11::result_of<R::Intersect_2(Segment_2<R>, Line_2<R>)>::type
result = intersection(seg, lin);
if (result) { boost::apply_visitor(Intersection_visitor(), *result); } The second example uses`boost::apply_visitor`.
else {
// no intersection
}
// alternatively: \cgalExample{Kernel_23/intersection_visitor.cpp}
if (result) {
if (const Segment_2<R>* s = boost::get<Segment_2>(&*result)) {
// handle segment
} else {
const Point_2<R>* p = boost::get<Point_2<R> >(&*result);
// handle point
}
}
}
\endcode
A third example shows the use of the intersection function as a
Another example showing the use of the intersection function as a plain function call and with `Dispatch_output_iterator`, combined with
plain function call and with `Dispatch_output_iterator` combined with
a standard library algorithm. a standard library algorithm.
\cgalExample{Kernel_23/intersections.cpp} \cgalExample{Kernel_23/intersections.cpp}

View File

@ -7,6 +7,8 @@
\example Kernel_23/MyKernel.cpp \example Kernel_23/MyKernel.cpp
\example Filtered_kernel/Filtered_predicate.cpp \example Filtered_kernel/Filtered_predicate.cpp
\example Kernel_23/cartesian_converter.cpp \example Kernel_23/cartesian_converter.cpp
\example Kernel_23/intersection_get.cpp
\example Kernel_23/intersection_visitor.cpp
\example Kernel_23/intersections.cpp \example Kernel_23/intersections.cpp
\example Kernel_23/points_and_segment.cpp \example Kernel_23/points_and_segment.cpp
\example Kernel_23/surprising.cpp \example Kernel_23/surprising.cpp

View File

@ -1,11 +1,10 @@
#include <CGAL/Simple_cartesian.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>
#include <CGAL/iterator.h> #include <CGAL/iterator.h>
#include <CGAL/point_generators_2.h> #include <CGAL/point_generators_2.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
typedef CGAL::Simple_cartesian<double> K; typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_2 Point; typedef K::Point_2 Point;
typedef K::Segment_2 Segment; typedef K::Segment_2 Segment;
@ -49,7 +48,7 @@ int main()
std::vector<Segment> segments; std::vector<Segment> segments;
typedef CGAL::Dispatch_output_iterator< typedef CGAL::Dispatch_output_iterator<
CGAL::cpp11::tuple<Point,Segment>, CGAL::cpp0x::tuple< std::back_insert_iterator<std::vector<Point> >, CGAL::cpp11::tuple<Point,Segment>, CGAL::cpp11::tuple< std::back_insert_iterator<std::vector<Point> >,
std::back_insert_iterator<std::vector<Segment> > > > std::back_insert_iterator<std::vector<Segment> > > >
Dispatcher; Dispatcher;

View File

@ -109,7 +109,7 @@ The class `Dispatch_or_drop_output_iterator` defines an
dispatches among those based on the type of the value type which is dispatches among those based on the type of the value type which is
put in it. Besides defining assignment for all parameters of `V` put in it. Besides defining assignment for all parameters of `V`
and for a tuple of type `V`, it is also defined for the types `boost::variant<T...>` and and for a tuple of type `V`, it is also defined for the types `boost::variant<T...>` and
`boost::optional<boost::variant<T...>>`, where `T...` `boost::optional<boost::variant<T...> >`, where `T...`
must be a subset of the parameters of `V`. Should the must be a subset of the parameters of `V`. Should the
`boost::optional` be empty, it will be discarded. `boost::optional` be empty, it will be discarded.
@ -195,12 +195,12 @@ The class `Dispatch_output_iterator` defines an
dispatches among those based on the type of the value type which is dispatches among those based on the type of the value type which is
put in it. Other types are also accepted, and the object is put in it. Other types are also accepted, and the object is
discarded in this case. Besides defining assignment for all discarded in this case. Besides defining assignment for all
parameters of V and for a tuple of type `V`, it is also defined for the types parameters of `V` and for a tuple of type `V`, it is also defined for the types
`boost::variant<T...` and `boost::variant<T...>` and
`boost::optional<boost::variant<T...>`, where `T...` `boost::optional<boost::variant<T...> >`, where `T...`
can be a list of arbitrary types. can be a list of arbitrary types.
It also inherits from `O, which makes it easy to treat like a It also inherits from `O`, which makes it easy to treat like a
tuple. tuple.
\cgalHeading{Parameters} \cgalHeading{Parameters}

View File

@ -1271,7 +1271,7 @@ struct Derivator<D, cpp11::tuple<V1, V...>, cpp11::tuple<O1, O...> >
// OutputIterator which accepts several types in *o++= and dispatches, // OutputIterator which accepts several types in *o++= and dispatches,
// wraps several other outputiterators, and dispatches accordingly. // wraps several other output iterators, and dispatches accordingly.
template < typename V, typename O > template < typename V, typename O >
class Dispatch_output_iterator; class Dispatch_output_iterator;