Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84292 - in trunk/boost/geometry/index: . detail detail/algorithms
From: adam.wulkiewicz_at_[hidden]
Date: 2013-05-15 19:24:57


Author: awulkiew
Date: 2013-05-15 19:24:56 EDT (Wed, 15 May 2013)
New Revision: 84292
URL: http://svn.boost.org/trac/boost/changeset/84292

Log:
geometry.index: added handling of Segments to path queries.
Text files modified:
   trunk/boost/geometry/index/detail/algorithms/path_intersection.hpp | 50 +++++++++++++++++++++++++++------------
   trunk/boost/geometry/index/detail/distance_predicates.hpp | 10 ++++----
   trunk/boost/geometry/index/detail/predicates.hpp | 8 +++---
   trunk/boost/geometry/index/predicates.hpp | 18 +++++++-------
   4 files changed, 52 insertions(+), 34 deletions(-)

Modified: trunk/boost/geometry/index/detail/algorithms/path_intersection.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/algorithms/path_intersection.hpp (original)
+++ trunk/boost/geometry/index/detail/algorithms/path_intersection.hpp 2013-05-15 19:24:56 EDT (Wed, 15 May 2013)
@@ -17,24 +17,33 @@
 
 namespace dispatch {
 
-template <typename Indexable, typename LineString, typename Tag>
+template <typename Indexable, typename Geometry, typename IndexableTag, typename GeometryTag>
 struct path_intersection
 {
- BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_GEOMETRY, (path_intersection));
+ BOOST_MPL_ASSERT_MSG((false), NOT_IMPLEMENTED_FOR_THIS_GEOMETRY_OR_INDEXABLE, (path_intersection));
 };
 
-template <typename Indexable, typename Linestring>
-struct path_intersection<Indexable, Linestring, point_tag>
+template <typename Indexable, typename Segment>
+struct path_intersection<Indexable, Segment, box_tag, segment_tag>
 {
- BOOST_MPL_ASSERT_MSG((false), SEGMENT_POINT_INTERSECTION_UNAVAILABLE, (path_intersection));
+ typedef typename default_distance_result<typename ::boost::geometry::traits::point_type<Segment>::type>::type comparable_distance_type;
+
+ static inline bool apply(Indexable const& b, Segment const& segment, comparable_distance_type & comparable_distance)
+ {
+ typedef typename ::boost::geometry::traits::point_type<Segment>::type point_type;
+ point_type p1, p2;
+ geometry::detail::assign_point_from_index<0>(segment, p1);
+ geometry::detail::assign_point_from_index<1>(segment, p2);
+ return index::detail::segment_intersection(b, p1, p2, comparable_distance);
+ }
 };
 
 template <typename Indexable, typename Linestring>
-struct path_intersection<Indexable, Linestring, box_tag>
+struct path_intersection<Indexable, Linestring, box_tag, linestring_tag>
 {
- typedef typename default_length_result<Linestring>::type length_type;
+ typedef typename default_length_result<Linestring>::type comparable_distance_type;
 
- static inline bool apply(Indexable const& b, Linestring const& path, length_type & comparable_distance)
+ static inline bool apply(Indexable const& b, Linestring const& path, comparable_distance_type & comparable_distance)
     {
         typedef typename ::boost::range_value<Linestring>::type point_type;
         typedef typename ::boost::range_const_iterator<Linestring>::type const_iterator;
@@ -59,7 +68,7 @@
                 typename default_distance_result<point_type, point_type>::type
                     dist = geometry::distance(*it0, *it1);
 
- length_type rel_dist;
+ comparable_distance_type rel_dist;
                 if ( index::detail::segment_intersection(b, *it0, *it1, rel_dist) )
                 {
                     comparable_distance += dist * rel_dist;
@@ -76,19 +85,28 @@
 
 } // namespace dispatch
 
-// TODO - change the name e.g. to path_intersection_distance
-// and segment_intersection e.g. to segment_intersection_relative_distance
+template <typename Indexable, typename SegmentOrLinestring>
+struct default_path_intersection_distance_type
+{
+ typedef typename dispatch::path_intersection<
+ Indexable, SegmentOrLinestring,
+ typename detail::traits::tag<Indexable>::type,
+ typename detail::traits::tag<SegmentOrLinestring>::type
+ >::comparable_distance_type type;
+};
 
-template <typename Indexable, typename Linestring> inline
+template <typename Indexable, typename SegmentOrLinestring> inline
 bool path_intersection(Indexable const& b,
- Linestring const& path,
- typename default_length_result<Linestring>::type & distance)
+ SegmentOrLinestring const& path,
+ typename default_path_intersection_distance_type<Indexable, SegmentOrLinestring>::type & comparable_distance)
 {
     // TODO check Indexable and Linestring concepts
 
     return dispatch::path_intersection<
- Indexable, Linestring, typename detail::traits::tag<Indexable>::type
- >::apply(b, path, distance);
+ Indexable, SegmentOrLinestring,
+ typename detail::traits::tag<Indexable>::type,
+ typename detail::traits::tag<SegmentOrLinestring>::type
+ >::apply(b, path, comparable_distance);
 }
 
 }}}} // namespace boost::geometry::index::detail

Modified: trunk/boost/geometry/index/detail/distance_predicates.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/distance_predicates.hpp (original)
+++ trunk/boost/geometry/index/detail/distance_predicates.hpp 2013-05-15 19:24:56 EDT (Wed, 15 May 2013)
@@ -143,14 +143,14 @@
     }
 };
 
-template <typename Linestring, typename Indexable, typename Tag>
-struct calculate_distance< path<Linestring>, Indexable, Tag>
+template <typename SegmentOrLinestring, typename Indexable, typename Tag>
+struct calculate_distance< path<SegmentOrLinestring>, Indexable, Tag>
 {
- typedef typename geometry::default_length_result<Linestring>::type result_type;
+ typedef typename geometry::default_length_result<SegmentOrLinestring>::type result_type;
 
- static inline bool apply(path<Linestring> const& p, Indexable const& i, result_type & result)
+ static inline bool apply(path<SegmentOrLinestring> const& p, Indexable const& i, result_type & result)
     {
- return index::detail::path_intersection(i, p.linestring, result);
+ return index::detail::path_intersection(i, p.geometry, result);
     }
 };
 

Modified: trunk/boost/geometry/index/detail/predicates.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/predicates.hpp (original)
+++ trunk/boost/geometry/index/detail/predicates.hpp 2013-05-15 19:24:56 EDT (Wed, 15 May 2013)
@@ -151,14 +151,14 @@
     unsigned count;
 };
 
-template <typename Linestring>
+template <typename SegmentOrLinestring>
 struct path
 {
- path(Linestring const& ls, unsigned k)
- : linestring(ls)
+ path(SegmentOrLinestring const& g, unsigned k)
+ : geometry(g)
         , count(k)
     {}
- Linestring linestring;
+ SegmentOrLinestring geometry;
     unsigned count;
 };
 

Modified: trunk/boost/geometry/index/predicates.hpp
==============================================================================
--- trunk/boost/geometry/index/predicates.hpp (original)
+++ trunk/boost/geometry/index/predicates.hpp 2013-05-15 19:24:56 EDT (Wed, 15 May 2013)
@@ -240,14 +240,14 @@
 /*!
 \brief Generate path() predicate.
 
-When path predicate is passed to the query, the returned values are k values on the path closest to
-its begin. \c path() predicate takes a \c Linestring defining the path and the maximum
+When path predicate is passed to the query, the returned values are k values along the path closest to
+its begin. \c path() predicate takes a \c Segment or a \c Linestring defining the path and the maximum
 number of \c Values that should be returned.
 
 \par Example
 \verbatim
-bgi::query(spatial_index, bgi::path(pt, 5), std::back_inserter(result));
-bgi::query(spatial_index, bgi::path(pt, 5) && bgi::intersects(box), std::back_inserter(result));
+bgi::query(spatial_index, bgi::path(segment, 5), std::back_inserter(result));
+bgi::query(spatial_index, bgi::path(linestring, 5) && bgi::intersects(box), std::back_inserter(result));
 \endverbatim
 
 \warning
@@ -255,14 +255,14 @@
 
 \ingroup predicates
 
-\param point The point from which distance is calculated.
+\param linestring The path along which distance is calculated.
 \param k The maximum number of values to return.
 */
-template <typename Linestring> inline
-detail::path<Linestring>
-path(Linestring const& linestring, unsigned k)
+template <typename SegmentOrLinestring> inline
+detail::path<SegmentOrLinestring>
+path(SegmentOrLinestring const& linestring, unsigned k)
 {
- return detail::path<Linestring>(linestring, k);
+ return detail::path<SegmentOrLinestring>(linestring, k);
 }
 
 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk