diff --git a/include/boost/geometry/algorithms/centroid.hpp b/include/boost/geometry/algorithms/centroid.hpp index d0c74e88c..a78f00114 100644 --- a/include/boost/geometry/algorithms/centroid.hpp +++ b/include/boost/geometry/algorithms/centroid.hpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include @@ -247,7 +247,7 @@ struct centroid_linestring typedef typename point_type::type point_type; typedef typename boost::range_iterator::type point_iterator_type; - typedef segment_iterator segment_iterator; + typedef segment_returning_iterator segment_iterator; double length = double(); std::pair average_sum; @@ -366,8 +366,8 @@ template struct centroid : detail::centroid::centroid_ring < - Ring, - Point, + Ring, + Point, geometry::closure::value, Strategy > diff --git a/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp b/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp index 471413ce4..0beda3d57 100644 --- a/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/clip_linestring.hpp @@ -157,14 +157,14 @@ template < typename OutputLinestring, typename OutputIterator, - typename Linestring, + typename Range, typename Box, typename Strategy > -OutputIterator clip_linestring_with_box(Box const& b, Linestring const& linestring, +OutputIterator clip_range_with_box(Box const& b, Range const& range, OutputIterator out, Strategy const& strategy) { - if (boost::begin(linestring) == boost::end(linestring)) + if (boost::begin(range) == boost::end(range)) { return out; } @@ -173,11 +173,11 @@ OutputIterator clip_linestring_with_box(Box const& b, Linestring const& linestri OutputLinestring line_out; - typedef typename boost::range_iterator::type iterator_type; - iterator_type vertex = boost::begin(linestring); + typedef typename boost::range_iterator::type iterator_type; + iterator_type vertex = boost::begin(range); for(iterator_type previous = vertex++; - vertex != boost::end(linestring); - previous = vertex++) + vertex != boost::end(range); + ++previous, ++vertex) { point_type p1, p2; copy_coordinates(*previous, p1); diff --git a/include/boost/geometry/algorithms/intersection.hpp b/include/boost/geometry/algorithms/intersection.hpp index 2836aa972..b2c156914 100644 --- a/include/boost/geometry/algorithms/intersection.hpp +++ b/include/boost/geometry/algorithms/intersection.hpp @@ -20,6 +20,7 @@ #include #include #include +#include @@ -87,15 +88,15 @@ namespace dispatch template < - typename Tag1, typename Tag2, typename Tag3, - typename G1, typename G2, + typename TagIn1, typename TagIn2, typename TagOut, + typename Geometry1, typename Geometry2, typename OutputIterator, typename GeometryOut, typename Strategy > struct intersection_inserter : detail::overlay::overlay - + {}; @@ -162,11 +163,38 @@ struct intersection_inserter { typedef typename point_type::type point_type; strategy::intersection::liang_barsky lb_strategy; - return detail::intersection::clip_linestring_with_box + return detail::intersection::clip_range_with_box (box, linestring, out, lb_strategy); } }; +template +< + typename Segment, typename Box, + typename OutputIterator, typename GeometryOut, + typename Strategy +> +struct intersection_inserter + < + segment_tag, box_tag, linestring_tag, + Segment, Box, + OutputIterator, GeometryOut, + Strategy + > +{ + static inline OutputIterator apply(Segment const& segment, + Box const& box, OutputIterator out, Strategy const& strategy) + { + typedef boost::geometry::segment_range range_type; + range_type range(segment); + + typedef typename point_type::type point_type; + strategy::intersection::liang_barsky lb_strategy; + return detail::intersection::clip_range_with_box + (box, range, out, lb_strategy); + } +}; + template < diff --git a/include/boost/geometry/extensions/io/svg/svg_mapper.hpp b/include/boost/geometry/extensions/io/svg/svg_mapper.hpp index ebb6668b9..2420c818f 100644 --- a/include/boost/geometry/extensions/io/svg/svg_mapper.hpp +++ b/include/boost/geometry/extensions/io/svg/svg_mapper.hpp @@ -12,10 +12,11 @@ #include - -#include -#include +#include #include +#include +#include +#include #include #include @@ -24,8 +25,8 @@ #include #include #include - #include +#include #include #include @@ -51,6 +52,11 @@ namespace dispatch template struct svg_map { + BOOST_MPL_ASSERT_MSG + ( + false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE + , (Geometry) + ); }; @@ -98,6 +104,23 @@ struct svg_map_range } }; +template +struct svg_map +{ + template + static inline void apply(std::ostream& stream, + std::string const& style, int size, + Segment const& segment, TransformStrategy const& strategy) + { + typedef boost::geometry::segment_range range_type; + range_type range(segment); + svg_map_range + < + range_type, + boost::geometry::linestring > + >::apply(stream, style, size, range, strategy); + } +}; template @@ -237,6 +260,18 @@ public : void map(Geometry const& geometry, std::string const& style, int size = -1) { + BOOST_MPL_ASSERT_MSG + ( + ( boost::is_same + < + Point, + typename boost::geometry::point_type::type + >::value ) + , POINT_TYPES_ARE_NOT_SAME_FOR_MAPPER_AND_MAP + , (types::type>) + ); + + init_matrix(); svg_map(m_stream, style, size, geometry, *m_matrix); } diff --git a/include/boost/geometry/extensions/io/svg/write_svg.hpp b/include/boost/geometry/extensions/io/svg/write_svg.hpp index 2409b3043..858c4a955 100644 --- a/include/boost/geometry/extensions/io/svg/write_svg.hpp +++ b/include/boost/geometry/extensions/io/svg/write_svg.hpp @@ -13,6 +13,7 @@ #include #include +#include #include @@ -192,7 +193,14 @@ template static inline void apply(std::basic_ostream& os, G const& geometry) */ template -struct svg {}; +struct svg +{ + BOOST_MPL_ASSERT_MSG + ( + false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE + , (Geometry) + ); +}; template struct svg : detail::svg::svg_point {}; diff --git a/include/boost/geometry/geometries/concepts/linestring_concept.hpp b/include/boost/geometry/geometries/concepts/linestring_concept.hpp index aae339091..e9b2d6ca5 100644 --- a/include/boost/geometry/geometries/concepts/linestring_concept.hpp +++ b/include/boost/geometry/geometries/concepts/linestring_concept.hpp @@ -102,7 +102,9 @@ class ConstLinestring typedef typename point_type::type point_type; BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); - BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept) ); + //BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept) ); + // Relaxed the concept. + BOOST_CONCEPT_ASSERT( (boost::ForwardRangeConcept) ); public : diff --git a/include/boost/geometry/iterators/segment_range_iterator.hpp b/include/boost/geometry/iterators/segment_range_iterator.hpp new file mode 100644 index 000000000..e344ac493 --- /dev/null +++ b/include/boost/geometry/iterators/segment_range_iterator.hpp @@ -0,0 +1,111 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// 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 at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_SEGMENT_RANGE_ITERATOR_HPP +#define BOOST_GEOMETRY_SEGMENT_RANGE_ITERATOR_HPP + +#include +#include +#include + +#include +#include + + +namespace boost { namespace geometry +{ + +/*! + \brief Iterator which adapts a segment (two points) as iterator + \tparam Segment segment type on which this iterator is based on + \note It is always const. We cannot dereference something non-const + (at least not without doing tricks as returning assignables) + \ingroup iterators +*/ +template +struct segment_range_iterator + : public boost::iterator_facade + < + segment_range_iterator, + typename point_type::type const, + boost::bidirectional_traversal_tag + > +{ + // Default constructor is required to check concept of Range + // (used in checking linestring/ring concepts) + inline segment_range_iterator() + : m_index(-1) + , m_segment_address(NULL) + { + } + + + explicit inline segment_range_iterator(Segment const& segment) + : m_index(0) + , m_segment_address(&segment) + { + init(segment); + } + + // Constructor to indicate the end of a segment + explicit inline segment_range_iterator(Segment const& segment, bool) + : m_index(2) + , m_segment_address(&segment) + { + init(segment); + } + +private: + friend class boost::iterator_core_access; + typedef typename point_type::type point_type; + + inline point_type const& dereference() const + { + if (m_index >= 0 && m_index <= 1) + { + return m_points[m_index]; + } + // Should not occur. Probably throw here. + // TODO decide + return m_points[0]; + } + + inline bool equal(segment_range_iterator const& other) const + { + return m_segment_address == this->m_segment_address + && other.m_index == this->m_index; + } + + inline void increment() + { + m_index++; + } + + inline void decrement() + { + m_index--; + } + + inline void init(Segment const& segment) + { + assign_point_from_index<0>(segment, m_points[0]); + assign_point_from_index<1>(segment, m_points[1]); + } + + // We HAVE TO copy the points, because a segment does not need + // to consist of two points, + // and we are expected to return a point here + point_type m_points[2]; + int m_index; + Segment const* const m_segment_address; +}; + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_SEGMENT_RANGE_ITERATOR_HPP diff --git a/include/boost/geometry/iterators/segment_iterator.hpp b/include/boost/geometry/iterators/segment_returning_iterator.hpp similarity index 73% rename from include/boost/geometry/iterators/segment_iterator.hpp rename to include/boost/geometry/iterators/segment_returning_iterator.hpp index 07e9fc3a0..d1b949334 100644 --- a/include/boost/geometry/iterators/segment_iterator.hpp +++ b/include/boost/geometry/iterators/segment_returning_iterator.hpp @@ -7,8 +7,8 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#ifndef BOOST_GEOMETRY_ITERATORS_SEGMENT_ITERATOR_HPP -#define BOOST_GEOMETRY_ITERATORS_SEGMENT_ITERATOR_HPP +#ifndef BOOST_GEOMETRY_ITERATORS_SEGMENT_RETURNING_ITERATOR_HPP +#define BOOST_GEOMETRY_ITERATORS_SEGMENT_RETURNING_ITERATOR_HPP // TODO: This is very experimental version of input iterator // reading collection of points as segments - proof of concept. @@ -30,7 +30,7 @@ namespace boost { namespace geometry { template -struct segment_iterator +struct segment_returning_iterator { typedef Base base_type; typedef Point point_type; @@ -42,7 +42,7 @@ struct segment_iterator typedef segment_type* pointer; typedef segment_type& reference; - explicit segment_iterator(Base const& end) + explicit segment_returning_iterator(Base const& end) : m_segment(p1 , p2) , m_prev(end) , m_it(end) @@ -50,7 +50,7 @@ struct segment_iterator { } - segment_iterator(Base const& it, Base const& end) + segment_returning_iterator(Base const& it, Base const& end) : m_segment(p1 , p2) , m_prev(it) , m_it(it) @@ -78,16 +78,16 @@ struct segment_iterator return &(operator*()); } - segment_iterator& operator++() + segment_returning_iterator& operator++() { ++m_prev; ++m_it; return *this; } - segment_iterator operator++(int) + segment_returning_iterator operator++(int) { - segment_iterator it(*this); + segment_returning_iterator it(*this); ++(*this); return it; } @@ -106,32 +106,32 @@ private: }; template -bool operator==(segment_iterator const& lhs, - segment_iterator const& rhs) +bool operator==(segment_returning_iterator const& lhs, + segment_returning_iterator const& rhs) { return (lhs.base() == rhs.base()); } template -bool operator!=(segment_iterator const& lhs, - segment_iterator const& rhs) +bool operator!=(segment_returning_iterator const& lhs, + segment_returning_iterator const& rhs) { return (lhs.base() != rhs.base()); } template -segment_iterator +inline segment_returning_iterator < typename C::iterator, typename C::value_type > -make_segment_iterator(C& c) +make_segment_returning_iterator(C& c) { typedef typename C::iterator base_iterator; typedef typename C::value_type point_type; - return segment_iterator(c.begin(), c.end()); + return segment_returning_iterator(c.begin(), c.end()); } }} // namespace boost::geometry -#endif // BOOST_GEOMETRY_ITERATORS_SEGMENT_ITERATOR_HPP +#endif // BOOST_GEOMETRY_ITERATORS_SEGMENT_RETURNING_ITERATOR_HPP diff --git a/include/boost/geometry/ranges/box_range.hpp b/include/boost/geometry/ranges/box_range.hpp new file mode 100644 index 000000000..7c3ffe365 --- /dev/null +++ b/include/boost/geometry/ranges/box_range.hpp @@ -0,0 +1,61 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// 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 at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_RANGES_BOX_RANGE_HPP +#define BOOST_GEOMETRY_RANGES_BOX_RANGE_HPP + + +#include + +#include + + +namespace boost { namespace geometry +{ + + +template +class box_range +{ +public : + typedef box_iterator const_iterator; + typedef box_iterator iterator; // must be defined + + explicit box_range(Box const& box) + : m_begin(const_iterator(box)) + , m_end(const_iterator(box, true)) + { + } + + const_iterator begin() const { return m_begin; } + const_iterator end() const { return m_end; } + + // It may not be used non-const, so comment this: + //iterator begin() { return m_begin; } + //iterator end() { return m_end; } + +private : + const_iterator m_begin, m_end; +}; + + +// All box ranges can be handled as linestrings +namespace traits +{ + template + struct tag > + { + typedef ring_tag type; + }; +} + + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_RANGES_BOX_RANGE_HPP diff --git a/include/boost/geometry/ranges/segment_range.hpp b/include/boost/geometry/ranges/segment_range.hpp new file mode 100644 index 000000000..76859fcbf --- /dev/null +++ b/include/boost/geometry/ranges/segment_range.hpp @@ -0,0 +1,61 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) +// +// 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 at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_RANGES_SEGMENT_RANGE_HPP +#define BOOST_GEOMETRY_RANGES_SEGMENT_RANGE_HPP + + +#include + +#include + + +namespace boost { namespace geometry +{ + + +template +class segment_range +{ +public : + typedef segment_range_iterator const_iterator; + typedef segment_range_iterator iterator; // must be defined + + explicit segment_range(Segment const& segment) + : m_begin(const_iterator(segment)) + , m_end(const_iterator(segment, true)) + { + } + + const_iterator begin() const { return m_begin; } + const_iterator end() const { return m_end; } + + // It may not be used non-const, so comment this: + //iterator begin() { return m_begin; } + //iterator end() { return m_end; } + +private : + const_iterator m_begin, m_end; +}; + + +// All segment ranges can be handled as linestrings +namespace traits +{ + template + struct tag > + { + typedef linestring_tag type; + }; +} + + + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_RANGES_SEGMENT_RANGE_HPP diff --git a/test/algorithms/distance.cpp b/test/algorithms/distance.cpp index 4a9f0405f..a5ac99e7d 100644 --- a/test/algorithms/distance.cpp +++ b/test/algorithms/distance.cpp @@ -179,17 +179,34 @@ void test_all() test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); test_geometry, P>("LINESTRING(1 1,4 4)", "POINT(1 3)", sqrt(2.0)); - + // Rings test_geometry >("POINT(1 3)", "POLYGON((1 1,4 4,5 0,1 1))", sqrt(2.0)); test_geometry >("POINT(3 1)", "POLYGON((1 1,4 4,5 0,1 1))", 0.0); // other way round test_geometry, P>("POLYGON((1 1,4 4,5 0,1 1))", "POINT(3 1)", 0.0); - // open ring test_geometry >("POINT(1 3)", "POLYGON((4 4,5 0,1 1))", sqrt(2.0)); - // This one COMPILES but should THROW - because boost::array is not variably sized - //test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); + // Polygons + test_geometry >("POINT(1 3)", "POLYGON((1 1,4 4,5 0,1 1))", sqrt(2.0)); + test_geometry >("POINT(3 1)", "POLYGON((1 1,4 4,5 0,1 1))", 0.0); + // other way round + test_geometry, P>("POLYGON((1 1,4 4,5 0,1 1))", "POINT(3 1)", 0.0); + // open polygon + test_geometry >("POINT(1 3)", "POLYGON((4 4,5 0,1 1))", sqrt(2.0)); + + // Polygons with holes + std::string donut = "POLYGON ((0 0,1 9,8 1,0 0),(1 1,4 1,1 4,1 1))"; + test_geometry >("POINT(2 2)", donut, 0.5 * sqrt(2.0)); + test_geometry >("POINT(3 3)", donut, 0.0); + // other way round + test_geometry, P>(donut, "POINT(2 2)", 0.5 * sqrt(2.0)); + // open + test_geometry >("POINT(2 2)", "POLYGON ((0 0,1 9,8 1),(1 1,4 1,1 4))", 0.5 * sqrt(2.0)); + + + // DOES NOT COMPILE - cannot do read_wkt (because boost::array is not variably sized) + // test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); } diff --git a/test/algorithms/intersection.cpp b/test/algorithms/intersection.cpp index 530d2aab5..12a028d62 100644 --- a/test/algorithms/intersection.cpp +++ b/test/algorithms/intersection.cpp @@ -17,6 +17,7 @@ #include #include +#include @@ -26,6 +27,7 @@ void test_all() typedef boost::geometry::linestring

linestring; typedef boost::geometry::polygon

polygon; typedef boost::geometry::box

box; + typedef test::custom_segment_of

segment; std::string clip = "box(2 2,8 8)"; @@ -38,6 +40,10 @@ void test_all() test_one("llb", "LINESTRING(0 0,10 10)", clip, 1, 2, sqrt(2.0 * 6.0 * 6.0)); test_one("lbl", clip, "LINESTRING(0 0,10 10)", 1, 2, sqrt(2.0 * 6.0 * 6.0)); + // Box/segment + test_one("lsb", "LINESTRING(0 0,10 10)", clip, 1, 2, sqrt(2.0 * 6.0 * 6.0)); + test_one("lbs", clip, "LINESTRING(0 0,10 10)", 1, 2, sqrt(2.0 * 6.0 * 6.0)); + // Completely inside test_one("llbi", "LINESTRING(3 3,7 7)", clip, 1, 2, sqrt(2.0 * 4.0 * 4.0)); diff --git a/test/iterators/Jamfile.v2 b/test/iterators/Jamfile.v2 index 4034a738d..201199860 100644 --- a/test/iterators/Jamfile.v2 +++ b/test/iterators/Jamfile.v2 @@ -8,8 +8,10 @@ test-suite ggl-iterators : + [ run box_iterator.cpp ] [ run circular_iterator.cpp ] [ run closing_iterator.cpp ] [ run ever_circling_iterator.cpp ] - [ run segment_iterator.cpp ] + [ run segment_returning_iterator.cpp ] + [ run segment_range_iterator.cpp ] ; diff --git a/test/iterators/iterators.sln b/test/iterators/iterators.sln index 41aac9f84..2d058d869 100644 --- a/test/iterators/iterators.sln +++ b/test/iterators/iterators.sln @@ -2,6 +2,18 @@ Microsoft Visual Studio Solution File, Format Version 9.00 # Visual C++ Express 2005 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ever_circling_closeable_reversible_iterator", "ever_circling_closeable_reversible_iterator.vcproj", "{8EC8E503-BCB9-4A58-AC33-D61B3B0C2EAF}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ever_circling_iterator", "ever_circling_iterator.vcproj", "{73F8C969-FA1E-4D9D-81F9-35B1206F0C14}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "circular_iterator", "circular_iterator.vcproj", "{46571A34-B68D-4854-90C0-56D29EE63FFE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "closing_iterator", "closing_iterator.vcproj", "{04C31A2D-BE88-4FDB-AFFE-EFDFFA9D9C39}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "segment_range_iterator", "segment_range_iterator.vcproj", "{887E64C9-6786-44E2-AE09-B02B855486DE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "box_iterator", "box_iterator.vcproj", "{CD4B14B2-ED74-4111-B8BF-093FA3930A5C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "segment_returning_iterator", "segment_returning_iterator.vcproj", "{A38B1CA8-5194-4FAD-B85E-55697BEECCB7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -12,6 +24,30 @@ Global {8EC8E503-BCB9-4A58-AC33-D61B3B0C2EAF}.Debug|Win32.Build.0 = Debug|Win32 {8EC8E503-BCB9-4A58-AC33-D61B3B0C2EAF}.Release|Win32.ActiveCfg = Release|Win32 {8EC8E503-BCB9-4A58-AC33-D61B3B0C2EAF}.Release|Win32.Build.0 = Release|Win32 + {73F8C969-FA1E-4D9D-81F9-35B1206F0C14}.Debug|Win32.ActiveCfg = Debug|Win32 + {73F8C969-FA1E-4D9D-81F9-35B1206F0C14}.Debug|Win32.Build.0 = Debug|Win32 + {73F8C969-FA1E-4D9D-81F9-35B1206F0C14}.Release|Win32.ActiveCfg = Release|Win32 + {73F8C969-FA1E-4D9D-81F9-35B1206F0C14}.Release|Win32.Build.0 = Release|Win32 + {46571A34-B68D-4854-90C0-56D29EE63FFE}.Debug|Win32.ActiveCfg = Debug|Win32 + {46571A34-B68D-4854-90C0-56D29EE63FFE}.Debug|Win32.Build.0 = Debug|Win32 + {46571A34-B68D-4854-90C0-56D29EE63FFE}.Release|Win32.ActiveCfg = Release|Win32 + {46571A34-B68D-4854-90C0-56D29EE63FFE}.Release|Win32.Build.0 = Release|Win32 + {04C31A2D-BE88-4FDB-AFFE-EFDFFA9D9C39}.Debug|Win32.ActiveCfg = Debug|Win32 + {04C31A2D-BE88-4FDB-AFFE-EFDFFA9D9C39}.Debug|Win32.Build.0 = Debug|Win32 + {04C31A2D-BE88-4FDB-AFFE-EFDFFA9D9C39}.Release|Win32.ActiveCfg = Release|Win32 + {04C31A2D-BE88-4FDB-AFFE-EFDFFA9D9C39}.Release|Win32.Build.0 = Release|Win32 + {887E64C9-6786-44E2-AE09-B02B855486DE}.Debug|Win32.ActiveCfg = Debug|Win32 + {887E64C9-6786-44E2-AE09-B02B855486DE}.Debug|Win32.Build.0 = Debug|Win32 + {887E64C9-6786-44E2-AE09-B02B855486DE}.Release|Win32.ActiveCfg = Release|Win32 + {887E64C9-6786-44E2-AE09-B02B855486DE}.Release|Win32.Build.0 = Release|Win32 + {CD4B14B2-ED74-4111-B8BF-093FA3930A5C}.Debug|Win32.ActiveCfg = Debug|Win32 + {CD4B14B2-ED74-4111-B8BF-093FA3930A5C}.Debug|Win32.Build.0 = Debug|Win32 + {CD4B14B2-ED74-4111-B8BF-093FA3930A5C}.Release|Win32.ActiveCfg = Release|Win32 + {CD4B14B2-ED74-4111-B8BF-093FA3930A5C}.Release|Win32.Build.0 = Release|Win32 + {A38B1CA8-5194-4FAD-B85E-55697BEECCB7}.Debug|Win32.ActiveCfg = Debug|Win32 + {A38B1CA8-5194-4FAD-B85E-55697BEECCB7}.Debug|Win32.Build.0 = Debug|Win32 + {A38B1CA8-5194-4FAD-B85E-55697BEECCB7}.Release|Win32.ActiveCfg = Release|Win32 + {A38B1CA8-5194-4FAD-B85E-55697BEECCB7}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/iterators/segment_range_iterator.cpp b/test/iterators/segment_range_iterator.cpp new file mode 100644 index 000000000..bb48ff64f --- /dev/null +++ b/test/iterators/segment_range_iterator.cpp @@ -0,0 +1,52 @@ +// Boost.Geometry (aka GGL, Generic Segment Library) +// +// 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 at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + + +template +void test_geometry(std::string const& wkt, std::string const& expected) +{ + Segment segment; + boost::geometry::read_wkt(wkt, segment); + + std::ostringstream out; + boost::geometry::segment_range_iterator it(segment), end(segment, true); + for ( ; it != end; ++it) + { + out << " " << boost::geometry::get<0>(*it) << boost::geometry::get<1>(*it); + } + BOOST_CHECK_EQUAL(out.str(), expected); +} + + +template +void test_all() +{ + test_geometry("linestring(1 1,2 2)", " 11 22"); + test_geometry("linestring(4 4,3 3)", " 44 33"); +} + + +int test_main(int, char* []) +{ + test_all(); + + return 0; +} diff --git a/test/iterators/segment_range_iterator.vcproj b/test/iterators/segment_range_iterator.vcproj new file mode 100644 index 000000000..b6264af2a --- /dev/null +++ b/test/iterators/segment_range_iterator.vcproj @@ -0,0 +1,176 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/iterators/segment_iterator.cpp b/test/iterators/segment_returning_iterator.cpp similarity index 88% rename from test/iterators/segment_iterator.cpp rename to test/iterators/segment_returning_iterator.cpp index 74791c290..6c74d3c9a 100644 --- a/test/iterators/segment_iterator.cpp +++ b/test/iterators/segment_returning_iterator.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include template @@ -28,8 +28,8 @@ void test_linestring(std::string const& wkt, std::string const& expected) typedef C point_list; typedef typename C::value_type point; typedef typename C::iterator base_iterator; - typedef boost::geometry::segment_iterator segment_iterator; - typedef typename segment_iterator::value_type segment; + typedef boost::geometry::segment_returning_iterator segment_returning_iterator; + typedef typename segment_returning_iterator::value_type segment; typedef boost::geometry::linestring linestring; linestring g; @@ -39,8 +39,8 @@ void test_linestring(std::string const& wkt, std::string const& expected) std::copy(g.begin(), g.end(), std::back_insert_iterator(v)); BOOST_CHECK_EQUAL(g.size(), v.size()); - segment_iterator it(v.begin(), v.end()); - segment_iterator end(v.end()); + segment_returning_iterator it(v.begin(), v.end()); + segment_returning_iterator end(v.end()); std::ostringstream oss; while (it != end) diff --git a/test/iterators/segment_iterator.vcproj b/test/iterators/segment_returning_iterator.vcproj similarity index 91% rename from test/iterators/segment_iterator.vcproj rename to test/iterators/segment_returning_iterator.vcproj index 442ac6988..b8f4f1059 100644 --- a/test/iterators/segment_iterator.vcproj +++ b/test/iterators/segment_returning_iterator.vcproj @@ -2,9 +2,9 @@ @@ -18,7 +18,7 @@ diff --git a/test/ranges/Jamfile.v2 b/test/ranges/Jamfile.v2 new file mode 100644 index 000000000..09c7edfbe --- /dev/null +++ b/test/ranges/Jamfile.v2 @@ -0,0 +1,13 @@ +# test/iterators/Jamfile.v2 +# +# Copyright (c) 2010 Barend Gehrels +# +# Use, modification and distribution is subject to the Boost Software License, +# Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +test-suite boost-geometry-ranges + : + [ run segment_range.cpp ] + [ run box_range.cpp ] + ; diff --git a/test/ranges/ranges.sln b/test/ranges/ranges.sln new file mode 100644 index 000000000..5fee651c7 --- /dev/null +++ b/test/ranges/ranges.sln @@ -0,0 +1,25 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual C++ Express 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "segment_range", "segment_range.vcproj", "{B49AC3E2-3497-465B-88C2-BCADA4B4ADAF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "box_range", "box_range.vcproj", "{34A1F53A-DA46-41E6-9E26-740D22D662DC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B49AC3E2-3497-465B-88C2-BCADA4B4ADAF}.Debug|Win32.ActiveCfg = Debug|Win32 + {B49AC3E2-3497-465B-88C2-BCADA4B4ADAF}.Debug|Win32.Build.0 = Debug|Win32 + {B49AC3E2-3497-465B-88C2-BCADA4B4ADAF}.Release|Win32.ActiveCfg = Release|Win32 + {B49AC3E2-3497-465B-88C2-BCADA4B4ADAF}.Release|Win32.Build.0 = Release|Win32 + {34A1F53A-DA46-41E6-9E26-740D22D662DC}.Debug|Win32.ActiveCfg = Debug|Win32 + {34A1F53A-DA46-41E6-9E26-740D22D662DC}.Debug|Win32.Build.0 = Debug|Win32 + {34A1F53A-DA46-41E6-9E26-740D22D662DC}.Release|Win32.ActiveCfg = Release|Win32 + {34A1F53A-DA46-41E6-9E26-740D22D662DC}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/ranges/segment_range.cpp b/test/ranges/segment_range.cpp new file mode 100644 index 000000000..deb4ccef4 --- /dev/null +++ b/test/ranges/segment_range.cpp @@ -0,0 +1,70 @@ +// 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 at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + + +template +void test_geometry(std::string const& wkt, std::string const& expected) +{ + namespace bg = boost::geometry; + + Segment segment; + bg::read_wkt(wkt, segment); + + typedef bg::segment_range range_type; + range_type range(segment); + + { + std::ostringstream out; + for (typename boost::range_iterator::type it = boost::begin(range); + it != boost::end(range); ++it) + { + out << " " << boost::geometry::get<0>(*it) << boost::geometry::get<1>(*it); + } + BOOST_CHECK_EQUAL(out.str(), expected); + } + + { + // Check forward/backward behaviour + std::ostringstream out; + typename boost::range_iterator::type it = boost::begin(range); + it++; + it--; + out << " " << boost::geometry::get<0>(*it) << boost::geometry::get<1>(*it); + typename boost::range_iterator::type it2 = boost::end(range); + it2--; + out << " " << boost::geometry::get<0>(*it2) << boost::geometry::get<1>(*it2); + BOOST_CHECK_EQUAL(out.str(), expected); + } +} + + +template +void test_all() +{ + test_geometry("linestring(1 1,2 2)", " 11 22"); + test_geometry("linestring(4 4,3 3)", " 44 33"); +} + + +int test_main(int, char* []) +{ + test_all(); + return 0; +} diff --git a/test/ranges/segment_range.vcproj b/test/ranges/segment_range.vcproj new file mode 100644 index 000000000..6f03d21cb --- /dev/null +++ b/test/ranges/segment_range.vcproj @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +