Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64115 - in sandbox/geometry: boost/geometry/algorithms libs/geometry/test/algorithms libs/geometry/test/geometries libs/geometry/test/test_geometries
From: barend.gehrels_at_[hidden]
Date: 2010-07-17 16:59:31


Author: barendgehrels
Date: 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
New Revision: 64115
URL: http://svn.boost.org/trac/boost/changeset/64115

Log:
Fixed old issue that only geometry::segment could be used in distance
Splitted custom segment, moved to separate header
Added:
   sandbox/geometry/libs/geometry/test/test_geometries/custom_segment.hpp (contents, props changed)
Text files modified:
   sandbox/geometry/boost/geometry/algorithms/distance.hpp | 8 +++++---
   sandbox/geometry/libs/geometry/test/algorithms/distance.cpp | 12 ++++++++----
   sandbox/geometry/libs/geometry/test/geometries/segment.cpp | 35 ++++++-----------------------------
   sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp | 19 ++++++++-----------
   4 files changed, 27 insertions(+), 47 deletions(-)

Modified: sandbox/geometry/boost/geometry/algorithms/distance.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/algorithms/distance.hpp (original)
+++ sandbox/geometry/boost/geometry/algorithms/distance.hpp 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
@@ -24,6 +24,7 @@
 
 #include <boost/geometry/strategies/distance.hpp>
 #include <boost/geometry/strategies/distance_result.hpp>
+#include <boost/geometry/algorithms/assign.hpp>
 #include <boost/geometry/algorithms/within.hpp>
 
 
@@ -97,9 +98,10 @@
                 Strategy
>::type segment_strategy;
 
- // See remark below.
- // TODO: avoid .first, .second
- return segment_strategy.apply(point, segment.first, segment.second);
+ typename point_type<Segment>::type p[2];
+ geometry::assign_point_from_index<0>(segment, p[0]);
+ geometry::assign_point_from_index<1>(segment, p[1]);
+ return segment_strategy.apply(point, p[0], p[1]);
     }
 };
 

Modified: sandbox/geometry/libs/geometry/test/algorithms/distance.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/algorithms/distance.cpp (original)
+++ sandbox/geometry/libs/geometry/test/algorithms/distance.cpp 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
@@ -20,6 +20,7 @@
 #include <boost/geometry/geometries/adapted/tuple_cartesian.hpp>
 
 #include <test_common/test_point.hpp>
+#include <test_geometries/custom_segment.hpp>
 #include <test_geometries/wrapped_boost_array.hpp>
 
 
@@ -134,10 +135,11 @@
 
 
 template <typename P>
-void test_distance_linestring()
+void test_distance_array_as_linestring()
 {
     typedef typename bg::distance_result<P>::type return_type;
 
+ // Normal array does not have
     boost::array<P, 2> points;
     bg::set<0>(points[0], 1);
     bg::set<1>(points[0], 1);
@@ -164,7 +166,10 @@
 {
     test_distance_point<P>();
     test_distance_segment<P>();
- test_distance_linestring<P>();
+ test_distance_array_as_linestring<P>();
+
+ test_geometry<P, test::custom_segment>("POINT(1 3)", "LINESTRING(1 1,4 4)", sqrt(2.0));
+ test_geometry<P, test::custom_segment>("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
 
     test_geometry<P, P>("POINT(1 1)", "POINT(2 2)", sqrt(2.0));
     test_geometry<P, P>("POINT(0 0)", "POINT(0 3)", 3.0);
@@ -172,13 +177,12 @@
     test_geometry<P, P>("POINT(0 3)", "POINT(4 0)", 5.0);
     test_geometry<P, bg::linestring<P> >("POINT(1 3)", "LINESTRING(1 1,4 4)", sqrt(2.0));
     test_geometry<P, bg::linestring<P> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
+ test_geometry<bg::linestring<P>, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0));
 
     // This one COMPILES but should THROW - because boost::array is not variably sized
     //test_geometry<P, boost::array<P, 2> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
 
     test_geometry<P, test::wrapped_boost_array<P, 2> >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0));
-
- test_geometry<bg::linestring<P>, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0));
 }
 
 int test_main(int, char* [])

Modified: sandbox/geometry/libs/geometry/test/geometries/segment.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/geometries/segment.cpp (original)
+++ sandbox/geometry/libs/geometry/test/geometries/segment.cpp 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
@@ -15,8 +15,6 @@
 #include <boost/geometry/geometries/point.hpp>
 #include <boost/geometry/geometries/segment.hpp>
 
-#include <boost/geometry/geometries/register/point.hpp>
-#include <boost/geometry/geometries/register/segment.hpp>
 
 #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
 #include <boost/geometry/geometries/adapted/tuple_cartesian.hpp>
@@ -25,6 +23,7 @@
 
 
 #include <test_common/test_point.hpp>
+#include <test_geometries/custom_segment.hpp>
 
 
 template <typename P>
@@ -48,7 +47,7 @@
 
     //std::cout << sizeof(typename coordinate_type<S>::type) << std::endl;
 
- typedef boost::geometry::segment<const P> CS;
+ typedef boost::geometry::segment<P const> CS;
     //BOOST_CONCEPT_ASSERT( (concept::ConstSegment<CS>) );
 
     CS cs(p1, p2);
@@ -57,28 +56,6 @@
     typedef typename boost::geometry::point_type<CS>::type CSP;
 }
 
-struct custom_point
-{
- double x, y;
-};
-struct custom_segment
-{
- custom_point one, two;
-};
-template <typename P>
-struct custom_segment_of
-{
- P p1, p2;
-};
-struct custom_segment_4
-{
- double a, b, c, d;
-};
-
-BOOST_GEOMETRY_REGISTER_POINT_2D(custom_point, double, boost::geometry::cs::cartesian, x, y)
-BOOST_GEOMETRY_REGISTER_SEGMENT(custom_segment, custom_point, one, two)
-BOOST_GEOMETRY_REGISTER_SEGMENT_TEMPLATIZED(custom_segment_of, p1, p2)
-BOOST_GEOMETRY_REGISTER_SEGMENT_2D_4VALUES(custom_segment_4, custom_point, a, b, c, d)
 
 
 template <typename S>
@@ -105,10 +82,10 @@
     test_all<boost::geometry::point<float, 3, boost::geometry::cs::cartesian> >();
     test_all<boost::geometry::point<double, 3, boost::geometry::cs::cartesian> >();
 
- test_custom<custom_segment>();
- test_custom<custom_segment_of<boost::geometry::point<double, 2, boost::geometry::cs::cartesian> > >();
- test_custom<custom_segment_of<custom_point> >();
- test_custom<custom_segment_4>();
+ test_custom<test::custom_segment>();
+ test_custom<test::custom_segment_of<boost::geometry::point<double, 2, boost::geometry::cs::cartesian> > >();
+ test_custom<test::custom_segment_of<test::custom_point_for_segment> >();
+ test_custom<test::custom_segment_4>();
 
     return 0;
 }

Added: sandbox/geometry/libs/geometry/test/test_geometries/custom_segment.hpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/test/test_geometries/custom_segment.hpp 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
@@ -0,0 +1,56 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library) test file
+//
+// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy ar
+// http://www.boost.org/LICENSE_1_0.txt)
+
+
+#ifndef GEOMETRY_TEST_TEST_GEOMETRIES_CUSTOM_SEGMENT_HPP
+#define GEOMETRY_TEST_TEST_GEOMETRIES_CUSTOM_SEGMENT_HPP
+
+
+#include <boost/geometry/geometries/register/point.hpp>
+#include <boost/geometry/geometries/register/segment.hpp>
+
+#include <boost/geometry/core/tag.hpp>
+#include <boost/geometry/core/tags.hpp>
+
+
+namespace test
+{
+
+struct custom_point_for_segment
+{
+ double x, y;
+};
+
+
+struct custom_segment
+{
+ custom_point_for_segment one, two;
+};
+
+template <typename P>
+struct custom_segment_of
+{
+ P p1, p2;
+};
+
+struct custom_segment_4
+{
+ double a, b, c, d;
+};
+
+
+} // namespace test
+
+
+BOOST_GEOMETRY_REGISTER_POINT_2D(test::custom_point_for_segment, double, boost::geometry::cs::cartesian, x, y)
+
+BOOST_GEOMETRY_REGISTER_SEGMENT(test::custom_segment, test::custom_point_for_segment, one, two)
+BOOST_GEOMETRY_REGISTER_SEGMENT_TEMPLATIZED(test::custom_segment_of, p1, p2)
+BOOST_GEOMETRY_REGISTER_SEGMENT_2D_4VALUES(test::custom_segment_4, test::custom_point_for_segment, a, b, c, d)
+
+
+#endif // GEOMETRY_TEST_TEST_GEOMETRIES_CUSTOM_SEGMENT_HPP

Modified: sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp
==============================================================================
--- sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp (original)
+++ sandbox/geometry/libs/geometry/test/test_geometries/wrapped_boost_array.hpp 2010-07-17 16:59:30 EDT (Sat, 17 Jul 2010)
@@ -10,9 +10,6 @@
 #define GEOMETRY_TEST_TEST_GEOMETRIES_WRAPPED_BOOST_ARRAY_HPP
 
 #include <cstddef>
-#include <vector>
-#include <boost/array.hpp>
-
 
 #include <boost/array.hpp>
 #include <boost/range.hpp>
@@ -63,7 +60,7 @@
     template <typename Point, std::size_t Count>
     inline typename boost::range_iterator
         <
- wrapped_boost_array<Point, Count>
+ wrapped_boost_array<Point, Count>
>::type range_begin(wrapped_boost_array<Point, Count>& ar)
     {
         return ar.array.begin();
@@ -86,7 +83,7 @@
     {
         typename boost::range_iterator
             <
- wrapped_boost_array<Point, Count>
+ wrapped_boost_array<Point, Count>
>::type it = ar.array.begin();
         return it + ar.size;
     }
@@ -141,22 +138,22 @@
 public:
 
     typedef test::wrapped_boost_array<Point, Count> container_type;
- typedef back_insert_iterator<container_type> this_type;
+ typedef back_insert_iterator<container_type> this_type;
 
- explicit back_insert_iterator(container_type& ar)
+ explicit back_insert_iterator(container_type& ar)
         : m_current(boost::begin(ar) + ar.size)
         , m_array(ar)
     {}
 
- inline this_type& operator=(Point const& value)
- {
+ inline this_type& operator=(Point const& value)
+ {
         // Check if not passed beyond
         if (m_array.size < Count)
         {
- *m_current++ = value;
+ *m_current++ = value;
             m_array.size++;
         }
- return *this;
+ return *this;
     }
 
     // Boiler-plate


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