moved code to separate files;

added template parameter for enabling/disabling functionality wrt filtering turns, removing turns, and the parameters of the assign policy;
This commit is contained in:
Menelaos Karavelas
2014-03-14 10:11:02 +02:00
parent 0fc2b5cbeb
commit f934a3aa5f
3 changed files with 175 additions and 69 deletions

View File

@@ -20,7 +20,14 @@
#include <boost/geometry/algorithms/detail/turns/print_turns.hpp>
#include <boost/geometry/algorithms/detail/overlay/follow_linear_linear.hpp>
#include <boost/geometry/multi/geometries/multi_linestring.hpp>
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_FILTER_CONTINUE_TURNS
#include <boost/geometry/algorithms/detail/turns/filter_continue_turns.hpp>
#endif
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_REMOVE_DUPLICATE_TURNS
#include <boost/geometry/algorithms/detail/turns/remove_duplicate_turns.hpp>
#endif
namespace boost { namespace geometry
{
@@ -118,7 +125,10 @@ template
typename Linear1,
typename Linear2,
typename LinestringOut,
overlay_type OverlayType
overlay_type OverlayType,
bool EnableFilterContinueTurns = true,
bool EnableRemoveDuplicateTurns = true,
bool EnableDegenerateTurns = true
>
class linear_linear_linestring
{
@@ -126,7 +136,11 @@ protected:
struct AssignPolicy
{
static bool const include_no_turn = false;
static bool const include_degenerate = false;
#ifdef BOOST_GEOMETRY_DIFFERENCE_INCLUDE_DEGENERATE_TURNS
static bool const include_degenerate = true;
#else
static bool const include_degenerate = EnableDegenerateTurns;
#endif
static bool const include_opposite = false;
template
@@ -145,68 +159,6 @@ protected:
};
class IsContinueTurn
{
private:
template <typename Operation>
inline bool is_continue_or_opposite(Operation const& operation) const
{
return operation == operation_continue
|| operation == operation_opposite;
}
public:
template <typename Turn>
bool operator()(Turn const& turn) const
{
if ( turn.method != method_collinear
&& turn.method != method_equal )
{
return false;
}
return is_continue_or_opposite(turn.operations[0].operation)
&& is_continue_or_opposite(turn.operations[1].operation);
}
};
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_REMOVE_DUPLICATE_TURNS
struct TurnEqualsTo
{
template <typename Turn>
bool operator()(Turn const& t1, Turn const& t2) const
{
return geometry::equals(t1.point, t2.point)
&& t1.operations[0].seg_id == t2.operations[0].seg_id
&& t1.operations[0].other_id == t2.operations[0].other_id;
}
};
#endif
template <typename Turns>
static inline void filter_turns(Turns& turns)
{
turns.erase( std::remove_if(turns.begin(), turns.end(),
IsContinueTurn()),
turns.end()
);
}
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_REMOVE_DUPLICATE_TURNS
template <typename Turns>
static inline void remove_duplicates(Turns& turns)
{
turns.erase( std::unique(turns.begin(), turns.end(),
TurnEqualsTo()),
turns.end()
);
}
#endif
template
<
typename Turns,
@@ -274,9 +226,17 @@ protected:
LinearGeometry2 const& linear2,
OutputIterator oit)
{
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_FILTER_CONTINUE_TURNS
// remove turns that have no added value
filter_turns(turns);
filter_turns(reverse_turns);
turns::filter_continue_turns
<
Turns, EnableFilterContinueTurns
>::apply(turns);
turns::filter_continue_turns
<
Turns, EnableFilterContinueTurns
>::apply(reverse_turns);
#endif
// sort by seg_id, distance, and operation
std::sort(boost::begin(turns), boost::end(turns),
@@ -287,8 +247,14 @@ protected:
#ifndef BOOST_GEOMETRY_DIFFERENCE_DO_NOT_REMOVE_DUPLICATE_TURNS
// remove duplicate turns
remove_duplicates(turns);
remove_duplicates(reverse_turns);
turns::remove_duplicate_turns
<
Turns, EnableRemoveDuplicateTurns
>::apply(turns);
turns::remove_duplicate_turns
<
Turns, EnableRemoveDuplicateTurns
>::apply(reverse_turns);
#endif
#ifdef GEOMETRY_TEST_DEBUG

View File

@@ -0,0 +1,78 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP
#include <algorithm>
#include <boost/geometry/algorithms/detail/overlay/turn_info.hpp>
namespace boost { namespace geometry
{
namespace detail { namespace turns
{
template <typename Turns, bool Enable>
struct filter_continue_turns
{
static inline void apply(Turns& turns) {}
};
template <typename Turns>
class filter_continue_turns<Turns, true>
{
private:
class IsContinueTurn
{
private:
template <typename Operation>
inline bool is_continue_or_opposite(Operation const& operation) const
{
return operation == detail::overlay::operation_continue
|| operation == detail::overlay::operation_opposite;
}
public:
template <typename Turn>
bool operator()(Turn const& turn) const
{
if ( turn.method != detail::overlay::method_collinear
&& turn.method != detail::overlay::method_equal )
{
return false;
}
return is_continue_or_opposite(turn.operations[0].operation)
&& is_continue_or_opposite(turn.operations[1].operation);
}
};
public:
static inline void apply(Turns& turns)
{
turns.erase( std::remove_if(turns.begin(), turns.end(),
IsContinueTurn()),
turns.end()
);
}
};
}} // namespace detail::turns
}} // namespect boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_FILTER_CONTINUE_TURNS_HPP

View File

@@ -0,0 +1,62 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Copyright (c) 2014, Oracle and/or its affiliates.
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
#ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP
#define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP
#include <algorithm>
#include <boost/geometry/algorithms/equals.hpp>
namespace boost { namespace geometry
{
namespace detail { namespace turns
{
template <typename Turns, bool Enable>
struct remove_duplicate_turns
{
static inline void apply(Turns& turns) {}
};
template <typename Turns>
class remove_duplicate_turns<Turns, true>
{
private:
struct TurnEqualsTo
{
template <typename Turn>
bool operator()(Turn const& t1, Turn const& t2) const
{
return geometry::equals(t1.point, t2.point)
&& t1.operations[0].seg_id == t2.operations[0].seg_id
&& t1.operations[0].other_id == t2.operations[0].other_id;
}
};
public:
static inline void apply(Turns& turns)
{
turns.erase( std::unique(turns.begin(), turns.end(),
TurnEqualsTo()),
turns.end()
);
}
};
}} // namespace detail::turns
}} // namespect boost::geometry
#endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TURNS_REMOVE_DUPLICATE_TURNS_HPP