mirror of https://github.com/CGAL/cgal
replace \code with real examples
This commit is contained in:
parent
2a78cd495e
commit
1f989622e7
|
|
@ -1564,6 +1564,7 @@ intersection(const typename K::Segment_3 &seg,
|
|||
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>(
|
||||
Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,9 +127,9 @@ depending on the arguments.
|
|||
|
||||
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.
|
||||
|
||||
<DIV ALIGN="CENTER">
|
||||
|
|
@ -217,9 +217,9 @@ It is equivalent to `boost::optional< boost::variant< T... > >`, the last column
|
|||
</TABLE>
|
||||
</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.
|
||||
|
||||
<DIV ALIGN="CENTER">
|
||||
|
|
@ -316,57 +316,30 @@ p <TD>Point_3, or Segment_3</TD>
|
|||
</TABLE>
|
||||
</DIV>
|
||||
|
||||
\cgalHeading{Example}
|
||||
\cgalHeading{Examples}
|
||||
|
||||
The following example demonstrates the most common use of
|
||||
`intersection` routines with the 2D and 3D Linear %Kernel.
|
||||
The following examples demonstrate the most common use of
|
||||
`intersection()` functions with the 2D and 3D Linear %Kernel.
|
||||
|
||||
\code
|
||||
#include <CGAL/intersections.h>
|
||||
In the first two examples we intersect a segment and a line.
|
||||
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>
|
||||
struct Intersection_visitor {
|
||||
typedef void result_type;
|
||||
void operator()(const Point_2<R>& p) const
|
||||
{
|
||||
// handle point
|
||||
}
|
||||
void operator()(const Segment_2<R>& s) const
|
||||
{
|
||||
// handle segment
|
||||
}
|
||||
};
|
||||
<A HREF="http://www.boost.org/libs/optional/">`boost::optional`</A> comes in
|
||||
as there might be no intersection. <A HREF="http://www.boost.org/libs/variant/">`boost::variant`</A> comes in
|
||||
as, if there is an intersection, it is either a point or a segment.
|
||||
|
||||
template <typename R>
|
||||
void foo (const Segment_2<R>& seg, const Line_2<R>& lin)
|
||||
{
|
||||
// with C++11 support
|
||||
// auto result = intersection(seg, lin);
|
||||
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`.
|
||||
|
||||
// without C++11
|
||||
cpp11::result_of<R::Intersect_2(Segment_2<R>, Line_2<R>)>::type
|
||||
result = intersection(seg, lin);
|
||||
\cgalExample{Kernel_23/intersection_get.cpp}
|
||||
|
||||
if (result) { boost::apply_visitor(Intersection_visitor(), *result); }
|
||||
else {
|
||||
// no intersection
|
||||
}
|
||||
The second example uses`boost::apply_visitor`.
|
||||
|
||||
// alternatively:
|
||||
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
|
||||
\cgalExample{Kernel_23/intersection_visitor.cpp}
|
||||
|
||||
|
||||
Another example showing the use of the intersection function as a
|
||||
plain function call and with `Dispatch_output_iterator` combined with
|
||||
A third example shows the use of the intersection function as a
|
||||
plain function call and with `Dispatch_output_iterator`, combined with
|
||||
a standard library algorithm.
|
||||
|
||||
\cgalExample{Kernel_23/intersections.cpp}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
\example Kernel_23/MyKernel.cpp
|
||||
\example Filtered_kernel/Filtered_predicate.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/points_and_segment.cpp
|
||||
\example Kernel_23/surprising.cpp
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/intersections.h>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/iterator.h>
|
||||
#include <CGAL/point_generators_2.h>
|
||||
|
||||
#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::Segment_2 Segment;
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ int main()
|
|||
std::vector<Segment> segments;
|
||||
|
||||
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> > > >
|
||||
Dispatcher;
|
||||
|
||||
|
|
|
|||
|
|
@ -195,12 +195,12 @@ The class `Dispatch_output_iterator` defines an
|
|||
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
|
||||
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
|
||||
`boost::variant<T...` and
|
||||
`boost::optional<boost::variant<T...>`, where `T...`
|
||||
parameters of `V` 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...`
|
||||
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.
|
||||
|
||||
\cgalHeading{Parameters}
|
||||
|
|
|
|||
Loading…
Reference in New Issue