From 7380fda6322a32f4e076f3c62c8852e143962ded Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Sun, 2 May 2010 21:38:12 +0000 Subject: [PATCH] Implemented circular_iterator to reverse also backwards Reversed const std::string -> std::string const for consistency Default mirror tempate argument for map transformer Set embed manifest to false because of after-link errors, sometimes but not always, on VC2005 / Win7 / 64 bits [SVN r61739] --- .../geometry/iterators/circular_iterator.hpp | 24 ++++ .../iterators/ever_circling_iterator.hpp | 2 +- .../strategies/transform/map_transformer.hpp | 2 +- test/extensions/algorithms/midpoints.cpp | 4 +- test/extensions/algorithms/selected.cpp | 4 +- test/extensions/gis/latlong/parse_dms.cpp | 12 +- .../extensions/gis/projections/projection.cpp | 2 +- .../gis/projections/projections.cpp | 4 +- test/iterators/circular_iterator.cpp | 116 +++++++++--------- test/iterators/circular_iterator.vcproj | 2 + test/iterators/ever_circling_iterator.cpp | 2 +- test/iterators/ever_circling_iterator.vcproj | 2 + test/iterators/segment_iterator.cpp | 2 +- test/iterators/segment_iterator.vcproj | 2 + test/multi/algorithms/multi_distance.cpp | 6 +- 15 files changed, 111 insertions(+), 75 deletions(-) diff --git a/include/boost/geometry/iterators/circular_iterator.hpp b/include/boost/geometry/iterators/circular_iterator.hpp index db0d3a698..678929aac 100644 --- a/include/boost/geometry/iterators/circular_iterator.hpp +++ b/include/boost/geometry/iterators/circular_iterator.hpp @@ -15,6 +15,7 @@ #include + namespace boost { namespace geometry { @@ -68,6 +69,27 @@ private: check_end(); } } + inline void decrement() + { + if (this->base() != m_end) + { + // If at begin, go back to end (assumed this is possible...) + if (this->base() == m_begin) + { + this->base_reference() = this->m_end; + } + + // Decrement + (this->base_reference())--; + + // If really back at start, go to end == end of iteration + if (this->base() == m_start) + { + this->base_reference() = this->m_end; + } + } + } + inline void check_end() { @@ -87,6 +109,8 @@ private: Iterator m_start; }; + }} // namespace boost::geometry + #endif // BOOST_GEOMETRY_ITERATORS_CIRCULAR_ITERATOR_HPP diff --git a/include/boost/geometry/iterators/ever_circling_iterator.hpp b/include/boost/geometry/iterators/ever_circling_iterator.hpp index 8fe593c28..ddb58c471 100644 --- a/include/boost/geometry/iterators/ever_circling_iterator.hpp +++ b/include/boost/geometry/iterators/ever_circling_iterator.hpp @@ -56,7 +56,7 @@ struct ever_circling_iterator : this->base_reference() = start; } - /// Navigate to a certain position, should be in [start .. end], it at end + /// Navigate to a certain position, should be in [start .. end], if at end /// it will circle again. inline void moveto(Iterator it) { diff --git a/include/boost/geometry/strategies/transform/map_transformer.hpp b/include/boost/geometry/strategies/transform/map_transformer.hpp index dfeb63623..f454962c2 100644 --- a/include/boost/geometry/strategies/transform/map_transformer.hpp +++ b/include/boost/geometry/strategies/transform/map_transformer.hpp @@ -32,7 +32,7 @@ namespace strategy { namespace transform template < typename P1, typename P2, - bool Mirror, bool SameScale = true, + bool Mirror = false, bool SameScale = true, std::size_t Dimension1 = dimension::type::value, std::size_t Dimension2 = dimension::type::value > diff --git a/test/extensions/algorithms/midpoints.cpp b/test/extensions/algorithms/midpoints.cpp index 9d6a646c0..2a88b86a3 100644 --- a/test/extensions/algorithms/midpoints.cpp +++ b/test/extensions/algorithms/midpoints.cpp @@ -26,7 +26,7 @@ #include template -void test_midpoints(const G& g, bool start_and_end) +void test_midpoints(G const& g, bool start_and_end) { G processed; boost::geometry::midpoints(g, start_and_end, std::back_inserter(processed)); @@ -34,7 +34,7 @@ void test_midpoints(const G& g, bool start_and_end) } template -void test_midpoints(const std::string& wkt) +void test_midpoints(std::string const& wkt) { G g; boost::geometry::read_wkt(wkt, g); diff --git a/test/extensions/algorithms/selected.cpp b/test/extensions/algorithms/selected.cpp index fcc0709f0..4bb1e95ac 100644 --- a/test/extensions/algorithms/selected.cpp +++ b/test/extensions/algorithms/selected.cpp @@ -23,14 +23,14 @@ #include template -void test_selected(const G& g, const P& point, bool result, double dist) +void test_selected(G const& g, P const& point, bool result, double dist) { bool sel = boost::geometry::selected(g, point, dist); BOOST_CHECK_EQUAL(sel, result); } template -void test_selected(const std::string& wkt, const P& point, bool result, double dist) +void test_selected(std::string const& wkt, P const& point, bool result, double dist) { G g; boost::geometry::read_wkt(wkt, g); diff --git a/test/extensions/gis/latlong/parse_dms.cpp b/test/extensions/gis/latlong/parse_dms.cpp index 8655e077f..cb45740b4 100644 --- a/test/extensions/gis/latlong/parse_dms.cpp +++ b/test/extensions/gis/latlong/parse_dms.cpp @@ -16,36 +16,36 @@ -void check(const boost::geometry::dms_result& r, double v, int axis) +void check(boost::geometry::dms_result const& r, double v, int axis) { - const double d = r; + double const d = r; BOOST_CHECK_CLOSE(d, v, 0.0001); BOOST_CHECK(int(r.axis()) == axis); } template -void test_dms(const std::string& s, double v, int axis) +void test_dms(std::string const& s, double v, int axis) { boost::geometry::strategy::dms_parser parser; check(parser(s.c_str()), v, axis); } template -void test_dms_french(const std::string& s, double v, int axis) +void test_dms_french(std::string const& s, double v, int axis) { boost::geometry::strategy::dms_parser parser; check(parser(s.c_str()), v, axis); } template -void test_dms_dutch(const std::string& s, double v, int axis) +void test_dms_dutch(std::string const& s, double v, int axis) { boost::geometry::strategy::dms_parser parser; check(parser(s.c_str()), v, axis); } template -void test_dms_case(const std::string& s, double v, int axis) +void test_dms_case(std::string const& s, double v, int axis) { boost::geometry::strategy::dms_parser parser; check(parser(s.c_str()), v, axis); diff --git a/test/extensions/gis/projections/projection.cpp b/test/extensions/gis/projections/projection.cpp index b8c878cdb..20ead9e73 100644 --- a/test/extensions/gis/projections/projection.cpp +++ b/test/extensions/gis/projections/projection.cpp @@ -33,7 +33,7 @@ template void test_one(double lon, double lat, typename boost::geometry::coordinate_type::type x, typename boost::geometry::coordinate_type::type y, - const std::string& parameters) + std::string const& parameters) { boost::geometry::projection::parameters par = boost::geometry::projection::detail::pj_init_plus(parameters); Prj prj(par); diff --git a/test/extensions/gis/projections/projections.cpp b/test/extensions/gis/projections/projections.cpp index 8afb36219..98308bd54 100644 --- a/test/extensions/gis/projections/projections.cpp +++ b/test/extensions/gis/projections/projections.cpp @@ -47,7 +47,7 @@ void test_forward(std::string const& name, double lon, double lat, typename boost::geometry::coordinate_type

::type x, typename boost::geometry::coordinate_type

::type y, - const std::string& parameters) + std::string const& parameters) { typedef typename boost::geometry::coordinate_type

::type coord_type; typedef boost::geometry::point_ll > lonlat_type; @@ -75,7 +75,7 @@ void test_inverse(std::string const& name, typename boost::geometry::coordinate_type

::type x, typename boost::geometry::coordinate_type

::type y, double lon, double lat, - const std::string& parameters) + std::string const& parameters) { typedef typename boost::geometry::coordinate_type

::type coord_type; typedef boost::geometry::point_ll > lonlat_type; diff --git a/test/iterators/circular_iterator.cpp b/test/iterators/circular_iterator.cpp index 2cca1bfeb..05a83ad0d 100644 --- a/test/iterators/circular_iterator.cpp +++ b/test/iterators/circular_iterator.cpp @@ -19,8 +19,42 @@ #include #include + +template +void test_forward(Geometry const& geometry, CircularIterator end, + int offset, std::string const& expected) +{ + CircularIterator it(boost::begin(geometry), boost::end(geometry), + boost::begin(geometry) + offset); + + std::ostringstream out; + for (; it != end; ++it) + { + out << boost::geometry::get<0>(*it); + } + BOOST_CHECK_EQUAL(out.str(), expected); +} + + +template +void test_backward(Geometry const& geometry, CircularIterator end, + int offset, std::string const& expected) +{ + CircularIterator it(boost::begin(geometry), boost::end(geometry), + boost::begin(geometry) + offset); + + std::ostringstream out; + for (; it != end; --it) + { + out << boost::geometry::get<0>(*it); + } + BOOST_CHECK_EQUAL(out.str(), expected); +} + + + template -void test_geometry(const std::string& wkt) +void test_geometry(std::string const& wkt) { G geo; boost::geometry::read_wkt(wkt, geo); @@ -29,70 +63,42 @@ void test_geometry(const std::string& wkt) circular_iterator end(boost::end(geo)); + // 2: start somewhere in the middle (first == test before) + test_forward(geo, end, 0, "12345"); + test_forward(geo, end, 1, "23451"); + test_forward(geo, end, 2, "34512"); + test_forward(geo, end, 3, "45123"); + test_forward(geo, end, 4, "51234"); + + test_backward(geo, end, 0, "15432"); + test_backward(geo, end, 1, "21543"); + test_backward(geo, end, 2, "32154"); + test_backward(geo, end, 3, "43215"); + test_backward(geo, end, 4, "54321"); + + // 4: check copy behaviour + G copy; + + normal_iterator start = boost::begin(geo) + 2; + circular_iterator it(boost::begin(geo), boost::end(geo), start); + std::copy(it, end, std::back_inserter(copy)); + + std::ostringstream out; + for (normal_iterator cit = boost::begin(copy); cit != boost::end(copy); ++cit) { - // 1: normal start position - normal_iterator start = boost::begin(geo); - - std::ostringstream out; - for (circular_iterator it(boost::begin(geo), boost::end(geo), start); - it != end; ++it) - { - out << boost::geometry::get<0>(*it); - } - BOOST_CHECK_EQUAL(out.str(), "12345"); - } - - { - // 2: start somewhere in the middle - normal_iterator start = boost::begin(geo) + 2; - - std::ostringstream out; - for (circular_iterator it(boost::begin(geo), boost::end(geo), start); - it != end; ++it) - { - out << boost::geometry::get<0>(*it); - } - BOOST_CHECK_EQUAL(out.str(), "34512"); - } - - { - // 3: start at end position - normal_iterator start = boost::begin(geo) + boost::size(geo) - 1; - - std::ostringstream out; - for (circular_iterator it(boost::begin(geo), boost::end(geo), start); - it != end; ++it) - { - out << boost::geometry::get<0>(*it); - } - BOOST_CHECK_EQUAL(out.str(), "51234"); - } - - { - // 4: check copy behaviour - G copy; - - { - normal_iterator start = boost::begin(geo) + 2; - circular_iterator it(boost::begin(geo), boost::end(geo), start); - std::copy(it, end, std::back_inserter(copy)); - } - - std::ostringstream out; - for (normal_iterator cit = boost::begin(copy); cit != boost::end(copy); ++cit) - { - out << boost::geometry::get<0>(*cit); - } - BOOST_CHECK_EQUAL(out.str(), "34512"); + out << boost::geometry::get<0>(*cit); } + BOOST_CHECK_EQUAL(out.str(), "34512"); } + template void test_all() { test_geometry >("linestring(1 1,2 2,3 3,4 4,5 5)"); } + int test_main(int, char* []) { test_all(); diff --git a/test/iterators/circular_iterator.vcproj b/test/iterators/circular_iterator.vcproj index 5ce9ed750..24210a2a0 100644 --- a/test/iterators/circular_iterator.vcproj +++ b/test/iterators/circular_iterator.vcproj @@ -69,6 +69,7 @@ /> template -void test_geometry(const std::string& wkt) +void test_geometry(std::string const& wkt) { G geo; boost::geometry::read_wkt(wkt, geo); diff --git a/test/iterators/ever_circling_iterator.vcproj b/test/iterators/ever_circling_iterator.vcproj index 3f243eecd..ebeddee29 100644 --- a/test/iterators/ever_circling_iterator.vcproj +++ b/test/iterators/ever_circling_iterator.vcproj @@ -69,6 +69,7 @@ /> template -void test_linestring(const std::string& wkt, const std::string& expected) +void test_linestring(std::string const& wkt, std::string const& expected) { typedef C point_list; typedef typename C::value_type point; diff --git a/test/iterators/segment_iterator.vcproj b/test/iterators/segment_iterator.vcproj index aa801db22..442ac6988 100644 --- a/test/iterators/segment_iterator.vcproj +++ b/test/iterators/segment_iterator.vcproj @@ -68,6 +68,7 @@ /> -void test_distance(const std::string& wkt1, const std::string& wkt2, double expected) +void test_distance(std::string const& wkt1, std::string const& wkt2, double expected) { Geometry1 g1; Geometry2 g2; @@ -41,8 +41,8 @@ void test_distance(const std::string& wkt1, const std::string& wkt2, double expe } template -void test_distance(const Strategy& strategy, const std::string& wkt1, - const std::string& wkt2, double expected) +void test_distance(Strategy const& strategy, std::string const& wkt1, + std::string const& wkt2, double expected) { Geometry1 g1; Geometry2 g2;