From ece2fa38d4fe225313948cd95823e4307c77ce69 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 6 Dec 2012 17:54:34 +0100 Subject: [PATCH] examples no longer use Object --- .../Circular_kernel_2/intersecting_arcs.cpp | 4 +++- Kernel_23/doc/Kernel_23/CGAL/intersections.h | 22 ++++++++++--------- Kernel_23/doc/Kernel_23/Kernel_23.txt | 21 +++--------------- .../Kernel_23/cartesian_converter.cpp | 9 ++++++-- .../examples/Kernel_23/intersections.cpp | 22 ++++--------------- 5 files changed, 29 insertions(+), 49 deletions(-) diff --git a/Circular_kernel_2/examples/Circular_kernel_2/intersecting_arcs.cpp b/Circular_kernel_2/examples/Circular_kernel_2/intersecting_arcs.cpp index d9e9c3fa10f..994ffb98846 100644 --- a/Circular_kernel_2/examples/Circular_kernel_2/intersecting_arcs.cpp +++ b/Circular_kernel_2/examples/Circular_kernel_2/intersecting_arcs.cpp @@ -24,7 +24,9 @@ double prob_2() { if(CGAL::orientation(p4, p5, p6) != CGAL::COUNTERCLOCKWISE) std::swap(p4, p6); T o2 = T(p4, p5, p6); - std::vector< CGAL::Object > res; + typedef boost::result_of::type + Intersection_result; + std::vector res; CGAL::intersection(o1, o2, std::back_inserter(res)); prob += (res.size() != 0) ? 1.0 : 0.0; diff --git a/Kernel_23/doc/Kernel_23/CGAL/intersections.h b/Kernel_23/doc/Kernel_23/CGAL/intersections.h index 7e9f6c729d0..b3c00e84db4 100644 --- a/Kernel_23/doc/Kernel_23/CGAL/intersections.h +++ b/Kernel_23/doc/Kernel_23/CGAL/intersections.h @@ -169,7 +169,6 @@ bool do_intersect(Type1 obj1, Type2 obj2, Type - /*! \addtogroup intersection @@ -185,6 +184,7 @@ defined before any \cgal header is included. #define CGAL_INTERSECTION_VERSION + /*! \addtogroup intersection @@ -299,7 +299,7 @@ the value for `T...` in `boost::optional< boost::variant< - + @@ -382,7 +382,7 @@ the value for `T...` in `boost::optional< boost::variant<
Type1 Type2 Return Type: Object Return Type: `T...`
Iso_rectangle_2
- + @@ -565,8 +565,8 @@ on the arguments, the function expects an output iterator on `boost::result_of::type`, as presented below. - */ + /// @{ /*! @@ -619,6 +619,9 @@ intersection(const Type1 &obj1, const Type2 &obj2, When using a spherical kernel, in addition to the function overloads documented \ref intersection_linear "here", the following function overloads are also available. +The iterator versions of those functions can be used in conjunction +`Dispatch_output_iterator`. + Since both the number of intersections, if any, and their type, depend on the arguments, the functions expects an output iterator on `boost::result_of::type`, @@ -629,7 +632,7 @@ as presented below. /*! Copies in the output iterator the intersection elements between the two objects. `intersections` iterates on -elements of type `CGAL::Object`, in lexicographic order, +elements of type `result_of< Intersect_3(SphericalType1, SphericalType2) >`, in lexicographic order, when this ordering is defined on the computed objects, where `SphericalType1` and `SphericalType2` can both be either: @@ -643,7 +646,7 @@ where `SphericalType1` and `SphericalType2` can both be either: and depending on the types `SphericalType1` and `SphericalType2`, the computed -`CGAL::Object`s can be assigned to +type can be - `std::pair, unsigned>`, where the unsigned integer is the multiplicity of the corresponding @@ -668,7 +671,7 @@ intersection(const SphericalType1 &obj1, const SphericalType2 &obj2, /*! Copies in the output iterator the intersection elements between the three objects. `intersections` iterates on -elements of type `CGAL::Object`, in lexicographic order +elements of type `boost::variant< Circle_3, Plane_3, Sphere_3, std::pair< Circular_arc_point_3, unsigned > >`, in lexicographic order when this ordering is defined on the computed objects where `Type1`, `Type2` and `Type3` @@ -678,8 +681,7 @@ can be either - `Plane_3` -and depending of these types, the computed `CGAL::Object`s can be -assigned to +and depending of these types, the computed return value - `std::pair, unsigned>`, where the unsigned integer is the multiplicity of the corresponding @@ -689,7 +691,7 @@ assigned to `Type3` are equal, and if the three objets `obj1` and `obj2` and `obj3` are equal. */ -template < typename Type1, typename Type2, typename OutputIterator > + template < typename Type1, typename Type2, typename Type3, typename OutputIterator > OutputIterator intersection(const Type1 &obj1, const Type2 &obj2, const Type3 &obj3, OutputIterator intersections); diff --git a/Kernel_23/doc/Kernel_23/Kernel_23.txt b/Kernel_23/doc/Kernel_23/Kernel_23.txt index 044b0a02439..a2a966ec682 100644 --- a/Kernel_23/doc/Kernel_23/Kernel_23.txt +++ b/Kernel_23/doc/Kernel_23/Kernel_23.txt @@ -488,35 +488,20 @@ especially integer types and rationals. \subsection Kernel_23VariantReturnValues Intersections and Variant Return Types -Some functions can return different types of objects. To achieve this +Some functions, for example `intersection()`, can return different types of objects. To achieve this in a type safe way \cgal uses return values of type `boost::optional< boost::variant< T \ldots\ > >` were `T...` is a list of all possible resulting geometric objects. The exact result type of an intersection can be determined through the metafunction `boost::result_of` or `boost::result_of`, where -`Type1} and `Type2` are the types of the objects used in the +`Type1` and `Type2` are the types of the objects used in the intersection computation. See `boost::result_of` for more information about this mechanism. -Some functions can return different types of objects. A typical -\cpp 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 -`Object` provides an abstraction. -An object `obj` of the class `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 `Object` is *not* a common base class for the -elementary classes. Therefore, there is no -automatic conversion from these classes to `Object`. Rather -this is done with the global function `make_object()`. This -encapsulation mechanism requires the use of -`object_cast` to access the encapsulated class (a less -efficient way, which is now discouraged, used to be to -use the `assign` function). + Example ------- diff --git a/Kernel_23/examples/Kernel_23/cartesian_converter.cpp b/Kernel_23/examples/Kernel_23/cartesian_converter.cpp index 943c2acb18d..4d00a0089d3 100644 --- a/Kernel_23/examples/Kernel_23/cartesian_converter.cpp +++ b/Kernel_23/examples/Kernel_23/cartesian_converter.cpp @@ -25,8 +25,13 @@ int main(){ EK::Triangle_3 t2=to_exact(t1); EK::Line_3 l2=to_exact(l1); - CGAL::Object inter=CGAL::intersection(t2,l2); - const EK::Point_3& exact_pt=CGAL::object_cast(inter); + boost::result_of::type + inter = CGAL::intersection(t2,l2); + + // As we are sure that there IS an intersection + // and that the intersection IS a point + // we do not have to check for this, or put it in a try/catch + const EK::Point_3& exact_pt = boost::get(*inter); EK_to_IK to_inexact; diff --git a/Kernel_23/examples/Kernel_23/intersections.cpp b/Kernel_23/examples/Kernel_23/intersections.cpp index f41316f59b2..9659fad495a 100644 --- a/Kernel_23/examples/Kernel_23/intersections.cpp +++ b/Kernel_23/examples/Kernel_23/intersections.cpp @@ -17,7 +17,6 @@ typedef Random_points_on_circle_2 P2; typedef Creator_uniform_2< Point, Segment> Seg_creator; typedef Join_input_iterator_2< P1, P2, Seg_creator> Seg_iterator; -using boost::result_of; int main() { @@ -33,15 +32,6 @@ int main() Seg_iterator g( p1, p2); std::copy_n( g, 200, std::back_inserter(input)); - // intersection of two objects -#if !defined(CGAL_CFG_NO_CPP0X_AUTO) - // with C++11 - auto v = intersection(input.back(), input.front()); -#else - // without C++11 - result_of::type v - = intersection(input.back(), input.front()); -#endif // splitting results with Dispatch_output_iterator std::vector points; @@ -56,17 +46,13 @@ int main() std::back_inserter(segments) ); // intersections of many objects, directly dispatched -#if !defined(CGAL_CFG_NO_CPP0X_LAMBDA) - // with C++11 lambdas - auto& s1 = input.front(); - std::transform(input.begin(), input.end(), disp, - [&s1] (const Segment& s) { return intersection(s1, s); }); -#else - // without + // intersects the first segment of input with all other segments + // The resulting points or segments are written in the vectors with the same names + K::Intersect_2 intersector = K().intersect_2_object(); std::transform(input.begin(), input.end(), disp, boost::bind(intersector, input.front(), _1)); -#endif + std::cout << "Point intersections: " << points.size() << std::endl; std::cout << "Segment intersections: " << segments.size() << std::endl;
Type1 Type2 Return Type: Object Return Type: `T...`
Line_3