Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76499 - in trunk/boost/geometry: algorithms algorithms/detail views/detail
From: barend.gehrels_at_[hidden]
Date: 2012-01-14 17:25:54


Author: barendgehrels
Date: 2012-01-14 17:25:53 EST (Sat, 14 Jan 2012)
New Revision: 76499
URL: http://svn.boost.org/trac/boost/changeset/76499

Log:
Added implementation for boxes
Text files modified:
   trunk/boost/geometry/algorithms/convex_hull.hpp | 34 ++++++++++++++++++++++++++++++++--
   trunk/boost/geometry/algorithms/detail/for_each_range.hpp | 27 +++++++++++++++++++++++++--
   trunk/boost/geometry/views/detail/range_type.hpp | 27 ++++++++++++++++++++-------
   3 files changed, 77 insertions(+), 11 deletions(-)

Modified: trunk/boost/geometry/algorithms/convex_hull.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/convex_hull.hpp (original)
+++ trunk/boost/geometry/algorithms/convex_hull.hpp 2012-01-14 17:25:53 EST (Sat, 14 Jan 2012)
@@ -14,7 +14,7 @@
 #ifndef BOOST_GEOMETRY_ALGORITHMS_CONVEX_HULL_HPP
 #define BOOST_GEOMETRY_ALGORITHMS_CONVEX_HULL_HPP
 
-
+#include <boost/array.hpp>
 
 #include <boost/geometry/core/cs.hpp>
 #include <boost/geometry/core/point_order.hpp>
@@ -29,6 +29,7 @@
 
 #include <boost/geometry/algorithms/num_points.hpp>
 #include <boost/geometry/algorithms/detail/as_range.hpp>
+#include <boost/geometry/algorithms/detail/assign_box_corners.hpp>
 
 
 namespace boost { namespace geometry
@@ -139,12 +140,41 @@
 template
 <
     typename Geometry,
- typename Strategy = typename detail::convex_hull::default_strategy<Geometry>::type
+ typename Strategy = typename detail::convex_hull::default_strategy<Geometry>::type,
+ typename Tag = typename tag<Geometry>::type
>
 struct convex_hull
     : detail::convex_hull::hull_to_geometry<Geometry, Strategy>
 {};
 
+template
+<
+ typename Box,
+ typename Strategy
+>
+struct convex_hull<Box, Strategy, box_tag>
+{
+ template <typename OutputGeometry>
+ static inline void apply(Box const& box, OutputGeometry& out,
+ Strategy const& )
+ {
+ static bool const Close
+ = geometry::closure<OutputGeometry>::value == closed;
+ static bool const Reverse
+ = geometry::point_order<OutputGeometry>::value == counterclockwise;
+
+ // A hull for boxes is trivial. Any strategy is (currently) skipped.
+ boost::array<typename point_type<Box>::type, 4> range;
+ geometry::detail::assign_box_corners_oriented<Reverse>(box, range);
+ geometry::append(out, range);
+ if (Close)
+ {
+ geometry::append(out, *boost::begin(range));
+ }
+ }
+};
+
+
 
 template
 <

Modified: trunk/boost/geometry/algorithms/detail/for_each_range.hpp
==============================================================================
--- trunk/boost/geometry/algorithms/detail/for_each_range.hpp (original)
+++ trunk/boost/geometry/algorithms/detail/for_each_range.hpp 2012-01-14 17:25:53 EST (Sat, 14 Jan 2012)
@@ -15,9 +15,9 @@
 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_FOR_EACH_RANGE_HPP
 
 
+#include <boost/mpl/assert.hpp>
 #include <boost/concept/requires.hpp>
 
-
 #include <boost/geometry/core/tag.hpp>
 #include <boost/geometry/core/tag_cast.hpp>
 
@@ -59,6 +59,17 @@
     }
 };
 
+template <typename Box, typename Actor, bool IsConst>
+struct fe_range_box
+{
+ static inline void apply(
+ typename add_const_if_c<IsConst, Box>::type& box,
+ Actor& actor)
+ {
+ actor.apply(box_view<Box>(box));
+ }
+};
+
 
 }} // namespace detail::for_each
 #endif // DOXYGEN_NO_DETAIL
@@ -76,7 +87,14 @@
     typename Actor,
     bool IsConst
>
-struct for_each_range {};
+struct for_each_range
+{
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (types<Geometry>)
+ );
+};
 
 
 template <typename Linestring, typename Actor, bool IsConst>
@@ -96,6 +114,11 @@
     : detail::for_each::fe_range_polygon<Polygon, Actor, IsConst>
 {};
 
+template <typename Box, typename Actor, bool IsConst>
+struct for_each_range<box_tag, Box, Actor, IsConst>
+ : detail::for_each::fe_range_box<Box, Actor, IsConst>
+{};
+
 
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH

Modified: trunk/boost/geometry/views/detail/range_type.hpp
==============================================================================
--- trunk/boost/geometry/views/detail/range_type.hpp (original)
+++ trunk/boost/geometry/views/detail/range_type.hpp 2012-01-14 17:25:53 EST (Sat, 14 Jan 2012)
@@ -15,12 +15,14 @@
 #define BOOST_GEOMETRY_VIEWS_DETAIL_RANGE_TYPE_HPP
 
 
+#include <boost/mpl/assert.hpp>
 #include <boost/type_traits.hpp>
 
 #include <boost/geometry/core/ring_type.hpp>
 #include <boost/geometry/core/tag.hpp>
 #include <boost/geometry/core/tags.hpp>
 
+#include <boost/geometry/views/box_view.hpp>
 
 namespace boost { namespace geometry
 {
@@ -34,19 +36,24 @@
 template <typename GeometryTag, typename Geometry>
 struct range_type
 {
- // Even if it is not recognized, define itself as a type.
- // This enables calling range_type over any range
- // (not necessarily a geometry)
+ BOOST_MPL_ASSERT_MSG
+ (
+ false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
+ , (types<Geometry>)
+ );
+};
+
 
- // Furthermore, applicable for ring/linestring
+template <typename Geometry>
+struct range_type<ring_tag, Geometry>
+{
     typedef Geometry type;
 };
 
-
 template <typename Geometry>
-struct range_type<point_tag, Geometry>
+struct range_type<linestring_tag, Geometry>
 {
- typedef void type;
+ typedef Geometry type;
 };
 
 
@@ -56,6 +63,12 @@
     typedef typename ring_type<Geometry>::type type;
 };
 
+template <typename Geometry>
+struct range_type<box_tag, Geometry>
+{
+ typedef typename box_view<Geometry> type;
+};
+
 
 } // namespace dispatch
 #endif // DOXYGEN_NO_DISPATCH


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