|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76638 - in trunk: boost/geometry/extensions/algorithms/buffer libs/geometry/test_extensions/algorithms/buffer
From: barend.gehrels_at_[hidden]
Date: 2012-01-22 13:58:16
Author: barendgehrels
Date: 2012-01-22 13:58:08 EST (Sun, 22 Jan 2012)
New Revision: 76638
URL: http://svn.boost.org/trac/boost/changeset/76638
Log:
Updated buffer, harmonized impl's for polygon/linestring for easier merge in next step
Text files modified:
trunk/boost/geometry/extensions/algorithms/buffer/linestring_buffer.hpp | 15 +++--
trunk/boost/geometry/extensions/algorithms/buffer/polygon_buffer.hpp | 94 ++++++++++++++++++++++++++++-----------
trunk/libs/geometry/test_extensions/algorithms/buffer/test_buffer.hpp | 12 ++--
3 files changed, 82 insertions(+), 39 deletions(-)
Modified: trunk/boost/geometry/extensions/algorithms/buffer/linestring_buffer.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algorithms/buffer/linestring_buffer.hpp (original)
+++ trunk/boost/geometry/extensions/algorithms/buffer/linestring_buffer.hpp 2012-01-22 13:58:08 EST (Sun, 22 Jan 2012)
@@ -45,8 +45,8 @@
>
struct linestring_buffer
{
- typedef typename coordinate_type<Polygon>::type coordinate_type;
typedef typename point_type<Polygon>::type output_point_type;
+ typedef typename coordinate_type<Polygon>::type coordinate_type;
typedef model::referring_segment<output_point_type const> segment_type;
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
@@ -64,8 +64,9 @@
static inline void iterate(Inserter& inserter,
Iterator begin, Iterator end,
buffer_side_selector side,
+
DistanceStrategy const& distance,
- JoinStrategy const& join
+ JoinStrategy const& join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, Mapper& mapper
#endif
@@ -87,6 +88,8 @@
{
bool skip = false;
+ // Generate a block along (left or right of) the segment
+
// Simulate a vector d (dx,dy)
coordinate_type dx = get<0>(*it) - get<0>(*prev);
coordinate_type dy = get<1>(*it) - get<1>(*prev);
@@ -131,7 +134,7 @@
segment_type s2(previous_p1, previous_p2);
if (line_line_intersection<output_point_type, segment_type>::apply(s1, s2, p))
{
- join.apply(p, *prev, previous_p2, p1,
+ join_strategy.apply(p, *prev, previous_p2, p1,
distance.apply(*prev, *it, side),
inserter.get_ring());
{
@@ -181,7 +184,7 @@
>
static inline void apply(Linestring const& linestring, Inserter& inserter,
DistanceStrategy const& distance,
- JoinStrategy const& join
+ JoinStrategy const& join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, Mapper& mapper
#endif
@@ -196,14 +199,14 @@
iterate(inserter, boost::begin(linestring), boost::end(linestring),
buffer_side_left,
- distance, join
+ distance, join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, mapper
#endif
);
iterate(inserter, boost::rbegin(linestring), boost::rend(linestring),
- buffer_side_right, distance, join
+ buffer_side_right, distance, join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, mapper
#endif
Modified: trunk/boost/geometry/extensions/algorithms/buffer/polygon_buffer.hpp
==============================================================================
--- trunk/boost/geometry/extensions/algorithms/buffer/polygon_buffer.hpp (original)
+++ trunk/boost/geometry/extensions/algorithms/buffer/polygon_buffer.hpp 2012-01-22 13:58:08 EST (Sun, 22 Jan 2012)
@@ -34,52 +34,58 @@
{
-template <typename RingInput, typename RingOutput, typename JoinStrategy>
+template
+<
+ typename RingInput,
+ typename RingOutput,
+ typename DistanceStrategy,
+ typename JoinStrategy
+>
struct ring_buffer
{
typedef typename point_type<RingOutput>::type output_point_type;
typedef typename coordinate_type<output_point_type>::type coordinate_type;
+ typedef model::referring_segment<output_point_type const> segment_type;
+ template
+ <
+ typename Iterator
+#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
+ , typename Mapper
+#endif
+ >
+ static inline void iterate(RingOutput& buffered,
+ Iterator begin, Iterator end,
+ buffer_side_selector side,
+ DistanceStrategy const& distance,
+ JoinStrategy const& join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
- template <typename Mapper>
-#endif
- static inline void apply(RingInput const& ring, RingOutput& buffered,
- coordinate_type distance,
- JoinStrategy const& join_strategy
-#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
- , Mapper& mapper
+ , Mapper& mapper
#endif
)
{
- typedef model::referring_segment<output_point_type const> segment_type;
- typedef typename boost::range_iterator
- <
- RingInput const
- >::type iterator_type;
-
output_point_type previous_p1, previous_p2;
output_point_type first_p1, first_p2;
- bool first = true;
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
int index = 0;
#endif
- iterator_type it = boost::begin(ring);
- for (iterator_type prev = it++;
- it != boost::end(ring); ++it)
+ bool first = true;
+
+ Iterator it = begin;
+ for (Iterator prev = it++; it != end; ++it)
{
if (! detail::equals::equals_point_point(*prev, *it))
{
bool skip = false;
- // Generate a block along (int most cases to the left of) the segment
+ // Generate a block along (left or right of) the segment
// Simulate a vector d (dx,dy)
coordinate_type dx = get<0>(*it) - get<0>(*prev);
coordinate_type dy = get<1>(*it) - get<1>(*prev);
-
// For normalization [0,1] (=dot product d.d, sqrt)
coordinate_type length = sqrt(dx * dx + dy * dy);
@@ -92,7 +98,7 @@
output_point_type p1, p2;
- coordinate_type d = distance;
+ coordinate_type d = distance.apply(*prev, *it, side);
set<0>(p2, get<0>(*it) + px * d);
set<1>(p2, get<1>(*it) + py * d);
@@ -101,6 +107,7 @@
set<1>(p1, get<1>(*prev) + py * d);
{
+ #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
RingOutput block;
block.push_back(*prev);
block.push_back(*it);
@@ -108,7 +115,6 @@
block.push_back(p1);
block.push_back(*prev);
- #ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
mapper.map(block, "opacity:0.4;fill:rgb(255,128,0);stroke:rgb(0,0,0);stroke-width:1");
#endif
}
@@ -120,7 +126,9 @@
segment_type s2(previous_p1, previous_p2);
if (line_line_intersection<output_point_type, segment_type>::apply(s1, s2, p))
{
- join_strategy.apply(p, *prev, previous_p2, p1, distance, buffered);
+ join_strategy.apply(p, *prev, previous_p2, p1,
+ distance.apply(*prev, *it, side),
+ buffered);
{
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
mapper.map(p, "fill:rgb(0,0,0);", 3);
@@ -159,7 +167,9 @@
segment_type s2(first_p1, first_p2);
line_line_intersection<output_point_type, segment_type>::apply(s1, s2, p);
- join_strategy.apply(p, *boost::begin(ring), previous_p2, first_p1, distance, buffered);
+ join_strategy.apply(p, *begin, previous_p2, first_p1,
+ distance.apply(*(end - 1), *begin, side),
+ buffered);
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
mapper.map(p, "fill:rgb(0,0,0);", 3);
@@ -168,6 +178,30 @@
mapper.text(p, out.str(), "fill:rgb(0,0,0);font-family='Arial';", 5, 5);
#endif
}
+ }
+
+#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
+ template <typename Mapper>
+#endif
+ static inline void apply(RingInput const& ring,
+ RingOutput& buffered,
+
+ DistanceStrategy const& distance,
+
+ JoinStrategy const& join_strategy
+#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
+ , Mapper& mapper
+#endif
+ )
+ {
+ iterate(buffered, boost::begin(ring), boost::end(ring),
+ buffer_side_left,
+ distance, join_strategy
+#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
+ , mapper
+#endif
+ );
+
// Close the generated buffer
{
@@ -179,14 +213,20 @@
-template <typename PolygonInput, typename PolygonOutput, typename JoinStrategy>
+template
+<
+ typename PolygonInput,
+ typename PolygonOutput,
+ typename DistanceStrategy,
+ typename JoinStrategy
+>
struct polygon_buffer
{
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
template <typename Mapper>
#endif
static inline void apply(PolygonInput const& polygon, PolygonOutput& buffered,
- typename coordinate_type<PolygonOutput>::type distance,
+ DistanceStrategy const& distance,
JoinStrategy const& join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, Mapper& mapper
@@ -198,7 +238,7 @@
typedef typename ring_type<PolygonInput>::type input_ring_type;
typedef typename ring_type<PolygonOutput>::type output_ring_type;
- typedef ring_buffer<input_ring_type, output_ring_type, JoinStrategy> policy;
+ typedef ring_buffer<input_ring_type, output_ring_type, DistanceStrategy, JoinStrategy> policy;
policy::apply(exterior_ring(polygon), exterior_ring(buffered),
distance, join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
Modified: trunk/libs/geometry/test_extensions/algorithms/buffer/test_buffer.hpp
==============================================================================
--- trunk/libs/geometry/test_extensions/algorithms/buffer/test_buffer.hpp (original)
+++ trunk/libs/geometry/test_extensions/algorithms/buffer/test_buffer.hpp 2012-01-22 13:58:08 EST (Sun, 22 Jan 2012)
@@ -146,6 +146,8 @@
join_strategy_type join_strategy;
#endif
+ typedef bg::strategy::buffer::distance_assymetric<coordinate_type> distance_strategy_type;
+ distance_strategy_type distance_strategy(distance_left, distance_left / 2.0); // TODO: distance_right
std::vector<GeometryOut> buffered;
@@ -154,9 +156,9 @@
GeometryOut buffered_step1;
bg::detail::buffer::polygon_buffer
<
- Geometry, GeometryOut, join_strategy_type
+ Geometry, GeometryOut, distance_strategy_type, join_strategy_type
>::apply(geometry, buffered_step1,
- distance_left,
+ distance_strategy,
join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, mapper
@@ -166,7 +168,6 @@
}
#else
{
- typedef bg::strategy::buffer::distance_assymetric<coordinate_type> distance;
typedef bg::detail::buffer::intersecting_inserter
<
std::vector<GeometryOut>
@@ -176,9 +177,8 @@
bg::detail::buffer::linestring_buffer
<
- Geometry, GeometryOut, distance, join_strategy_type
- >::apply(geometry, inserter,
- distance(distance_left, distance_left / 2.0),
+ Geometry, GeometryOut, distance_strategy_type, join_strategy_type
+ >::apply(geometry, inserter, distance_strategy,
join_strategy
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
, mapper
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